| Crates.io | cnxt |
| lib.rs | cnxt |
| version | 0.1.6 |
| created_at | 2025-04-04 15:12:37.698606+00 |
| updated_at | 2025-04-19 01:52:01.532503+00 |
| description | Coloring made simple, for your terminal. |
| homepage | |
| repository | https://github.com/cnlancehu/cnxt |
| max_upload_size | |
| id | 1620206 |
| size | 129,306 |
Run cargo run --example banner -r to print the Banner!
An enhanced fork of colored offering superior performance and terminal handling.
Why CNXT?
Cow for intelligent memory
management (Inspired by this PR)Coloring your terminal made simple. You already know how to do it.

For Windows targets, add this to enable colors in Windows CMD:
#[cfg(windows)]
cnxt::control::set_virtual_terminal(true);
Comparison showing how Windows CMD displays colors before and after enabling virtual terminal.

CNXT dynamically detects terminal color support across three tiers:
Ansi16 (16 colors)Ansi256 (256 colors)TrueColorWhen using colors beyond your terminal's capabilities, CNXT automatically downgrades them to the maximum supported level.
Manual control options:
use cnxt::control::{set_should_colorize, ShouldColorize};
// Environment-based detection level (default)
set_should_colorize(ShouldColorize::from_env());
// Explicit configuration
set_should_colorize(ShouldColorize::YesWithTrueColor); // Force truecolor
set_should_colorize(ShouldColorize::YesWithAnsi256); // Force 256-color
set_should_colorize(ShouldColorize::No); // Disable colors
set_should_colorize(ShouldColorize::Yes); // Enable colors with auto-detect level
// Manual color fallback
use cnxt::Color;
let truecolor = Color::TrueColor { r: 166, g: 227, b: 161 };
let ansi16 = truecolor.fallback_to_ansi16();
let ansi256 = truecolor.fallback_to_ansi256();
terminal-detection (Enabled by default):
Automatically detects terminal color support and downgrades colors accordingly.
Defaultly use TrueColor if disable this feature.
conditional-coloring : Provide helper functions to colorize strings based on conditions.
use cnxt::Colorize as _;
println!("{}", "red".red_if(true)); // print red color
println!("{}", "red".red_if(false)); // print no color
println!("{}", "green".green().red_if(false)); // print green color
CNXT maintains the original MPL-2.0 License from the colored project.