/** * Output the table to `STDOUT` using `cli\line()`. * * If STDOUT is a pipe or redirected to a file, should output simple * tab-separated text. Otherwise, renders table with ASCII table borders * * @uses cli\Shell::isPiped() Determine what format to output * * @see cli\Table::renderRow() */ public function display() { foreach ($this->getDisplayLines() as $line) { Streams::line($line); } }
private static function outSolid($color, $text) { cli\Streams::line($color . $text . self::FONT_RESET); }
/** * Displays an array of strings as a menu where a user can enter a number to * choose an option. The array must be a single dimension with either strings * or objects with a `__toString()` method. * * @param array $items The list of items the user can choose from. * @param string $default The index of the default item. * @param string $title The message displayed to the user when prompted. * @return string The index of the chosen item. * @see cli\line() * @see cli\input() * @see cli\err() */ public static function menu($items, $default = false, $title = 'Choose an item') { $map = array_values($items); if ($default && strpos($title, '[') === false && isset($items[$default])) { $title .= ' [' . $items[$default] . ']'; } foreach ($map as $idx => $item) { \cli\Streams::line(' %d. %s', $idx + 1, (string) $item); } \cli\Streams::line(); while (true) { fwrite(static::$out, sprintf('%s: ', $title)); $line = \cli\Streams::input(); if (is_numeric($line)) { $line--; if (isset($map[$line])) { return array_search($map[$line], $items); } if ($line < 0 || $line >= count($map)) { \cli\Streams::err('Invalid menu selection: out of range'); } } else { if (isset($default)) { return $default; } } } }
/** * Prints a message to `STDOUT` with a newline appended. See `\cli\out` for * more documentation. * * @see cli\out() */ function line($msg = '') { // func_get_args is empty if no args are passed even with the default above. $args = func_get_args(); if ($args) { call_user_func_array(array('\\cli\\Streams', 'line'), $args); } else { \cli\Streams::line(); } }
/** * Finish our Notification display. Should be called after the Notifier is * no longer needed. * * @see cli\Notify::display() */ public function finish() { Streams::out("\r"); $this->display(true); Streams::line(); }
/** * Output the table to `STDOUT` using `cli\line()`. * * If STDOUT is a pipe or redirected to a file, should output simple * tab-separated text. Otherwise, renders table with ASCII table borders * * @uses cli\Shell::isPiped() Determine what format to output * * @see cli\Table::renderRow() */ public function display() { $this->_renderer->setWidths($this->_width); $border = $this->_renderer->border(); if (isset($border)) { Streams::line($border); } Streams::line($this->_renderer->row($this->_headers)); if (isset($border)) { Streams::line($border); } foreach ($this->_rows as $row) { Streams::line($this->_renderer->row($row)); } if (isset($border)) { Streams::line($border); } if ($this->_footers) { Streams::line($this->_renderer->row($this->_footers)); if (isset($border)) { Streams::line($border); } } }