Beispiel #1
0
 /**
  * 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 .= ANSIColor::colorize(sprintf("%{$this->lineWidth}s: ", $lineNumber + 1), 'grey+inverse');
                 $output .= ANSIColor::colorize(substr($lineContent, 0, $this->currentColumn - 1), 'grey');
                 $output .= ANSIColor::colorize(substr($lineContent, $this->currentColumn - 1, 1), 'red+bold');
                 $output .= ANSIColor::colorize(substr($lineContent, $this->currentColumn), 'red');
                 $output .= "\n";
             } else {
                 $output .= ANSIColor::colorize(sprintf("%{$this->lineWidth}s: %s\n", $lineNumber + 1, $lineContent), 'red');
             }
         } else {
             $output .= ANSIColor::colorize(sprintf("%{$this->lineWidth}s: %s\n", $lineNumber + 1, $lineContent), 'grey');
         }
     }
     return $output;
 }
Beispiel #2
0
 /**
  * Renders an exception
  *
  * @param Exception $e
  */
 protected function renderException(Exception $e)
 {
     $hasColors = $this->detectColors();
     // excerpt?
     if ($e instanceof ILess\Exception\Exception) {
         printf("%s: %s\n", $this->scriptName, $hasColors && !$this->getOption('no_color') ? 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') ? ANSIColor::colorize($e->getMessage(), 'red') : $e->getMessage());
     }
 }