overtrue/bash-color

用于输出格式化bash文本的工具。

0.0.1 2015-08-21 02:52 UTC

This package is auto-updated.

Last update: 2024-08-25 12:59:16 UTC


README

生成带颜色的命令行文本。为命令行文字添加前景/背景色以及修饰效果。

Build Status Latest Stable Version Latest Unstable Version Code Coverage Scrutinizer Code Quality Total Downloads License

安装

$ composer require "overtrue/bash-color"

用法

use Overtrue\BashColor\BashColor;

echo BashColor::render('<fg=green>Are you sure ?</><fg=yellow> [Y/n]:</>'), "\n";
echo BashColor::render('<bg=purple;>hello world!</>'), "\n";
echo BashColor::render('<fg=green;opt=bold>yes!</>'), "\n";
echo BashColor::render('<fg=cyan;opt=bold;bg=red>ugly!</>'), "\n";

结果

qq20150822-1 2x

属性

  • fg 前景色。
  • bg 背景色。
  • opt 选项。

前景色

'default'       // Default (usually green, white or light gray)
'black'         // Black
'red'           // Red (don't use with green background)
'green'         // Green
'yellow'        // Yellow
'blue'          // Blue
'magenta'       // Magenta/Purple
'purple'        // Magenta/Purple
'cyan'          // Cyan
'light_gray'    // Light Gray
'dark_gray'     // Dark Gray
'light_red'     // Light Red
'light_green'   // Light Green
'light_yellow'  // Light Yellow
'light_blue'    // Light Blue
'light_magenta' // Light Magenta/pink
'light_pink'    // Light Magenta/pink
'light_cyan'    // Light Cyan
'white'         // White

背景色

'default'       // Default background color (usually black or blue)
'black'         // Black
'red'           // Red
'green'         // Green
'yellow'        // Yellow
'blue'          // Blue
'magenta'       // Magenta/Purple
'PURPLE'        // Magenta/Purple
'cyan'          // Cyan
'light_gray'    // Light Gray (don't use with white foreground)
'dark_gray'     // Dark Gray (don't use with black foreground)
'light_red'     // Light Red
'light_green'   // Light Green (don't use with white foreground)
'light_yellow'  // Light Yellow (don't use with white foreground)
'light_blue'    // Light Blue (don't use with light yellow foreground)
'light_magenta' // Light Magenta/Pink (don't use with light foreground)
'light_cyan'    // Light Cyan (don't use with white foreground)
'white'         // White (don't use with light foreground)

选项

'none'       // Reset/Remove all option
'bold'       // Bold/Bright
'bright'     // Bold/Bright
'dim'        // Dim
'underlined' // Underlined
'blink'      // Blink
'reverse'    // Reverse/invert
'invert'     // Reverse/invert
'hidden'     // Hidden

参考

Bash技巧:颜色和格式化

PHP 扩展包开发

想知道如何从零开始构建PHP扩展包吗?

请关注我的实战课程,我将在该课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

许可证

MIT