命令行颜色
代码
<?php
declare (strict_types = 1);
namespace app\admin\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\output\formatter\Style;
use think\console\Output;
class Hello extends Command
{
protected function configure()
{
// 指令配置
$this->setName('hello')
->setDescription('php think hello --ansi 演示命令行颜色');
}
protected function execute(Input $input, Output $output)
{
$output->info("info");
$output->error("error");
$output->warning("warning");
$output->highlight("highlight");
$output->question("question");
/*$question = $output->confirm($input, 'Continue with this action?', false);
if (!$question) {
return;
}*/
}
}
添加至php think
add_action("console",function(&$console){
if(!is_cli()){return;}
// php think hello
$console['hello'] = "app\admin\command\Hello";
});
运行
php think hello --ansi
效果