wilensky / cli-colorizer
一个轻量级的PHP7 CLI输出着色工具。
v1.5.0
2017-01-03 17:18 UTC
Requires
- php: >=7.0.1
This package is not auto-updated.
Last update: 2024-09-28 19:47:32 UTC
README
轻量级PHP7 CLI输出着色器
- 通过
composer require
wilensky/cli-colorizer
获取 - PHP7 兼容
- PSR2 兼容
- 轻量级
- 已文档化
- 兼容本地Linux的
tail
和cat
命令
用法
为了便于使用,可以使用 use
语句将 CliColorizer
别名。
<?php use Wilensky/CliColorizer as WCC;
更改文字颜色
常规方法
echo WCC::fgYellow('YoHoHo').PHP_EOL; // YoHoHo will be yellowed on default background
所有可用的前景颜色方法都列在类的文档注释下,以
fg*
前缀开头。
高级方法
$answer = true; $isOk = $answer === true; echo WCC::fg( $isOk ? 'Yes' : 'No', $isOk ? 'green' : 'red' ).PHP_EOL;
更改背景颜色
常规方法
echo WCC::bgCyan('YoHoHo').PHP_EOL; // YoHoHo will be displayed on cyan background with default foreground color
所有可用的背景颜色方法都列在类的文档注释下,以
bg*
前缀开头。
高级方法
$error = true; $hasError = $error === true; echo WCC::bg( $hasError ? 'Failed' : 'Ready', $hasError ? 'red' : 'black' ).PHP_EOL;
混合前景和背景颜色
echo WCC::bgGreen(WCC::fgYellow('YoHoHo')).PHP_EOL; // YoHoHo will be displayed as yellow text on green background echo WCC::fgYellow(WCC::bgGreen('YoHoHo')).PHP_EOL; // Produces same output as invocation priority doesn't matter for display
使文字 加粗
echo WCC::bold('YoHoHo').PHP_EOL; // YoHoHo will be displayed bold with default fore/background colors
使颜色 加粗
echo WCC::bold(WCC::fgYellow('YoHoHo')).PHP_EOL; // YoHoHo will be bold yellow echo WCC::fgYellow(WCC::bold('YoHoHo')).PHP_EOL; // Produces same output
echo WCC::bold(WCC::bgCyan('YoHoHo')).PHP_EOL; // YoHoHo will be bold with default color on cyan background
echo WCC::bold(WCC::fgYellow(WCC::bgCyan('YoHoHo'))).PHP_EOL; // YoHoHo will be bold yellow on cyan background