/** * Converts the exceprt to colorized string for terminal * * @return string */ public function toTerminal() { $output = ''; foreach ($this->lines as $lineNumber => $lineContent) { if ($lineNumber + 1 == $this->currentLine) { // current column will be highlighted if ($this->currentColumn !== null) { $output .= ILess_ANSIColor::colorize(sprintf("%{$this->lineWidth}s: ", $lineNumber + 1), 'grey+inverse'); $output .= ILess_ANSIColor::colorize(substr($lineContent, 0, $this->currentColumn - 1), 'grey'); $output .= ILess_ANSIColor::colorize(substr($lineContent, $this->currentColumn - 1, 1), 'red+bold'); $output .= ILess_ANSIColor::colorize(substr($lineContent, $this->currentColumn), 'red'); $output .= "\n"; } else { $output .= ILess_ANSIColor::colorize(sprintf("%{$this->lineWidth}s: %s\n", $lineNumber + 1, $lineContent), 'red'); } } else { $output .= ILess_ANSIColor::colorize(sprintf("%{$this->lineWidth}s: %s\n", $lineNumber + 1, $lineContent), 'grey'); } } return $output; }
/** * Renders an exception * * @param Exception $e */ protected function renderException(Exception $e) { $hasColors = $this->detectColors(); // excerpt? if ($e instanceof ILess_Exception) { printf("%s: %s\n", $this->scriptName, $hasColors && !$this->getOption('no_color') ? ILess_ANSIColor::colorize($e->toString(false), 'red') : $e->toString(false)); if ($excerpt = $e->getExcerpt()) { $hasColors ? printf("%s\n", $excerpt->toTerminal()) : printf("%s\n", $excerpt->toText()); } } else { printf("%s: %s\n", $this->scriptName, $hasColors && !$this->getOption('no_color') ? ILess_ANSIColor::colorize($e->getMessage(), 'red') : $e->getMessage()); } }