tdtrung17693/php-chalk

PHP 终端字符串样式库之一

v1.0.0 2019-06-11 16:31 UTC

This package is auto-updated.

Last update: 2024-09-20 11:41:49 UTC


README

一个受Chalk启发的 PHP 终端样式库

特性

  • 支持 16 种颜色、256 种颜色和 Truecolor (16m 颜色) 模式。
  • 支持样式链。
  • 支持样式嵌套。

安装

通过 composer

composer require tdtrung17693/php-chalk

手动:

只需下载/克隆此仓库

用法

查看 examples 了解如何使用此库的更多信息。

print $chalk->bold->green("Bold Green");
print "\n";
print $chalk->underscore->color220->bgColor20("Blink Foreground 220 Background 20");
print "\n";
print $chalk->rgb(200, 20, 100)->inverse("Inverse");

// Style nesting
print $chalk->red("Red then", $chalk->bold->green("bold and green then"), $chalk->reset("back to normal\n"));

屏幕截图:

Examples

Color blocks

API

$chalk-><style>[-><style>...](string, [string...])

示例: $chalk->bgGreen->red->bold('背景绿色红色加粗文本')

$chalk->hasColorSupport(), $chalk->has256Support(), $chalk->has16mSupport()

如果支持相应的功能则返回 true。

支持样式

  • reset, bold, dim, underscore, italic, strikethrough, blink.
  • red, green, yellow, blue, magenta, cyan, white
  • lightGray, darkGray, lightRed, lightGreen, lightYellow, lightBlue, lightMagenta, lightCyan
  • 上述每种颜色样式前都有 bg 前缀

贡献

欢迎通过分支或提出建议来贡献。