sevenecks/ansi
Composer 安装命令:
composer require sevenecks/ansi
包简介
This package offers an API to colorize strings of text with various ANSI colors using static methods.
README 文档
README
composer require sevenecks/ansi
Colorize
Usage
Static Usage
The methods on Colorize can be called statically and the full API is listed later.
require_once __DIR__ . '/vendor/autoload.php'; use SevenEcks\Ansi\Colorize; $test_string = 'This is a test'; echo Colorize::italic($test_string) . "\n"; echo Colorize::cyan($test_string) . "\n"; echo Colorize::bgRed($test_string) . "\n"; // background color first echo Colorize::cyan(Colorize::bgRed($test_string)) . "\n"; // manually call the colorize string function echo Colorize::colorizeString("TEST STRING", Colorize::$FOREGROUND_BLUE);
Instantiated Usage
Colorize also supports a magic method that will allow you to call the static methods dynamically, if you want to instantiate the Colorize class. This can be useful for dependency injection.
require_once __DIR__ . '/vendor/autoload.php'; use SevenEcks\Ansi\Colorize; $test_string = 'This is a test'; $colorize = new Colorize; echo $color->red('tester'); echo $color->darkGray('testy mctesterson');
Colors
There are several colors available for foreground and background.
Foreground
Colorize::italic Colorize::bold Colorize::underline Colorize::invert Colorize::darkGray Colorize::blue Colorize::lightBlue Colorize::green Colorize::lightGreen Colorize::cyan Colorize::lightCyan Colorize::red Colorize::lightRed Colorize::purple Colorize::lightPurple Colorize::brown Colorize::yellow Colorize::lightGray Colorize::white
Background
Colorize::bgBlack Colorize::bgRed Colorize::bgGreen Colorize::bgYellow Colorize::bgBlue Colorize::bgMagenta Colorize::bgCyan Colorize::bgLightGray
API
//foreground colors public static $FOREGROUND_BLACK = '0;30'; public static $FOREGROUND_DARK_GRAY = '1;30'; public static $FOREGROUND_BLUE = '0;34'; public static $FOREGROUND_LIGHT_BLUE = '1;34'; public static $FOREGROUND_GREEN = '0;32'; public static $FOREGROUND_LIGHT_GREEN = '1;32'; public static $FOREGROUND_CYAN = '0;36'; public static $FOREGROUND_LIGHT_CYAN = '1;36'; public static $FOREGROUND_RED = '0;31'; public static $FOREGROUND_LIGHT_RED = '1;31'; public static $FOREGROUND_PURPLE = '0;35'; public static $FOREGROUND_LIGHT_PURPLE = '1;35'; public static $FOREGROUND_BROWN = '0;33'; public static $FOREGROUND_YELLOW = '1;33'; public static $FOREGROUND_LIGHT_GRAY = '0;37'; public static $FOREGROUND_WHITE = '1;37'; public static $FOREGROUND_BOLD = '1'; public static $FOREGROUND_UNDERLINE = '4'; public static $FOREGROUND_ITALIC = '3'; public static $FOREGROUND_INVERT = '7'; public static $FOREGROUND_STRIKEOUT = '9'; // background colors public static $BACKGROUND_BLACK = '40'; public static $BACKGROUND_RED = '41'; public static $BACKGROUND_GREEN = '42'; public static $BACKGROUND_YELLOW = '43'; public static $BACKGROUND_BLUE = '44'; public static $BACKGROUND_MAGENTA = '45'; public static $BACKGROUND_CYAN = '46'; public static $BACKGROUND_LIGHT_GRAY = '47'; /** * Dynamically call the static methods from instance variables * and provide the correct arguments as needed * * @param string $name * @param array $arguments * @return string */ public function __call($name, $arguments) /** * Colorize a string of text and return it * * @param string $text * @param string $color * * @return string */ public static function colorizeString($text, $color) /** * strikethrough some text * * @param string $text * @return string */ public static function strikeout($text) /** * invert the foreground of a string * * @param string $text * @return string */ public static function invert($text) /** * bold the foreground of a string * * @param string $text * @return string */ public static function bold($text) /** * Italic the foreground of a string * * @param string $text * @return string */ public static function italic($text) /** * Underline the foreground of a string * * @param string $text * @return string */ public static function underline($text) /** * Colorize the foreground of a string * * @param string $text * @return string */ public static function black($text) public static function darkGray($text) public static function blue($text) public static function lightBlue($text) public static function green($text) public static function lightGreen($text) public static function cyan($text) public static function lightCyan($text) public static function red($text) public static function lightRed($text) public static function purple($text) public static function lightPurple($text) public static function brown($text) public static function yellow($text) public static function lightGray($text) public static function white($text) /** * Colorize the background of a string * * @param string $text * @return string */ public static function bgBlack($text) public static function bgRed($text) public static function bgGreen($text) public static function bgYellow($text) public static function bgBlue($text) public static function bgMagenta($text) public static function bgCyan($text) public static function bgLightGray($text) ## ColorInterface You can use the ColorInterface.php file to implement your own ANSI Colorization class. The interface requires all the functions that the Colorize class implements, but does not care about how you define your colors or what is going on below the hood.
Change Log
Please see Change Log for more information.
License
The MIT License (MIT). Please see License File for more information.
sevenecks/ansi 适用场景与选型建议
sevenecks/ansi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.62k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 12 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cli」 「console」 「shell」 「colors」 「color」 「ansi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sevenecks/ansi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sevenecks/ansi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sevenecks/ansi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This class provides you with an easy-to-use interface to progress bars.
A Laravel package to retrieve data from Google Search Console
Additional artisan commands for Laravel
AMWSCAN (Antimalware Scanner) is a php antimalware/antivirus scanner console script written in php for scan your project. This can work on php projects and a lot of others platform.
Shell command module for PHP.
PHP library for the MUMSYS project
统计信息
- 总下载量: 6.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 30
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-08