PHPackages                             sugarcraft/candy-palette - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sugarcraft/candy-palette

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sugarcraft/candy-palette
========================

PHP port of charmbracelet/colorprofile — magical terminal color profile detection and color degradation (TrueColor → ANSI256 → ANSI → ASCII).

02.5k↑1427.8%1PHP

Since Jun 29Pushed 1mo agoCompare

[ Source](https://github.com/sugarcraft/candy-palette)[ Packagist](https://packagist.org/packages/sugarcraft/candy-palette)[ RSS](/packages/sugarcraft-candy-palette/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (1)

[![candy-palette](.assets/icon.png)](.assets/icon.png)

[![CI](https://github.com/detain/sugarcraft/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/detain/sugarcraft/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/f094f75a8f2fb1662df0284686bbbee90d19ba98a987fd76cf2168d8152c7837/68747470733a2f2f636f6465636f762e696f2f67682f64657461696e2f737567617263726166742f6272616e63682f6d61737465722f67726170682f62616467652e7376673f666c61673d63616e64792d70616c65747465)](https://app.codecov.io/gh/detain/sugarcraft?flags%5B0%5D=candy-palette)[![Packagist Version](https://camo.githubusercontent.com/137d6c4bf56968240499436e91165543a876ff5a57699d49cd43737aeeba08d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737567617263726166742f63616e64792d70616c657474653f6c6162656c3d7061636b6167697374)](https://packagist.org/packages/sugarcraft/candy-palette)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP](https://camo.githubusercontent.com/e78ffc83837c0d12647811a7fd1910c3cbeae04988de94bb4fd5b67e0874696a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d254532253839254135382e312d3838393262662e737667)](https://www.php.net/)

CandyPalette
============

[](#candypalette)

PHP port of [charmbracelet/colorprofile](https://github.com/charmbracelet/colorprofile) — magical terminal color profile detection and color degradation.

Features
--------

[](#features)

- **Detect terminal color profile** from environment variables and TTY info
- **Profile enum**: `TrueColor` (24-bit) → `ANSI256` (255-color) → `ANSI` (16-color) → `Ascii` (no color) → `NoTTY`
- **Color conversion**: downsample RGBA colors to any target profile
- **ProfileWriter**: wrap a stream and automatically degrade color codes to match the terminal
- **ANSI stripping**: `NoTTY` strips all ANSI sequences from output
- **Environment-aware**: reads `TERM`, `COLORTERM`, `FORCE_COLOR`, `NO_COLOR`, `TERM_PROGRAM`
- **Probe class**: static env-detection layer with precedence-ordered rules + infocmp Phase 2 upgrade
- **ColorProfile enum**: SSOT env-detection enum (NoTTY/Ascii/Ansi/Ansi256/TrueColor) for libs that need raw profile values without constructing a Palette instance

Install
-------

[](#install)

```
composer require sugarcraft/candy-palette
```

Quick Start
-----------

[](#quick-start)

```
use SugarCraft\Palette\Palette;
use SugarCraft\Palette\Profile;
use SugarCraft\Palette\Color;

// Detect the terminal's color profile
$profile = Palette::detect();

echo "Your terminal supports: " . $profile->name . "\n";

// Convert a TrueColor color to the detected profile
$color = new Color(0x6b, 0x50, 0xff, 0xff); // #6b50ff
$converted = Palette::convert($color, $profile);
echo "Converted: " . $converted->toAnsi() . "\n";

// Wrap stdout for automatic color degradation
$writer = ProfileWriter::wrap(STDOUT, [
    'TERM' => getenv('TERM'),
    'COLORTERM' => getenv('COLORTERM'),
]);
fwrite($writer, "\x1b[38;2;107;80;255mFancy text\x1b[0m\n");
```

Profiles
--------

[](#profiles)

ProfileColorsDescriptionTrueColor16.7MFull 24-bit RGB (24-bit ANSI)ANSI256256216 cube + 24 grey + 16 standardANSI16Standard terminal colorsAscii2Black &amp; whiteNoTTY0No color (ANSI stripped)Color Degradation
-----------------

[](#color-degradation)

```
use SugarCraft\Palette\Palette;
use SugarCraft\Palette\Profile;
use SugarCraft\Palette\Color;

$color = new Color(100, 50, 255, 255);

// Auto-detect
$converted = Palette::convert($color, Palette::detect());

// Manual downgrade
$ansi256 = Palette::convert($color, Profile::ANSI256);
$ansi    = Palette::convert($color, Profile::ANSI);
```

Probe — Static Environment Detection
------------------------------------

[](#probe--static-environment-detection)

The `Probe` class provides precedence-ordered environment probing for terminal color capability and reduced-motion preference. Use it directly when you need raw detection values without constructing a `Palette` instance.

```
use SugarCraft\Palette\Probe;
use SugarCraft\Palette\ColorProfile;

// Detect the negotiated color profile
$profile = Probe::colorProfile(); // ColorProfile::TrueColor|Ansi256|Ansi|Ascii|NoTTY
echo $profile->label(); // "TrueColor"

// Check for explicit disable/enable flags
if (Probe::isNoColor()) {
    // NO_COLOR env var is set — disable all color output
}
if (Probe::isForceColor()) {
    // CLICOLOR_FORCE=1 — force full color regardless of terminal
}

// Reduced-motion preference (REDUCE_MOTION or PREFERS_REDUCED_MOTION)
if (Probe::reducedMotion()) {
    // Skip animations, spinners, and other motion
}
```

**Detection precedence** (mirrors [charmbracelet/colorprofile](https://github.com/charmbracelet/colorprofile)):

1. `CLICOLOR_FORCE=1` → `TrueColor` (overrides everything)
2. `NO_COLOR` (any value) → `NoTTY`
3. `CLICOLOR=0` → `NoTTY`
4. `TERM=dumb` → `NoTTY`
5. `COLORTERM=24bit|truecolor|yes` → `TrueColor`
6. `WT_SESSION` (set) → `TrueColor` (Windows Terminal)
7. `GOOGLE_CLOUD_SHELL=true` → `TrueColor`
8. `TMUX`/`STY` + `screen*`/`tmux*` base term → `Ansi256`
9. `TERM=xterm-kitty|xterm-ghostty|*-256color` → `Ansi256`
10. `TERM=xterm*|screen*|tmux*` → `Ansi`
11. Default → `Ansi`, then **Phase 2 infocmp upgrade** → `TrueColor` if `Tc`/`RGB` capability found

ColorProfile Enum
-----------------

[](#colorprofile-enum)

`ColorProfile` is the SSOT enum for environment-driven color capability. It is used by `Probe` and consumed by libs that need the raw profile value (candy-log, candy-mosaic, candy-freeze, candy-vt).

```
use SugarCraft\Palette\ColorProfile;

$profile = Probe::colorProfile();

// Human-readable label
echo $profile->label(); // "TrueColor"
```

CaseValueLabel`NoTTY``'notty'`No TTY`Ascii``'ascii'`ASCII`Ansi``'ansi'`ANSI`Ansi256``'ansi256'`ANSI 256`TrueColor``'truecolor'`TrueColorArchitecture
------------

[](#architecture)

```
SugarCraft\Palette\
├── Color          — RGBA color value object with conversion methods (Color::namedColors() lists standard names)
├── Palette        — instance-based detection + degradation + ProfileWriter
├── Profile         — legacy detection enum (richest→simplest order)
├── ColorProfile    — new SSOT detection enum (simplest→richest order, Probe-driven)
├── Probe           — static env-probe layer (colorProfile/isNoColor/isForceColor/reducedMotion)
├── StandardColors  — ANSI/ANSI256 standard palette
├── ProfileWriter  — stream wrapper for automatic color degradation
└── Lang           — i18n strings

```

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance59

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1036e0717211b8030b83cbe729e8ba6ba442fdbd5285fb97a39d7dcfe339342?d=identicon)[detain](/maintainers/detain)

---

Top Contributors

[![detain](https://avatars.githubusercontent.com/u/1364504?v=4)](https://github.com/detain "detain (80 commits)")

### Embed Badge

![Health badge](/badges/sugarcraft-candy-palette/health.svg)

```
[![Health](https://phpackages.com/badges/sugarcraft-candy-palette/health.svg)](https://phpackages.com/packages/sugarcraft-candy-palette)
```

###  Alternatives

[symfony/polyfill-php70

Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions

3.2k202.3M61](/packages/symfony-polyfill-php70)[laravel-admin-ext/grid-lightbox

Turn your grid into a lightbox &amp; gallery

58186.3k2](/packages/laravel-admin-ext-grid-lightbox)

PHPackages © 2026

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