jfcherng/php-color-output
Composer 安装命令:
composer require jfcherng/php-color-output
包简介
Make your PHP command-line application colorful.
README 文档
README
The above screenshot is the output of demo.php. See the Example section.
Installation
composer require jfcherng/php-color-output
Available Styles
| Background | Foreground | Compound | Special | Alias |
|---|---|---|---|---|
| b_black | f_black | f_dark_gray | blink | b (bold) |
| b_blue | f_blue | f_light_blue | bold | blk (blink) |
| b_cyan | f_brown | f_light_cyan | dim | h (hidden) |
| b_green | f_cyan | f_light_green | hidden | rev (reverse) |
| b_light_gray | f_green | f_light_purple | reset | rst (reset) |
| b_magenta | f_light_gray | f_light_red | reverse | u (underline) |
| b_red | f_normal | f_white | underline | - |
| b_yellow | f_purple | f_yellow | - | - |
| - | f_red | - | - | - |
Functions and Methods
<?php /** * Make a string colorful. * * @param string $str the string * @param string|string[] $colors the colors * @param bool $reset reset color at the end of the string? * * @return string the colored string */ \Jfcherng\Utility\CliColor::color(string $str, $colors = [], bool $reset = true): string /** * Remove all colors from a string. * * @param string $str the string * * @return string the string without colors */ \Jfcherng\Utility\CliColor::noColor(string $str): string
Example
<?php include __DIR__ . '/vendor/autoload.php'; use \Jfcherng\Utility\CliColor; // colors in a string using a comma as the delimiter echo CliColor::color('foo', 'f_light_cyan, b_yellow'); // "\033[1;36;43mfoo\033[0m" echo PHP_EOL; // colors in an array echo CliColor::color('foo', ['f_white', 'b_magenta']); // "\033[1;37;45mfoo\033[0m" echo PHP_EOL; // do not auto reset color at the end of string echo CliColor::color('foo', ['f_red', 'b_green', 'b', 'blk'], false); // "\033[31;42;1;5mfoo" // manually add color reset echo CliColor::color('', 'reset'); // "\033[0m" echo PHP_EOL; // remove all color codes from a string echo CliColor::noColor("\033[31;42;5mfoo\033[0mbar"); // "foobar" echo PHP_EOL;
jfcherng/php-color-output 适用场景与选型建议
jfcherng/php-color-output 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.68M 次下载、GitHub Stars 达 14, 最近一次更新时间为 2018 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「color」 「command-line」 「ansi-colors」 「str-color」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jfcherng/php-color-output 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jfcherng/php-color-output 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jfcherng/php-color-output 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A help command for Minicli
Native (browser) color input field for SilverStripe
Colorizes the Flarum forum header and interface based on the active tag's color.
Command-line utility for Vtiger CRM.
Thermage provides a fluent and incredibly powerful object-oriented interface for customizing CLI output text color, background, formatting, theming and more.
Rules for the bdd-analyser CLI tool
统计信息
- 总下载量: 5.68M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 37
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-24
