PHPackages                             questocat/console-color - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. questocat/console-color

ActiveLibrary[CLI &amp; Console](/categories/cli)

questocat/console-color
=======================

A simple command line colorize library

v1.0.0(8y ago)453.1k↓50%12MITPHPPHP &gt;=5.5.0

Since Apr 14Pushed 7y ago1 watchersCompare

[ Source](https://github.com/questocat/console-color)[ Packagist](https://packagist.org/packages/questocat/console-color)[ RSS](/packages/questocat-console-color/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (2)

console-color
-------------

[](#console-color)

A simple command line colorize library

[![StyleCI](https://camo.githubusercontent.com/83fb527143ce95f315bbe2f799b9272ec384b9ef575c0ab6da9c9cd7cca8fb6e/68747470733a2f2f7374796c6563692e696f2f7265706f732f39363332343733342f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/96324734)[![Build Status](https://camo.githubusercontent.com/b71d9afa41e67f69d528ce49ac0bf27872decd90cf4e7efb689a86b1c0151c56/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f71756573746f6361742f636f6e736f6c652d636f6c6f722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/emanci/console-color/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/aa0aac5462d949bb374960747403c19ea327d75e1b937fc390f418a054ba6a3b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f71756573746f6361742f636f6e736f6c652d636f6c6f722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/emanci/console-color/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b4b194912b6a719dd05dc79431fb40d06fd7db1295799eb744423d8002f9141a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f71756573746f6361742f636f6e736f6c652d636f6c6f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/emanci/console-color/?branch=master)[![Packagist](https://camo.githubusercontent.com/a4b7a1d8377c4252b62962b12857454a352b488c7f58770dcbcadcffaf57247b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f646f637472696e652f6f726d2e737667)](https://packagist.org/packages/questocat/console-color)

Installation
------------

[](#installation)

Using [Composer](https://getcomposer.org) to add the package to your project's dependencies:

```
composer require questocat/console-color
```

Usage
-----

[](#usage)

```
$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

[![example-output](https://github.com/questocat/console-color/raw/master/colors.png)](https://github.com/questocat/console-color/blob/master/colors.png)

#### Colors/Formats Api

[](#colorsformats-api)

ForegroundBackgroundFormatsThemesdefaultdefaultBackgroundboldinfoblackblackBackgrounddimwarningredredBackgroundunderlineerrorgreengreenBackgroundblinksuccessyellowyellowBackgroundinvertblueblueBackgroundhiddenmagentamagentaBackgroundcyancyanBackgroundlightGraylightGrayBackgrounddarkGraydarkGrayBackgroundlightRedlightRedBackgroundlightGreenlightGreenBackgroundlightYellowlightYellowBackgroundlightBluelightBlueBackgroundlightMagentalightMagentaBackgroundlightCyanlightCyanBackgroundwhitewhiteBackgroundReference
---------

[](#reference)

- [bash:tip\_colors\_and\_formatting](http://misc.flogisoft.com/bash/tip_colors_and_formatting#colors2)
- [Wiki-Bash/Prompt\_customization#Colors](https://wiki.archlinux.org/index.php/Bash/Prompt_customization#Colors)
- [Wiki-ANSI\_escape\_code#Colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors)

License
-------

[](#license)

Licensed under the [MIT license](https://github.com/questocat/console-color/blob/master/LICENSE).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2949d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ce15799177be83de6d4b3c35f56c3eb827dc01d6baf78dc1e23a9b9d2bc859e?d=identicon)[questocat](/maintainers/questocat)

---

Top Contributors

[![voocx](https://avatars.githubusercontent.com/u/8717817?v=4)](https://github.com/voocx "voocx (45 commits)")

---

Tags

bashbash-colorcli-colorcolorconsole-colorcliconsolecolorbashconsole-color

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/questocat-console-color/health.svg)

```
[![Health](https://phpackages.com/badges/questocat-console-color/health.svg)](https://phpackages.com/packages/questocat-console-color)
```

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B11.3k](/packages/symfony-console)[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k331.8M8.5k](/packages/nunomaduro-collision)[nunomaduro/termwind

It's like Tailwind CSS, but for the console.

2.5k239.8M286](/packages/nunomaduro-termwind)[kevinlebrun/colors.php

Colors for PHP CLI scripts

3426.7M45](/packages/kevinlebrun-colorsphp)[wp-cli/php-cli-tools

Console utilities for PHP

68325.0M367](/packages/wp-cli-php-cli-tools)[alecrabbit/php-console-spinner

Extremely flexible spinner for \[async\] php cli applications

24032.0k2](/packages/alecrabbit-php-console-spinner)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
