/** * Output a line, erasing the line first * * @param string $str String to output * @param null|int $col The column to draw the current line * @param boolean $erase Clear the line before drawing the passed string */ static function line($str, $col = null, $erase = true) { if ($col !== null) { Cursor::rowcol($col, 1); } if ($erase) { Erase::line(); } fwrite(self::$stream, $str); }
/** * @param resource $stream * @param string $str * @param integer|null $row */ protected static function saveWriteRestore($stream, $str, $row) { if ($row) { Cursor::savepos(); Cursor::rowcol($row, Misc::cols()); } fwrite($stream, $str); if ($row) { Cursor::restore(); } }
/** * Render a statusbar stack * * @staticvar bool $lines A stack of previously added lines * @param string $str The status to add * @param null|int $height The height of the status menu to render * @param bool $last_line_to_opposing_stream Send the last line of the status to the oposite stream (STDERR/STDOUT) */ static function statusbar($str, $height = null, $last_line_to_opposing_stream = true) { if ($height < 0) { $height = Misc::rows() + $height + 1; } if (!$height) { if (defined('STATUSBAR_HEIGHT')) { $height = STATUSBAR_HEIGHT; //@todo: backwards compatibility with some of my older code, remove } else { $height = max(5, Misc::rows() - 5); } } static $lines = false; $i = 0; if (!$lines) { $lines = array_fill(0, $height - 1, array('str' => '')); } foreach (explode(PHP_EOL, $str) as $line) { $lines[] = array('str' => strtr(trim($line), "\r\n", " ")); array_shift($lines); } fwrite(self::$stream, "7[1;1f[2K"); foreach ($lines as $line) { $i++; $text = substr(str_pad($line['str'], Misc::cols()), 0, Misc::cols() - 1); Cursor::rowcol($i, 1); if ($i == $height - 1 && $last_line_to_opposing_stream) { fwrite(self::$altstream, $text); } else { fwrite(self::$stream, $text); } } fwrite(self::$stream, "[" . $height . ";1f"); fwrite(self::$stream, str_repeat('─', Misc::cols())); fwrite(self::$stream, "8"); }