/** * @param array $lines * @param null|int $markLine * @return string * @throws \JakubOnderka\PhpConsoleColor\InvalidStyleException */ private function lineNumbers(array $lines, $markLine = null) { end($lines); $lineStrlen = strlen(key($lines) + 1); $snippet = ''; foreach ($lines as $i => $line) { if ($markLine !== null) { $snippet .= $markLine === $i + 1 ? $this->color->apply(self::ACTUAL_LINE_MARK, ' > ') : ' '; } $snippet .= $this->color->apply(self::LINE_NUMBER, str_pad($i + 1, $lineStrlen, ' ', STR_PAD_LEFT) . '| '); $snippet .= $line . PHP_EOL; } return $snippet; }
public function parse() { $c = new ConsoleColor(); $o = ''; $b = []; foreach ($this->attributes as $a => $v) { $a = Str::underscored($a); $b[] = $a; if (is_string($v)) { $o .= $c->apply($b, $v); $b = []; } } return $o; }
/** * @param string $string * @param string $type * @throws \JakubOnderka\PhpConsoleColor\InvalidStyleException */ public function write($string, $type = self::TYPE_DEFAULT) { if (!$this->colors instanceof \JakubOnderka\PhpConsoleColor\ConsoleColor) { parent::write($string, $type); } else { switch ($type) { case self::TYPE_OK: parent::write($this->colors->apply('bg_green', $string)); break; case self::TYPE_SKIP: parent::write($this->colors->apply('bg_yellow', $string)); break; case self::TYPE_ERROR: parent::write($this->colors->apply('bg_red', $string)); break; default: parent::write($string); } } }
/** * @param ProgrammingCollection $collection * @param string $channelName * @param bool $showFullProgramming show all programs for the day * @param int $maxLength * @return string */ public static function printChannel(ProgrammingCollection $collection, $channelName, $showFullProgramming = false, $maxLength = 100) { $consoleColor = new ConsoleColor(); $res = ''; $programming = $collection->getProgrammingsByChannel($channelName); $res .= $consoleColor->apply('blue', '==> ') . $consoleColor->apply('white', $programming->getChannelName() . $consoleColor->apply('blue', ' <==') . "\n"); $now = Carbon::now(); $nextTwoHours = Carbon::now()->addHours(2); foreach ($programming->getEvents() as $event) { $color = null; if ($event->starts_at->lte($now) && $event->ends_at->gte($now)) { $color = 'green'; } else { if (!$showFullProgramming && $event->starts_at->gte($now) && $event->starts_at->lte($nextTwoHours)) { $color = 'default'; } else { if ($showFullProgramming) { $color = 'default'; } } } if (!$color) { continue; } $title = $event->render(); if (mb_strlen($title) > $maxLength) { $title = mb_substr($title, 0, $maxLength - 2) . '..'; } $res .= $consoleColor->apply($color, $title); $res .= "\n"; } return $res; }