Crate cnxt

Source
Expand description

§Colored Next (CNXT)

badge

A fork of colored which introduces better functionalities.

§Usage

Coloring your terminal made simple. You already know how to do it.

§Basic

usage

§Advanced

  1. For Windows targets, add this to enable colors in Windows CMD:

    #[cfg(windows)]
    cnxt::control::set_virtual_terminal(true);

    Comparison of colors with virtual terminal disabled vs enabled.

    comparison

  2. CNXT automatically detects terminal color support across 3 levels:

    • Ansi16
    • Ansi256
    • TrueColor

    When using colors beyond your terminal’s capabilities, CNXT automatically downgrades them to the maximum supported level.

    use cnxt::control::{set_should_colorize, ShouldColorize};
    
    // By default, the support level is detected from environment
    ShouldColorize::from_env()
    
    // You can explicitly set the support level:
    set_should_colorize(ShouldColorize::YesWithTrueColor);  // Enable colorization with true color support
    set_should_colorize(ShouldColorize::YesWithAnsi256);    // Enable colorization with 256 color support
    
    // Simple on/off control:
    set_should_colorize(ShouldColorize::No);    // Disable colorization
    set_should_colorize(ShouldColorize::Yes);   // Enable colorization
    
    // Reset to environment-based detection:
    set_should_colorize(ShouldColorize::from_env());

    And for manual color fallback control:

    use cnxt::Color;
     
    let color = Color::TrueColor {
        r: 166,
        g: 227,
        b: 161,
    };
    let ansi16_color = color.fallback_to_ansi16();
    let ansi256_color = color.fallback_to_ansi256();

Re-exports§

pub use self::customcolors::CustomColor;

Modules§

control
A couple of functions to set whether to colorize.
customcolors
Custom colors support.

Structs§

ColoredString
A string that may have color and/or style applied to it.
Style
A combinatorial style such as bold, italics, dimmed, etc.

Enums§

Color
The 16 standard colors, Ansi256 and TrueColor.
Styles
Enum containing all of the available style settings that can be applied to a Styles and by extension, a colrized type.

Traits§

Colorize
The trait that enables something to be given color.