localgod / console-color
处理控制台颜色的工具
v1.0.3
2021-05-17 13:52 UTC
Requires
- php: >=8.0
Requires (Dev)
- behat/behat: v3.8.1
- phpunit/phpunit: 9.5.4
- squizlabs/php_codesniffer: 3.6.0
This package is not auto-updated.
Last update: 2024-09-19 06:43:13 UTC
README
控制台颜色
console-color 使您能够轻松地在控制台中处理ANSI颜色代码。
基本方法
escape($string) : 转义%符号,使其不被解释为颜色代码;接收一个字符串作为参数,并返回转义后的字符串。
convert($string, $colored = true)) : 将提供的字符串中的颜色代码转换为ANSI控制代码
魔术方法
对于支持的每种颜色,您都可以调用
- {colorname}Normal($string)
- {colorname}Bright($string)
- {colorname}Background($string)
以快速格式化字符串。
代码转换表
示例
use Localgod\Console\Color; // Let's add a little color to the world // %n resets the color so the following stuff doesn't get messed up print Color::convert("%bHello World!%n\n"); // Paint it red print Color::redNormal("Paint it red!\n"); // Colorless mode, in case you need to strip colorcodes off a text print Color::convert("%rHello World!%n\n", false); // The uppercase version makes a colorcode bold/bright print Color::convert("%BHello World!%n\n"); // To print a %, you use %% print Color::convert("3 out of 4 people make up about %r75%% %nof the world population.\n"); // Or you can use the escape() method. print Color::convert("%y".Color::escape('If you feel that you do everying wrong, be random, there\'s a 50% Chance of making the right decision.')."%n\n");
灵感
此项目是 http://pear.php.net/package/Console_Color/ 中使用思想的重实现。