Ejemplo n.º 1
0
 /**
  * @param string $text
  * @param bool $escape
  * @param mixed $length
  * @param bool $break
  * @param bool $wordwrap
  * @param int $offset
  * @return string
  */
 public function prepare($text, $escape = true, $length = null, $break = true, $wordwrap = true, $offset = 0)
 {
     if (isset($this->param) && is_array($this->param) && in_array('-noconsole', $this->param, true)) {
         return $escape ? $this->escape($text) : $text;
     }
     $formatter = FormatterFactory::console();
     $text = $formatter->bold($text);
     $text = $formatter->underline($text);
     $text = $formatter->color($text);
     if ($length === false) {
         $text .= substr($text, -1) === '\\' ? ' ' : '';
         return $escape ? $this->escape($text) : $text;
     }
     if ($length === null) {
         if (Cerberus::isExecAvailable() === false) {
             return $escape ? $this->escape($text) : $text;
         }
         preg_match('/columns\\s([0-9]+);/', strtolower(exec('stty -a | grep columns')), $matches);
         if (isset($matches[1]) === false) {
             return $escape ? $this->escape($text) : $text;
         }
         $length = $matches[1];
     }
     $length = $length - $offset;
     if ($this->len($text) <= $length) {
         $text .= substr($text, -1) === '\\' ? ' ' : '';
         return $escape ? $this->escape($text) : $text;
     }
     $text = utf8_decode($text);
     if ($break === true) {
         if ($wordwrap === true) {
             $text = $this->wordwrap($text, $length);
         } else {
             $text = $this->split($text, $length, PHP_EOL);
         }
         $text = str_replace(PHP_EOL, PHP_EOL . str_repeat(' ', $offset), $text);
     } else {
         $text = $this->cut($text, $length - 3) . '...';
         if (strpos($text, "") !== false) {
             $text .= "";
         }
     }
     $text = utf8_encode($text);
     $text .= substr($text, -1) === '\\' ? ' ' : '';
     return $escape ? $this->escape($text) : $text;
 }
Ejemplo n.º 2
0
 protected function setUp()
 {
     $this->consoleFormatter = FormatterFactory::console();
     $this->htmlFormatter = FormatterFactory::html();
 }