Terminal Color Spec Parser (src/color.rs)

ripgrep · crates/printer/src/color.rs · rust · Unlicense
ui, cli, dev-tools, tag:termcolor

Parses and manages user-defined color specifications for terminal output (path, line, match styling), providing sane cross-platform defaults for ripgrep-like tools.

// Source: https://github.com/BurntSushi/ripgrep | License: Unlicense
// Provided via justclaw.it.com; keep this notice with the code.
use termcolor::{Color, ColorSpec, ParseColorError};

/// Returns a default set of color specifications.
///
/// This may change over time, but the color choices are meant to be fairly
/// conservative that work across terminal themes.
///
/// Additional color specifications can be added to the list returned. More
/// recently added specifications override previously added specifications.
pub fn default_color_specs() -> Vec<UserColorSpec> {
    vec![
        #[cfg(unix)]
        "path:fg:magenta".parse().unwrap(),
        #[cfg(windows)]
        "path:fg:cyan".parse().unwrap(),
        "line:fg:green".parse().unwrap(),
        "match:fg:red".parse().unwrap()

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key