use std::fmt::Display;
#[derive(Debug, Clone, Copy)]
struct RGB {
r: u8,
g: u8,
b: u8,
}
#[allow(dead_code)]
impl RGB {
fn new(r: u8, g: u8, b: u8) -> Self {
RGB { r, g, b }
}
fn to_hex(&self) -> String {
format!("#{:02x}{:02x}{:02x}", self.r, self.g, self.b)
}
}
fn hex_to_rgb(hex: &str) -> Option<RGB> {
let hex = hex.trim_start_matches('#');
if hex.len() != 6 {
return None;
}
let r = u8::from_str_radix(&hex[0..2], 16).ok()?;
let g = u8::from_str_radix(&hex[2..4], 16).ok()?;
let b = u8::from_str_radix(&hex[4..6], 16).ok()?;
Some(RGB::new(r, g, b))
}
fn is_hex_color(s: &str) -> bool {
let s = s.trim_start_matches('#');
s.len() == 6 && s.chars().all(|c| c.is_ascii_hexdigit())
}
fn is_rgb_color(s: &str) -> bool {
s.starts_with("rgb(") && s.ends_with(')')
}
fn parse_rgb(s: &str) -> Option<RGB> {
let contents = s.trim_start_matches("rgb(").trim_end_matches(')');
let parts: Vec<&str> = contents.split(',').collect();
if parts.len() != 3 {
return None;
}
let r = parts[0].trim().parse().ok()?;
let g = parts[1].trim().parse().ok()?;
let b = parts[2].trim().parse().ok()?;
Some(RGB::new(r, g, b))
}
fn identify_color_type(s: &str) -> ColorType {
if is_hex_color(s) {
ColorType::Hex
} else if is_rgb_color(s) {
ColorType::RGB
} else if s.starts_with("text_") || s.starts_with("bg_") {
ColorType::Accent
} else {
ColorType::Default
}
}
enum ColorType {
Hex,
RGB,
Accent,
Default,
}
pub trait Colors {
fn text_default(&self) -> String;
fn bg_default(&self) -> String;
fn text_black(&self) -> String;
fn bg_black(&self) -> String;
fn text_red(&self) -> String;
fn bg_red(&self) -> String;
fn text_blue(&self) -> String;
fn bg_blue(&self) -> String;
fn text_green(&self) -> String;
fn bg_green(&self) -> String;
fn text_yellow(&self) -> String;
fn bg_yellow(&self) -> String;
fn text_magenta(&self) -> String;
fn bg_magenta(&self) -> String;
fn text_cyan(&self) -> String;
fn bg_cyan(&self) -> String;
fn text_white(&self) -> String;
fn bg_white(&self) -> String;
fn text_gray(&self) -> String;
fn bg_gray(&self) -> String;
fn text_red_bright(&self) -> String;
fn bg_red_bright(&self) -> String;
fn text_blue_bright(&self) -> String;
fn bg_blue_bright(&self) -> String;
fn text_green_bright(&self) -> String;
fn bg_green_bright(&self) -> String;
fn text_yellow_bright(&self) -> String;
fn bg_yellow_bright(&self) -> String;
fn text_magenta_bright(&self) -> String;
fn bg_magenta_bright(&self) -> String;
fn text_cyan_bright(&self) -> String;
fn bg_cyan_bright(&self) -> String;
fn text_white_bright(&self) -> String;
fn bg_white_bright(&self) -> String;
fn text_red_50(&self) -> String;
fn bg_red_50(&self) -> String;
fn text_red_100(&self) -> String;
fn bg_red_100(&self) -> String;
fn text_red_200(&self) -> String;
fn bg_red_200(&self) -> String;
fn text_red_300(&self) -> String;
fn bg_red_300(&self) -> String;
fn text_red_400(&self) -> String;
fn bg_red_400(&self) -> String;
fn text_red_500(&self) -> String;
fn bg_red_500(&self) -> String;
fn text_red_600(&self) -> String;
fn bg_red_600(&self) -> String;
fn text_red_700(&self) -> String;
fn bg_red_700(&self) -> String;
fn text_red_800(&self) -> String;
fn bg_red_800(&self) -> String;
fn text_red_900(&self) -> String;
fn bg_red_900(&self) -> String;
fn text_red_950(&self) -> String;
fn bg_red_950(&self) -> String;
fn text_yellow_50(&self) -> String;
fn bg_yellow_50(&self) -> String;
fn text_yellow_100(&self) -> String;
fn bg_yellow_100(&self) -> String;
fn text_yellow_200(&self) -> String;
fn bg_yellow_200(&self) -> String;
fn text_yellow_300(&self) -> String;
fn bg_yellow_300(&self) -> String;
fn text_yellow_400(&self) -> String;
fn bg_yellow_400(&self) -> String;
fn text_yellow_500(&self) -> String;
fn bg_yellow_500(&self) -> String;
fn text_yellow_600(&self) -> String;
fn bg_yellow_600(&self) -> String;
fn text_yellow_700(&self) -> String;
fn bg_yellow_700(&self) -> String;
fn text_yellow_800(&self) -> String;
fn bg_yellow_800(&self) -> String;
fn text_yellow_900(&self) -> String;
fn bg_yellow_900(&self) -> String;
fn text_yellow_950(&self) -> String;
fn bg_yellow_950(&self) -> String;
fn text_green_50(&self) -> String;
fn bg_green_50(&self) -> String;
fn text_green_100(&self) -> String;
fn bg_green_100(&self) -> String;
fn text_green_200(&self) -> String;
fn bg_green_200(&self) -> String;
fn text_green_300(&self) -> String;
fn bg_green_300(&self) -> String;
fn text_green_400(&self) -> String;
fn bg_green_400(&self) -> String;
fn text_green_500(&self) -> String;
fn bg_green_500(&self) -> String;
fn text_green_600(&self) -> String;
fn bg_green_600(&self) -> String;
fn text_green_700(&self) -> String;
fn bg_green_700(&self) -> String;
fn text_green_800(&self) -> String;
fn bg_green_800(&self) -> String;
fn text_green_900(&self) -> String;
fn bg_green_900(&self) -> String;
fn text_green_950(&self) -> String;
fn bg_green_950(&self) -> String;
fn text_blue_50(&self) -> String;
fn bg_blue_50(&self) -> String;
fn text_blue_100(&self) -> String;
fn bg_blue_100(&self) -> String;
fn text_blue_200(&self) -> String;
fn bg_blue_200(&self) -> String;
fn text_blue_300(&self) -> String;
fn bg_blue_300(&self) -> String;
fn text_blue_400(&self) -> String;
fn bg_blue_400(&self) -> String;
fn text_blue_500(&self) -> String;
fn bg_blue_500(&self) -> String;
fn text_blue_600(&self) -> String;
fn bg_blue_600(&self) -> String;
fn text_blue_700(&self) -> String;
fn bg_blue_700(&self) -> String;
fn text_blue_800(&self) -> String;
fn bg_blue_800(&self) -> String;
fn text_blue_900(&self) -> String;
fn bg_blue_900(&self) -> String;
fn text_blue_950(&self) -> String;
fn bg_blue_950(&self) -> String;
fn text_purple_50(&self) -> String;
fn bg_purple_50(&self) -> String;
fn text_purple_100(&self) -> String;
fn bg_purple_100(&self) -> String;
fn text_purple_200(&self) -> String;
fn bg_purple_200(&self) -> String;
fn text_purple_300(&self) -> String;
fn bg_purple_300(&self) -> String;
fn text_purple_400(&self) -> String;
fn bg_purple_400(&self) -> String;
fn text_purple_500(&self) -> String;
fn bg_purple_500(&self) -> String;
fn text_purple_600(&self) -> String;
fn bg_purple_600(&self) -> String;
fn text_purple_700(&self) -> String;
fn bg_purple_700(&self) -> String;
fn text_purple_800(&self) -> String;
fn bg_purple_800(&self) -> String;
fn text_purple_900(&self) -> String;
fn bg_purple_900(&self) -> String;
fn text_purple_950(&self) -> String;
fn bg_purple_950(&self) -> String;
fn text_pink_50(&self) -> String;
fn bg_pink_50(&self) -> String;
fn text_pink_100(&self) -> String;
fn bg_pink_100(&self) -> String;
fn text_pink_200(&self) -> String;
fn bg_pink_200(&self) -> String;
fn text_pink_300(&self) -> String;
fn bg_pink_300(&self) -> String;
fn text_pink_400(&self) -> String;
fn bg_pink_400(&self) -> String;
fn text_pink_500(&self) -> String;
fn bg_pink_500(&self) -> String;
fn text_pink_600(&self) -> String;
fn bg_pink_600(&self) -> String;
fn text_pink_700(&self) -> String;
fn bg_pink_700(&self) -> String;
fn text_pink_800(&self) -> String;
fn bg_pink_800(&self) -> String;
fn text_pink_900(&self) -> String;
fn bg_pink_900(&self) -> String;
fn text_pink_950(&self) -> String;
fn bg_pink_950(&self) -> String;
fn text_black_50(&self) -> String;
fn bg_black_50(&self) -> String;
fn text_black_100(&self) -> String;
fn bg_black_100(&self) -> String;
fn text_black_200(&self) -> String;
fn bg_black_200(&self) -> String;
fn text_black_300(&self) -> String;
fn bg_black_300(&self) -> String;
fn text_black_400(&self) -> String;
fn bg_black_400(&self) -> String;
fn text_black_500(&self) -> String;
fn bg_black_500(&self) -> String;
fn text_black_600(&self) -> String;
fn bg_black_600(&self) -> String;
fn text_black_700(&self) -> String;
fn bg_black_700(&self) -> String;
fn text_black_800(&self) -> String;
fn bg_black_800(&self) -> String;
fn text_black_900(&self) -> String;
fn bg_black_900(&self) -> String;
fn text_black_950(&self) -> String;
fn bg_black_950(&self) -> String;
fn text_gradient(&self, steps: &[&'static str]) -> String;
fn bg_gradient(&self, steps: &[&'static str]) -> String;
fn code(&self, code: usize) -> String;
fn codes(&self, initial: usize, codes: (usize, usize, usize)) -> String;
}
impl<T> Colors for T
where
T: Display,
{
fn code(&self, code: usize) -> String {
format!("\x1B[{}m{}\x1B[0m", code, self)
}
fn codes(&self, initial: usize, (a, b, c): (usize, usize, usize)) -> String {
format!("\x1B[{initial};2;{a};{b};{c}m{self}\x1B[{}m", initial + 1)
}
fn text_black(&self) -> String {
self.code(30)
}
fn bg_black(&self) -> String {
self.code(40)
}
fn text_red(&self) -> String {
self.code(31)
}
fn bg_red(&self) -> String {
self.code(41)
}
fn text_blue(&self) -> String {
self.code(34)
}
fn bg_blue(&self) -> String {
self.code(44)
}
fn text_green(&self) -> String {
self.code(32)
}
fn bg_green(&self) -> String {
self.code(42)
}
fn text_yellow(&self) -> String {
self.code(33)
}
fn bg_yellow(&self) -> String {
self.code(43)
}
fn text_magenta(&self) -> String {
self.code(35)
}
fn bg_magenta(&self) -> String {
self.code(45)
}
fn text_cyan(&self) -> String {
self.code(36)
}
fn bg_cyan(&self) -> String {
self.code(46)
}
fn text_white(&self) -> String {
self.code(37)
}
fn bg_white(&self) -> String {
self.code(47)
}
fn text_default(&self) -> String {
self.code(39)
}
fn bg_default(&self) -> String {
self.code(49)
}
fn text_gray(&self) -> String {
self.code(90)
}
fn bg_gray(&self) -> String {
self.code(100)
}
fn text_red_bright(&self) -> String {
self.code(91)
}
fn bg_red_bright(&self) -> String {
self.code(101)
}
fn text_green_bright(&self) -> String {
self.code(92)
}
fn bg_green_bright(&self) -> String {
self.code(102)
}
fn text_yellow_bright(&self) -> String {
self.code(93)
}
fn bg_yellow_bright(&self) -> String {
self.code(103)
}
fn text_blue_bright(&self) -> String {
self.code(94)
}
fn bg_blue_bright(&self) -> String {
self.code(104)
}
fn text_magenta_bright(&self) -> String {
self.code(95)
}
fn bg_magenta_bright(&self) -> String {
self.code(105)
}
fn text_cyan_bright(&self) -> String {
self.code(96)
}
fn bg_cyan_bright(&self) -> String {
self.code(106)
}
fn text_white_bright(&self) -> String {
self.code(97)
}
fn bg_white_bright(&self) -> String {
self.code(107)
}
fn text_red_50(&self) -> String {
self.codes(38, (254, 242, 242))
}
fn bg_red_50(&self) -> String {
self.codes(48, (254, 242, 242))
}
fn text_red_100(&self) -> String {
self.codes(38, (254, 226, 226))
}
fn bg_red_100(&self) -> String {
self.codes(48, (254, 226, 226))
}
fn text_red_200(&self) -> String {
self.codes(38, (254, 202, 202))
}
fn bg_red_200(&self) -> String {
self.codes(48, (254, 202, 202))
}
fn text_red_300(&self) -> String {
self.codes(38, (252, 165, 165))
}
fn bg_red_300(&self) -> String {
self.codes(48, (252, 165, 165))
}
fn text_red_400(&self) -> String {
self.codes(38, (248, 113, 113))
}
fn bg_red_400(&self) -> String {
self.codes(48, (248, 113, 113))
}
fn text_red_500(&self) -> String {
self.codes(38, (239, 68, 68))
}
fn bg_red_500(&self) -> String {
self.codes(48, (239, 68, 68))
}
fn text_red_600(&self) -> String {
self.codes(38, (220, 38, 38))
}
fn bg_red_600(&self) -> String {
self.codes(48, (220, 38, 38))
}
fn text_red_700(&self) -> String {
self.codes(38, (185, 28, 28))
}
fn bg_red_700(&self) -> String {
self.codes(48, (185, 28, 28))
}
fn text_red_800(&self) -> String {
self.codes(38, (153, 27, 27))
}
fn bg_red_800(&self) -> String {
self.codes(48, (153, 27, 27))
}
fn text_red_900(&self) -> String {
self.codes(38, (127, 29, 29))
}
fn bg_red_900(&self) -> String {
self.codes(48, (127, 29, 29))
}
fn text_red_950(&self) -> String {
self.codes(38, (69, 10, 10))
}
fn bg_red_950(&self) -> String {
self.codes(48, (69, 10, 10))
}
fn text_yellow_50(&self) -> String {
self.codes(38, (254, 252, 232))
}
fn bg_yellow_50(&self) -> String {
self.codes(48, (254, 252, 232))
}
fn text_yellow_100(&self) -> String {
self.codes(38, (254, 249, 195))
}
fn bg_yellow_100(&self) -> String {
self.codes(48, (254, 249, 195))
}
fn text_yellow_200(&self) -> String {
self.codes(38, (254, 240, 138))
}
fn bg_yellow_200(&self) -> String {
self.codes(48, (254, 240, 138))
}
fn text_yellow_300(&self) -> String {
self.codes(38, (253, 224, 71))
}
fn bg_yellow_300(&self) -> String {
self.codes(48, (253, 224, 71))
}
fn text_yellow_400(&self) -> String {
self.codes(38, (250, 204, 21))
}
fn bg_yellow_400(&self) -> String {
self.codes(48, (250, 204, 21))
}
fn text_yellow_500(&self) -> String {
self.codes(38, (234, 179, 8))
}
fn bg_yellow_500(&self) -> String {
self.codes(48, (234, 179, 8))
}
fn text_yellow_600(&self) -> String {
self.codes(38, (202, 138, 4))
}
fn bg_yellow_600(&self) -> String {
self.codes(48, (202, 138, 4))
}
fn text_yellow_700(&self) -> String {
self.codes(38, (161, 98, 7))
}
fn bg_yellow_700(&self) -> String {
self.codes(48, (161, 98, 7))
}
fn text_yellow_800(&self) -> String {
self.codes(38, (133, 77, 14))
}
fn bg_yellow_800(&self) -> String {
self.codes(48, (133, 77, 14))
}
fn text_yellow_900(&self) -> String {
self.codes(38, (113, 63, 18))
}
fn bg_yellow_900(&self) -> String {
self.codes(48, (113, 63, 18))
}
fn text_yellow_950(&self) -> String {
self.codes(38, (66, 32, 6))
}
fn bg_yellow_950(&self) -> String {
self.codes(48, (66, 32, 6))
}
fn text_green_50(&self) -> String {
self.codes(38, (240, 253, 244))
}
fn bg_green_50(&self) -> String {
self.codes(48, (240, 253, 244))
}
fn text_green_100(&self) -> String {
self.codes(38, (220, 252, 231))
}
fn bg_green_100(&self) -> String {
self.codes(48, (220, 252, 231))
}
fn text_green_200(&self) -> String {
self.codes(38, (187, 247, 208))
}
fn bg_green_200(&self) -> String {
self.codes(48, (187, 247, 208))
}
fn text_green_300(&self) -> String {
self.codes(38, (134, 239, 172))
}
fn bg_green_300(&self) -> String {
self.codes(48, (134, 239, 172))
}
fn text_green_400(&self) -> String {
self.codes(38, (74, 222, 128))
}
fn bg_green_400(&self) -> String {
self.codes(48, (74, 222, 128))
}
fn text_green_500(&self) -> String {
self.codes(38, (34, 197, 94))
}
fn bg_green_500(&self) -> String {
self.codes(48, (34, 197, 94))
}
fn text_green_600(&self) -> String {
self.codes(38, (22, 163, 74))
}
fn bg_green_600(&self) -> String {
self.codes(48, (22, 163, 74))
}
fn text_green_700(&self) -> String {
self.codes(38, (21, 128, 61))
}
fn bg_green_700(&self) -> String {
self.codes(48, (21, 128, 61))
}
fn text_green_800(&self) -> String {
self.codes(38, (22, 101, 52))
}
fn bg_green_800(&self) -> String {
self.codes(48, (22, 101, 52))
}
fn text_green_900(&self) -> String {
self.codes(38, (20, 83, 45))
}
fn bg_green_900(&self) -> String {
self.codes(48, (20, 83, 45))
}
fn text_green_950(&self) -> String {
self.codes(38, (5, 46, 22))
}
fn bg_green_950(&self) -> String {
self.codes(48, (5, 46, 22))
}
fn text_blue_50(&self) -> String {
self.codes(38, (239, 246, 255))
}
fn bg_blue_50(&self) -> String {
self.codes(48, (239, 246, 255))
}
fn text_blue_100(&self) -> String {
self.codes(38, (219, 234, 254))
}
fn bg_blue_100(&self) -> String {
self.codes(48, (219, 234, 254))
}
fn text_blue_200(&self) -> String {
self.codes(38, (191, 219, 254))
}
fn bg_blue_200(&self) -> String {
self.codes(48, (191, 219, 254))
}
fn text_blue_300(&self) -> String {
self.codes(38, (147, 197, 253))
}
fn bg_blue_300(&self) -> String {
self.codes(48, (147, 197, 253))
}
fn text_blue_400(&self) -> String {
self.codes(38, (96, 165, 250))
}
fn bg_blue_400(&self) -> String {
self.codes(48, (96, 165, 250))
}
fn text_blue_500(&self) -> String {
self.codes(38, (59, 130, 246))
}
fn bg_blue_500(&self) -> String {
self.codes(48, (59, 130, 246))
}
fn text_blue_600(&self) -> String {
self.codes(38, (37, 99, 235))
}
fn bg_blue_600(&self) -> String {
self.codes(48, (37, 99, 235))
}
fn text_blue_700(&self) -> String {
self.codes(38, (29, 78, 216))
}
fn bg_blue_700(&self) -> String {
self.codes(48, (29, 78, 216))
}
fn text_blue_800(&self) -> String {
self.codes(38, (30, 64, 175))
}
fn bg_blue_800(&self) -> String {
self.codes(48, (30, 64, 175))
}
fn text_blue_900(&self) -> String {
self.codes(38, (30, 58, 138))
}
fn bg_blue_900(&self) -> String {
self.codes(48, (30, 58, 138))
}
fn text_blue_950(&self) -> String {
self.codes(38, (23, 37, 84))
}
fn bg_blue_950(&self) -> String {
self.codes(48, (23, 37, 84))
}
fn text_purple_50(&self) -> String {
self.codes(38, (250, 245, 255))
}
fn bg_purple_50(&self) -> String {
self.codes(48, (250, 245, 255))
}
fn text_purple_100(&self) -> String {
self.codes(38, (243, 232, 255))
}
fn bg_purple_100(&self) -> String {
self.codes(48, (243, 232, 255))
}
fn text_purple_200(&self) -> String {
self.codes(38, (233, 213, 255))
}
fn bg_purple_200(&self) -> String {
self.codes(48, (233, 213, 255))
}
fn text_purple_300(&self) -> String {
self.codes(38, (216, 180, 254))
}
fn bg_purple_300(&self) -> String {
self.codes(48, (216, 180, 254))
}
fn text_purple_400(&self) -> String {
self.codes(38, (192, 132, 252))
}
fn bg_purple_400(&self) -> String {
self.codes(48, (192, 132, 252))
}
fn text_purple_500(&self) -> String {
self.codes(38, (168, 85, 247))
}
fn bg_purple_500(&self) -> String {
self.codes(48, (168, 85, 247))
}
fn text_purple_600(&self) -> String {
self.codes(38, (147, 51, 234))
}
fn bg_purple_600(&self) -> String {
self.codes(48, (147, 51, 234))
}
fn text_purple_700(&self) -> String {
self.codes(38, (126, 34, 206))
}
fn bg_purple_700(&self) -> String {
self.codes(48, (126, 34, 206))
}
fn text_purple_800(&self) -> String {
self.codes(38, (107, 33, 168))
}
fn bg_purple_800(&self) -> String {
self.codes(48, (107, 33, 168))
}
fn text_purple_900(&self) -> String {
self.codes(38, (88, 28, 135))
}
fn bg_purple_900(&self) -> String {
self.codes(48, (88, 28, 135))
}
fn text_purple_950(&self) -> String {
self.codes(38, (59, 7, 100))
}
fn bg_purple_950(&self) -> String {
self.codes(48, (59, 7, 100))
}
fn text_pink_50(&self) -> String {
self.codes(38, (253, 242, 248))
}
fn bg_pink_50(&self) -> String {
self.codes(48, (253, 242, 248))
}
fn text_pink_100(&self) -> String {
self.codes(38, (252, 231, 243))
}
fn bg_pink_100(&self) -> String {
self.codes(48, (252, 231, 243))
}
fn text_pink_200(&self) -> String {
self.codes(38, (251, 207, 232))
}
fn bg_pink_200(&self) -> String {
self.codes(48, (251, 207, 232))
}
fn text_pink_300(&self) -> String {
self.codes(38, (249, 168, 212))
}
fn bg_pink_300(&self) -> String {
self.codes(48, (249, 168, 212))
}
fn text_pink_400(&self) -> String {
self.codes(38, (244, 114, 182))
}
fn bg_pink_400(&self) -> String {
self.codes(48, (244, 114, 182))
}
fn text_pink_500(&self) -> String {
self.codes(38, (236, 72, 153))
}
fn bg_pink_500(&self) -> String {
self.codes(48, (236, 72, 153))
}
fn text_pink_600(&self) -> String {
self.codes(38, (219, 39, 119))
}
fn bg_pink_600(&self) -> String {
self.codes(48, (219, 39, 119))
}
fn text_pink_700(&self) -> String {
self.codes(38, (190, 24, 93))
}
fn bg_pink_700(&self) -> String {
self.codes(48, (190, 24, 93))
}
fn text_pink_800(&self) -> String {
self.codes(38, (157, 23, 77))
}
fn bg_pink_800(&self) -> String {
self.codes(48, (157, 23, 77))
}
fn text_pink_900(&self) -> String {
self.codes(38, (131, 24, 67))
}
fn bg_pink_900(&self) -> String {
self.codes(48, (131, 24, 67))
}
fn text_pink_950(&self) -> String {
self.codes(38, (80, 7, 36))
}
fn bg_pink_950(&self) -> String {
self.codes(48, (80, 7, 36))
}
fn text_black_50(&self) -> String {
self.codes(38, (249, 250, 251))
}
fn bg_black_50(&self) -> String {
self.codes(48, (249, 250, 251))
}
fn text_black_100(&self) -> String {
self.codes(38, (243, 244, 246))
}
fn bg_black_100(&self) -> String {
self.codes(48, (243, 244, 246))
}
fn text_black_200(&self) -> String {
self.codes(38, (229, 231, 235))
}
fn bg_black_200(&self) -> String {
self.codes(48, (229, 231, 235))
}
fn text_black_300(&self) -> String {
self.codes(38, (209, 213, 219))
}
fn bg_black_300(&self) -> String {
self.codes(48, (209, 213, 219))
}
fn text_black_400(&self) -> String {
self.codes(38, (156, 163, 175))
}
fn bg_black_400(&self) -> String {
self.codes(48, (156, 163, 175))
}
fn text_black_500(&self) -> String {
self.codes(38, (107, 114, 128))
}
fn bg_black_500(&self) -> String {
self.codes(48, (107, 114, 128))
}
fn text_black_600(&self) -> String {
self.codes(38, (75, 85, 99))
}
fn bg_black_600(&self) -> String {
self.codes(48, (75, 85, 99))
}
fn text_black_700(&self) -> String {
self.codes(38, (55, 65, 81))
}
fn bg_black_700(&self) -> String {
self.codes(48, (55, 65, 81))
}
fn text_black_800(&self) -> String {
self.codes(38, (31, 41, 55))
}
fn bg_black_800(&self) -> String {
self.codes(48, (31, 41, 55))
}
fn text_black_900(&self) -> String {
self.codes(38, (17, 24, 39))
}
fn bg_black_900(&self) -> String {
self.codes(48, (17, 24, 39))
}
fn text_black_950(&self) -> String {
self.codes(38, (3, 7, 18))
}
fn bg_black_950(&self) -> String {
self.codes(48, (3, 7, 18))
}
fn text_gradient(&self, steps: &[&'static str]) -> String {
if steps.is_empty() {
return self.to_string();
}
let text = self.to_string();
if text.is_empty() {
return text;
}
let mut result = String::new();
let char_count = text.chars().count();
let mut colors: Vec<RGB> = Vec::new();
for step in steps {
match identify_color_type(step) {
ColorType::Hex => {
if let Some(rgb) = hex_to_rgb(step) {
colors.push(rgb);
}
}
ColorType::RGB => {
if let Some(rgb) = parse_rgb(step) {
colors.push(rgb);
}
}
_ => {}
}
}
if colors.len() < 2 {
return text;
}
for (i, c) in text.chars().enumerate() {
let position = i as f32 / (char_count - 1) as f32;
let segment = position * (colors.len() - 1) as f32;
let index = segment.floor() as usize;
let next_index = (index + 1).min(colors.len() - 1);
let blend = segment.fract();
let current_color = &colors[index];
let next_color = &colors[next_index];
let r = lerp(current_color.r as f32, next_color.r as f32, blend) as u8;
let g = lerp(current_color.g as f32, next_color.g as f32, blend) as u8;
let b = lerp(current_color.b as f32, next_color.b as f32, blend) as u8;
result.push_str(&format!("\x1B[38;2;{};{};{}m{}", r, g, b, c));
}
result.push_str("\x1B[0m");
result
}
fn bg_gradient(&self, steps: &[&'static str]) -> String {
if steps.is_empty() {
return self.to_string();
}
let text = self.to_string();
if text.is_empty() {
return text;
}
let mut result = String::new();
let char_count = text.chars().count();
let mut colors: Vec<RGB> = Vec::new();
for step in steps {
match identify_color_type(step) {
ColorType::Hex => {
if let Some(rgb) = hex_to_rgb(step) {
colors.push(rgb);
}
}
ColorType::RGB => {
if let Some(rgb) = parse_rgb(step) {
colors.push(rgb);
}
}
_ => {}
}
}
if colors.len() < 2 {
return text;
}
for (i, c) in text.chars().enumerate() {
let position = i as f32 / (char_count - 1) as f32;
let segment = position * (colors.len() - 1) as f32;
let index = segment.floor() as usize;
let next_index = (index + 1).min(colors.len() - 1);
let blend = segment.fract();
let current_color = &colors[index];
let next_color = &colors[next_index];
let r = lerp(current_color.r as f32, next_color.r as f32, blend) as u8;
let g = lerp(current_color.g as f32, next_color.g as f32, blend) as u8;
let b = lerp(current_color.b as f32, next_color.b as f32, blend) as u8;
result.push_str(&format!("\x1B[48;2;{};{};{}m{}", r, g, b, c));
}
result.push_str("\x1B[0m");
result
}
}
fn lerp(start: f32, end: f32, t: f32) -> f32 {
start + (end - start) * t
}