Skip to content

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']);

带颜色风格的输出

$outputwrite() 方法支持带颜色风格的输出(当然得终端支持才行)

$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');
Clone this wiki locally
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy