<?php
namespace Engine\Debug\Dline; class Cli extends \Engine\Debug\Dline\Text { public function formatValue($var, $repl) { if($repl['ignore']) return ''; $color = str_replace('#', '', $repl['color']); $autoType = $this->detectVarType($var); if (!$repl['type']) { $repl['type'] = $autoType; } if (!$repl['color']) { switch ($autoType) { default: case 'string': $color ='string'; break; case 'int': case 'float': $color ='numeric'; break; case 'bool': $color = ($var?'bool-true':'bool-false'); break; case 'array-numeric': $color = 'array-numeric'; break; case 'array-associative': $color = 'array-associative'; break; } } $output = $this->formatValue_renderValue($var, $repl); $output = htmlspecialchars_decode($output); switch ($color) { case 'string': $output = "\e[0m${output}\e[0m"; break; case 'numeric': $output = "\e[36m${output}\e[0m"; break; case 'bool-true': $output = "\e[35m${output}\e[0m"; break; case 'bool-false': $output = "\e[95m${output}\e[0m"; break; case 'array-numeric': $output = "\e[94m${output}\e[0m"; break; case 'array-associative': $output = "\e[96m${output}\e[0m"; break; default: $colorArr = str_split($color, 1); foreach ($colorArr as $k=>$v) { $v = hexdec($colorArr[$k]); if ($v<4) { $v = 0; } elseif ($v<12) { $v = 1; } else { $v = 2; } $colorArr[$k] = $v; } $binnedColor = sprintf("%d%d%d", $colorArr[0], $colorArr[1], $colorArr[2]); $cliColorAssoc = [ "\e[0m" => ["000", "222", ], "\e[37m" => ["111", ], "\e[31m" => ["100", "200", ], "\e[32m" => ["010", "020", ], "\e[34m" => ["001", "002", ], "\e[33m" => ["110", "220", ], "\e[36m" => ["011", "022", ], "\e[35m" => ["101", "202", ], ]; $pickedCliColor = ""; foreach ($cliColorAssoc as $cliColor=>$colors) { if (in_array($binnedColor, $colors)) { $pickedCliColor = $cliColor; break; } } $output = "{$pickedCliColor}${output}\e[0m"; break; } return $output; } } 