chromakitx 1.0.2

A comprehensive color manipulation library for Rust
Documentation
// SPDX-FileCopyrightText: 2023 CELESTIFYX Team
// SPDX-License-Identifier: GPL-3.0-or-later

use super::EnumColor;

use crate::{
    ColorFormattable,
    define_ansi_colors
};

define_ansi_colors! {
    Black = (30, 40),
    Red = (31, 41),
    Green = (32, 42),
    Yellow = (33, 43),
    Blue = (34, 44),
    Magenta = (35, 45),
    Cyan = (36, 46),
    White = (37, 47),
    Default = (39, 49),
    BrightBlack = (90, 100),
    BrightRed = (91, 101),
    BrightGreen = (92, 102),
    BrightYellow = (93, 103),
    BrightBlue = (94, 104),
    BrightMagenta = (95, 105),
    BrightCyan = (96, 106),
    BrightWhite = (97, 107)
}

impl ColorFormattable for AnsiColor {
    fn format(&self, is_background: bool) -> String {
        let (fg, bg): (u8, u8) = self.values();

        format!("\x1B[{}m", if is_background {
            bg
        } else {
            fg
        })
    }
}

impl EnumColor for AnsiColor {
    fn from_name(name: &str) -> Option<Self> {
        Self::from_str(name).ok()
    }
}