console-color
A simple command line colorize library
Installation
Using Composer to add the package to your project's dependencies:
composer require questocat/console-colorUsage
$consoleColor = new ConsoleColor();
// å—体色渲染
$consoleColor->red('红色å—体');
$consoleColor->red()->render('红色å—体');
$consoleColor->blue('è“?色å—体');
$consoleColor->blue()->render('è“?色å—体');
// 背景色渲染
$consoleColor->redBackground('红色背景');
$consoleColor->redBackground()->render('红色背景');
$consoleColor->blueBackground('�色背景');
$consoleColor->blueBackground()->render('�色背景');
// 控制�列渲染
$consoleColor->bold('粗体文å—');
$consoleColor->underline('带下划线的文å—');
$consoleColor->underline()->render('带下划线的文å—');
// 内置主题渲染
$consoleColor->info('输出æ??示信æ?¯');
$consoleColor->error('输出错误信�');
$consoleColor->warning('输出è¦å‘Šä¿¡æ?¯');
$consoleColor->success('输出�功信�');
// æ·»åŠ è‡ªå®šä¹‰é¢œè‰²
$consoleColor->addColor('fooBar', 94); // æ·»åŠ å?•个颜色
$consoleColor->fooBar('自定义颜色å—体,å?•个属性');
$consoleColor->addColor('fooBar', [1, 4, 41, 92]); // æ·»åŠ å?•个颜色
$consoleColor->fooBar('自定义颜色å—体,å?«å¤šä¸ªå±žæ€§');
$consoleColor->addColor(['foo' => [38, 5, 5, 48, 5, 3], 'bar' => [48, 5, 28]]); // æ·»åŠ å¤šä¸ªé¢œè‰²ï¼ˆ256)
$consoleColor->foo('自定义颜色å—体,å?«å¤šä¸ªå±žæ€§');
$consoleColor->foo()->bar('自定义颜色å—体,å?«å¤šä¸ªå±žæ€§');
// 支� 88/256 Colors
$consoleColor->color256(12)->render('8/256 å—体'); // å—体颜色
$consoleColor->color256(12, FOREGROUND)->render('8/256 å—体'); // å—体颜色
$consoleColor->color256(25, BACKGROUND)->render('8/256 背景'); // 背景颜色
// 组�渲染
$consoleColor->blueBackground()->red('è“?色背景,红色å—体');
$consoleColor->red()->blueBackground()->render('è“?色背景,红色å—体,其他组å?ˆæ–¹å¼?');
$consoleColor->blue()->yellowBackground()->red()->render('黄色背景,红色å—体');
$consoleColor->color256(6)->yellowBackground()->render('8/256 å—体,黄色背景');
$consoleColor->red()->color256(60, BACKGROUND)->render('8/256 背景,红色å—体');Example will output
Colors/Formats Api
| Foreground | Background | Formats | Themes |
|---|---|---|---|
| default | defaultBackground | bold | info |
| black | blackBackground | dim | warning |
| red | redBackground | underline | error |
| green | greenBackground | blink | success |
| yellow | yellowBackground | invert | |
| blue | blueBackground | hidden | |
| magenta | magentaBackground | ||
| cyan | cyanBackground | ||
| lightGray | lightGrayBackground | ||
| darkGray | darkGrayBackground | ||
| lightRed | lightRedBackground | ||
| lightGreen | lightGreenBackground | ||
| lightYellow | lightYellowBackground | ||
| lightBlue | lightBlueBackground | ||
| lightMagenta | lightMagentaBackground | ||
| lightCyan | lightCyanBackground | ||
| white | whiteBackground |
Reference
License
Licensed under the MIT license.



