-
Notifications
You must be signed in to change notification settings - Fork 48
output instance
Inhere edited this page Jan 10, 2019
·
2 revisions
输出对象是
Inhere\Console\IO\Output
的实例
基本输出:
public function write(mixed $messages = '', bool $nl = true, bool $quit = false, array $options = [])
-
$messages
mixed 要输出的消息。可以是字符串或数组。 -
$nl
bool 输出后是否换行。 默认true
-
$quit
bool|int 输出后是否退出脚本。默认false
, 其它值都会转换为int
作为退出码(true
会转换为 0)。 -
$options
array 选项信息
$output->write('hello'); $output->write(['hello', 'world']);
$output
的 write()
方法支持带颜色风格的输出(当然得终端支持才行)
$output->write('hello <info>world<info>');
已经内置了常用的风格:
alt text
来自于类 Inhere\Console\Util\Show
。
output 实例拥有
Inhere\Console\Util\Show
的所有格式化输出方法。不过都是通过对象式访问的。
$style = Inhere\Console\Component\Style\Style::create(); echo $style->render('no color <info>color text</info>'); // 直接使用内置的风格 echo $style->info('message'); echo $style->error('message');