From f9e758f2de0e55c488b768bb3fbda5f3151cffa5 Mon Sep 17 00:00:00 2001 From: FujiApple Date: Tue, 13 Feb 2024 22:50:40 +0800 Subject: [PATCH] feat(tui): add support for more named colors (#1011) --- src/config/theme.rs | 257 ++++++++++++++++++++++++++++++++++++++++++ src/frontend/theme.rs | 128 +++++++++++++++++++++ 2 files changed, 385 insertions(+) diff --git a/src/config/theme.rs b/src/config/theme.rs index 5e818bc54..02b97a869 100644 --- a/src/config/theme.rs +++ b/src/config/theme.rs @@ -321,6 +321,7 @@ pub enum TuiThemeItem { #[derive(Debug, Clone, Copy, Eq, PartialEq, Deserialize)] #[serde(try_from = "String")] pub enum TuiColor { + // ANSI colors Black, Red, Green, @@ -337,6 +338,134 @@ pub enum TuiColor { LightMagenta, LightCyan, White, + // Other colors + AliceBlue, + AntiqueWhite, + Aqua, + Aquamarine, + Azure, + Beige, + Bisque, + BlanchedAlmond, + BlueViolet, + Brown, + BurlyWood, + CadetBlue, + Chartreuse, + Chocolate, + Coral, + CornflowerBlue, + CornSilk, + Crimson, + DarkBlue, + DarkCyan, + DarkGoldenrod, + DarkGreen, + DarkKhaki, + DarkMagenta, + DarkOliveGreen, + DarkOrange, + DarkOrchid, + DarkRed, + DarkSalmon, + DarkSeaGreen, + DarkSlateBlue, + DarkSlateGray, + DarkTurquoise, + DarkViolet, + DeepPink, + DeepSkyBlue, + DimGray, + DodgerBlue, + Firebrick, + FloralWhite, + ForestGreen, + Fuchsia, + Gainsboro, + GhostWhite, + Gold, + Goldenrod, + GreenYellow, + Honeydew, + HotPink, + IndianRed, + Indigo, + Ivory, + Khaki, + Lavender, + LavenderBlush, + LawnGreen, + LemonChiffon, + LightCoral, + LightGoldenrodYellow, + LightGray, + LightPink, + LightSalmon, + LightSeaGreen, + LightSkyBlue, + LightSlateGray, + LightSteelBlue, + Lime, + LimeGreen, + Linen, + Maroon, + MediumAquamarine, + MediumBlue, + MediumOrchid, + MediumPurple, + MediumSeaGreen, + MediumSlateBlue, + MediumSpringGreen, + MediumTurquoise, + MediumVioletRed, + MidnightBlue, + MintCream, + MistyRose, + Moccasin, + NavajoWhite, + Navy, + OldLace, + Olive, + OliveDrab, + Orange, + OrangeRed, + Orchid, + PaleGoldenrod, + PaleGreen, + PaleTurquoise, + PaleVioletRed, + PapayaWhip, + PeachPuff, + Peru, + Pink, + Plum, + PowderBlue, + Purple, + RebeccaPurple, + RosyBrown, + RoyalBlue, + SaddleBrown, + Salmon, + SandyBrown, + SeaGreen, + SeaShell, + Sienna, + Silver, + SkyBlue, + SlateBlue, + SlateGray, + Snow, + SpringGreen, + SteelBlue, + Tan, + Teal, + Thistle, + Tomato, + Turquoise, + Violet, + Wheat, + WhiteSmoke, + YellowGreen, Rgb(u8, u8, u8), } @@ -351,6 +480,7 @@ impl TryFrom for TuiColor { impl TryFrom<&str> for TuiColor { type Error = anyhow::Error; + #[allow(clippy::too_many_lines)] fn try_from(value: &str) -> Result { match value.to_ascii_lowercase().replace('-', "").as_ref() { "black" => Ok(Self::Black), @@ -369,6 +499,133 @@ impl TryFrom<&str> for TuiColor { "lightmagenta" => Ok(Self::LightMagenta), "lightcyan" => Ok(Self::LightCyan), "white" => Ok(Self::White), + "aliceblue" => Ok(Self::AliceBlue), + "antiquewhite" => Ok(Self::AntiqueWhite), + "aqua" => Ok(Self::Aqua), + "aquamarine" => Ok(Self::Aquamarine), + "azure" => Ok(Self::Azure), + "beige" => Ok(Self::Beige), + "bisque" => Ok(Self::Bisque), + "blanchedalmond" => Ok(Self::BlanchedAlmond), + "blueviolet" => Ok(Self::BlueViolet), + "brown" => Ok(Self::Brown), + "burlywood" => Ok(Self::BurlyWood), + "cadetblue" => Ok(Self::CadetBlue), + "chartreuse" => Ok(Self::Chartreuse), + "chocolate" => Ok(Self::Chocolate), + "coral" => Ok(Self::Coral), + "cornflowerblue" => Ok(Self::CornflowerBlue), + "cornsilk" => Ok(Self::CornSilk), + "crimson" => Ok(Self::Crimson), + "darkblue" => Ok(Self::DarkBlue), + "darkcyan" => Ok(Self::DarkCyan), + "darkgoldenrod" => Ok(Self::DarkGoldenrod), + "darkgreen" => Ok(Self::DarkGreen), + "darkkhaki" => Ok(Self::DarkKhaki), + "darkmagenta" => Ok(Self::DarkMagenta), + "darkolivegreen" => Ok(Self::DarkOliveGreen), + "darkorange" => Ok(Self::DarkOrange), + "darkorchid" => Ok(Self::DarkOrchid), + "darkred" => Ok(Self::DarkRed), + "darksalmon" => Ok(Self::DarkSalmon), + "darkseagreen" => Ok(Self::DarkSeaGreen), + "darkslateblue" => Ok(Self::DarkSlateBlue), + "darkslategray" | "darkslategrey" => Ok(Self::DarkSlateGray), + "darkturquoise" => Ok(Self::DarkTurquoise), + "darkviolet" => Ok(Self::DarkViolet), + "deeppink" => Ok(Self::DeepPink), + "deepskyblue" => Ok(Self::DeepSkyBlue), + "dimgray" | "dimgrey" => Ok(Self::DimGray), + "dodgerblue" => Ok(Self::DodgerBlue), + "firebrick" => Ok(Self::Firebrick), + "floralwhite" => Ok(Self::FloralWhite), + "forestgreen" => Ok(Self::ForestGreen), + "fuchsia" => Ok(Self::Fuchsia), + "gainsboro" => Ok(Self::Gainsboro), + "ghostwhite" => Ok(Self::GhostWhite), + "gold" => Ok(Self::Gold), + "goldenrod" => Ok(Self::Goldenrod), + "greenyellow" => Ok(Self::GreenYellow), + "honeydew" => Ok(Self::Honeydew), + "hotpink" => Ok(Self::HotPink), + "indianred" => Ok(Self::IndianRed), + "indigo" => Ok(Self::Indigo), + "ivory" => Ok(Self::Ivory), + "khaki" => Ok(Self::Khaki), + "lavender" => Ok(Self::Lavender), + "lavenderblush" => Ok(Self::LavenderBlush), + "lawngreen" => Ok(Self::LawnGreen), + "lemonchiffon" => Ok(Self::LemonChiffon), + "lightcoral" => Ok(Self::LightCoral), + "lightgoldenrodyellow" => Ok(Self::LightGoldenrodYellow), + "lightgray" | "lightgrey" => Ok(Self::LightGray), + "lightpink" => Ok(Self::LightPink), + "lightsalmon" => Ok(Self::LightSalmon), + "lightseagreen" => Ok(Self::LightSeaGreen), + "lightskyblue" => Ok(Self::LightSkyBlue), + "lightslategray" | "lightslategrey" => Ok(Self::LightSlateGray), + "lightsteelblue" => Ok(Self::LightSteelBlue), + "lime" => Ok(Self::Lime), + "limegreen" => Ok(Self::LimeGreen), + "linen" => Ok(Self::Linen), + "maroon" => Ok(Self::Maroon), + "mediumaquamarine" => Ok(Self::MediumAquamarine), + "mediumblue" => Ok(Self::MediumBlue), + "mediumorchid" => Ok(Self::MediumOrchid), + "mediumpurple" => Ok(Self::MediumPurple), + "mediumseagreen" => Ok(Self::MediumSeaGreen), + "mediumslateblue" => Ok(Self::MediumSlateBlue), + "mediumspringgreen" => Ok(Self::MediumSpringGreen), + "mediumturquoise" => Ok(Self::MediumTurquoise), + "mediumvioletred" => Ok(Self::MediumVioletRed), + "midnightblue" => Ok(Self::MidnightBlue), + "mintcream" => Ok(Self::MintCream), + "mistyrose" => Ok(Self::MistyRose), + "moccasin" => Ok(Self::Moccasin), + "navajowhite" => Ok(Self::NavajoWhite), + "navy" => Ok(Self::Navy), + "oldlace" => Ok(Self::OldLace), + "olive" => Ok(Self::Olive), + "olivedrab" => Ok(Self::OliveDrab), + "orange" => Ok(Self::Orange), + "orangered" => Ok(Self::OrangeRed), + "orchid" => Ok(Self::Orchid), + "palegoldenrod" => Ok(Self::PaleGoldenrod), + "palegreen" => Ok(Self::PaleGreen), + "paleturquoise" => Ok(Self::PaleTurquoise), + "palevioletred" => Ok(Self::PaleVioletRed), + "papayawhip" => Ok(Self::PapayaWhip), + "peachpuff" => Ok(Self::PeachPuff), + "peru" => Ok(Self::Peru), + "pink" => Ok(Self::Pink), + "plum" => Ok(Self::Plum), + "powderblue" => Ok(Self::PowderBlue), + "purple" => Ok(Self::Purple), + "rebeccapurple" => Ok(Self::RebeccaPurple), + "rosybrown" => Ok(Self::RosyBrown), + "royalblue" => Ok(Self::RoyalBlue), + "saddlebrown" => Ok(Self::SaddleBrown), + "salmon" => Ok(Self::Salmon), + "sandybrown" => Ok(Self::SandyBrown), + "seagreen" => Ok(Self::SeaGreen), + "seashell" => Ok(Self::SeaShell), + "sienna" => Ok(Self::Sienna), + "silver" => Ok(Self::Silver), + "skyblue" => Ok(Self::SkyBlue), + "slateblue" => Ok(Self::SlateBlue), + "slategray" | "slategrey" => Ok(Self::SlateGray), + "snow" => Ok(Self::Snow), + "springgreen" => Ok(Self::SpringGreen), + "steelblue" => Ok(Self::SteelBlue), + "tan" => Ok(Self::Tan), + "teal" => Ok(Self::Teal), + "thistle" => Ok(Self::Thistle), + "tomato" => Ok(Self::Tomato), + "turquoise" => Ok(Self::Turquoise), + "violet" => Ok(Self::Violet), + "wheat" => Ok(Self::Wheat), + "whitesmoke" => Ok(Self::WhiteSmoke), + "yellowgreen" => Ok(Self::YellowGreen), rgb_hex if value.len() == 6 && value.chars().all(|c| c.is_ascii_hexdigit()) => { let red = u8::from_str_radix(&rgb_hex[0..2], 16)?; let green = u8::from_str_radix(&rgb_hex[2..4], 16)?; diff --git a/src/frontend/theme.rs b/src/frontend/theme.rs index de880e053..028b39c9d 100644 --- a/src/frontend/theme.rs +++ b/src/frontend/theme.rs @@ -117,6 +117,7 @@ impl From for Theme { } impl From for Color { + #[allow(clippy::too_many_lines)] fn from(value: TuiColor) -> Self { match value { TuiColor::Black => Self::Black, @@ -135,6 +136,133 @@ impl From for Color { TuiColor::LightMagenta => Self::LightMagenta, TuiColor::LightCyan => Self::LightCyan, TuiColor::White => Self::White, + TuiColor::AliceBlue => Self::from_u32(0x00f0_f8ff), + TuiColor::AntiqueWhite => Self::from_u32(0x00fa_ebd7), + TuiColor::Aqua => Self::from_u32(0x0000_ffff), + TuiColor::Aquamarine => Self::from_u32(0x007f_ffd4), + TuiColor::Azure => Self::from_u32(0x00f0_ffff), + TuiColor::Beige => Self::from_u32(0x00f5_f5dc), + TuiColor::Bisque => Self::from_u32(0x00ff_e4c4), + TuiColor::BlanchedAlmond => Self::from_u32(0x00ff_ebcd), + TuiColor::BlueViolet => Self::from_u32(0x008a_2be2), + TuiColor::Brown => Self::from_u32(0x00a5_2a2a), + TuiColor::BurlyWood => Self::from_u32(0x00de_b887), + TuiColor::CadetBlue => Self::from_u32(0x005f_9ea0), + TuiColor::Chartreuse => Self::from_u32(0x007f_ff00), + TuiColor::Chocolate => Self::from_u32(0x00d2_691e), + TuiColor::Coral => Self::from_u32(0x00ff_7f50), + TuiColor::CornflowerBlue => Self::from_u32(0x0064_95ed), + TuiColor::CornSilk => Self::from_u32(0x00ff_f8dc), + TuiColor::Crimson => Self::from_u32(0x00dc_143c), + TuiColor::DarkBlue => Self::from_u32(0x0000_008b), + TuiColor::DarkCyan => Self::from_u32(0x0000_8b8b), + TuiColor::DarkGoldenrod => Self::from_u32(0x00b8_860b), + TuiColor::DarkGreen => Self::from_u32(0x0000_6400), + TuiColor::DarkKhaki => Self::from_u32(0x00bd_b76b), + TuiColor::DarkMagenta => Self::from_u32(0x008b_008b), + TuiColor::DarkOliveGreen => Self::from_u32(0x0055_6b2f), + TuiColor::DarkOrange => Self::from_u32(0x00ff_8c00), + TuiColor::DarkOrchid => Self::from_u32(0x0099_32cc), + TuiColor::DarkRed => Self::from_u32(0x008b_0000), + TuiColor::DarkSalmon => Self::from_u32(0x00e9_967a), + TuiColor::DarkSeaGreen => Self::from_u32(0x008f_bc8f), + TuiColor::DarkSlateBlue => Self::from_u32(0x0048_3d8b), + TuiColor::DarkSlateGray => Self::from_u32(0x002f_4f4f), + TuiColor::DarkTurquoise => Self::from_u32(0x0000_ced1), + TuiColor::DarkViolet => Self::from_u32(0x0094_00d3), + TuiColor::DeepPink => Self::from_u32(0x00ff_1493), + TuiColor::DeepSkyBlue => Self::from_u32(0x0000_bfff), + TuiColor::DimGray => Self::from_u32(0x0069_6969), + TuiColor::DodgerBlue => Self::from_u32(0x001e_90ff), + TuiColor::Firebrick => Self::from_u32(0x00b2_2222), + TuiColor::FloralWhite => Self::from_u32(0x00ff_faf0), + TuiColor::ForestGreen => Self::from_u32(0x0022_8b22), + TuiColor::Fuchsia => Self::from_u32(0x00ff_00ff), + TuiColor::Gainsboro => Self::from_u32(0x00dc_dcdc), + TuiColor::GhostWhite => Self::from_u32(0x00f8_f8ff), + TuiColor::Gold => Self::from_u32(0x00ff_d700), + TuiColor::Goldenrod => Self::from_u32(0x00da_a520), + TuiColor::GreenYellow => Self::from_u32(0x00ad_ff2f), + TuiColor::Honeydew => Self::from_u32(0x00f0_fff0), + TuiColor::HotPink => Self::from_u32(0x00ff_69b4), + TuiColor::IndianRed => Self::from_u32(0x00cd_5c5c), + TuiColor::Indigo => Self::from_u32(0x004b_0082), + TuiColor::Ivory => Self::from_u32(0x00ff_fff0), + TuiColor::Khaki => Self::from_u32(0x00f0_e68c), + TuiColor::Lavender => Self::from_u32(0x00e6_e6fa), + TuiColor::LavenderBlush => Self::from_u32(0x00ff_f0f5), + TuiColor::LawnGreen => Self::from_u32(0x007c_fc00), + TuiColor::LemonChiffon => Self::from_u32(0x00ff_facd), + TuiColor::LightCoral => Self::from_u32(0x00f0_8080), + TuiColor::LightGoldenrodYellow => Self::from_u32(0x00fa_fad2), + TuiColor::LightGray => Self::from_u32(0x00d3_d3d3), + TuiColor::LightPink => Self::from_u32(0x00ff_b6c1), + TuiColor::LightSalmon => Self::from_u32(0x00ff_a07a), + TuiColor::LightSeaGreen => Self::from_u32(0x0020_b2aa), + TuiColor::LightSkyBlue => Self::from_u32(0x0087_cefa), + TuiColor::LightSlateGray => Self::from_u32(0x0077_8899), + TuiColor::LightSteelBlue => Self::from_u32(0x00b0_c4de), + TuiColor::Lime => Self::from_u32(0x0000_ff00), + TuiColor::LimeGreen => Self::from_u32(0x0032_cd32), + TuiColor::Linen => Self::from_u32(0x00fa_f0e6), + TuiColor::Maroon => Self::from_u32(0x0080_0000), + TuiColor::MediumAquamarine => Self::from_u32(0x0066_cdaa), + TuiColor::MediumBlue => Self::from_u32(0x0000_00cd), + TuiColor::MediumOrchid => Self::from_u32(0x00ba_55d3), + TuiColor::MediumPurple => Self::from_u32(0x0093_70db), + TuiColor::MediumSeaGreen => Self::from_u32(0x003c_b371), + TuiColor::MediumSlateBlue => Self::from_u32(0x007b_68ee), + TuiColor::MediumSpringGreen => Self::from_u32(0x0000_fa9a), + TuiColor::MediumTurquoise => Self::from_u32(0x0048_d1cc), + TuiColor::MediumVioletRed => Self::from_u32(0x00c7_1585), + TuiColor::MidnightBlue => Self::from_u32(0x0019_1970), + TuiColor::MintCream => Self::from_u32(0x00f5_fffa), + TuiColor::MistyRose => Self::from_u32(0x00ff_e4e1), + TuiColor::Moccasin => Self::from_u32(0x00ff_e4b5), + TuiColor::NavajoWhite => Self::from_u32(0x00ff_dead), + TuiColor::Navy => Self::from_u32(0x0000_0080), + TuiColor::OldLace => Self::from_u32(0x00fd_f5e6), + TuiColor::Olive => Self::from_u32(0x0080_8000), + TuiColor::OliveDrab => Self::from_u32(0x006b_8e23), + TuiColor::Orange => Self::from_u32(0x00ff_a500), + TuiColor::OrangeRed => Self::from_u32(0x00ff_4500), + TuiColor::Orchid => Self::from_u32(0x00da_70d6), + TuiColor::PaleGoldenrod => Self::from_u32(0x00ee_e8aa), + TuiColor::PaleGreen => Self::from_u32(0x0098_fb98), + TuiColor::PaleTurquoise => Self::from_u32(0x00af_eeee), + TuiColor::PaleVioletRed => Self::from_u32(0x00db_7093), + TuiColor::PapayaWhip => Self::from_u32(0x00ff_efd5), + TuiColor::PeachPuff => Self::from_u32(0x00ff_dab9), + TuiColor::Peru => Self::from_u32(0x00cd_853f), + TuiColor::Pink => Self::from_u32(0x00ff_c0cb), + TuiColor::Plum => Self::from_u32(0x00dd_a0dd), + TuiColor::PowderBlue => Self::from_u32(0x00b0_e0e6), + TuiColor::Purple => Self::from_u32(0x0080_0080), + TuiColor::RebeccaPurple => Self::from_u32(0x0066_3399), + TuiColor::RosyBrown => Self::from_u32(0x00bc_8f8f), + TuiColor::RoyalBlue => Self::from_u32(0x0041_69e1), + TuiColor::SaddleBrown => Self::from_u32(0x008b_4513), + TuiColor::Salmon => Self::from_u32(0x00fa_8072), + TuiColor::SandyBrown => Self::from_u32(0x00f4_a460), + TuiColor::SeaGreen => Self::from_u32(0x002e_8b57), + TuiColor::SeaShell => Self::from_u32(0x00ff_f5ee), + TuiColor::Sienna => Self::from_u32(0x00a0_522d), + TuiColor::Silver => Self::from_u32(0x00c0_c0c0), + TuiColor::SkyBlue => Self::from_u32(0x0087_ceeb), + TuiColor::SlateBlue => Self::from_u32(0x006a_5acd), + TuiColor::SlateGray => Self::from_u32(0x0070_8090), + TuiColor::Snow => Self::from_u32(0x00ff_fafa), + TuiColor::SpringGreen => Self::from_u32(0x0000_ff7f), + TuiColor::SteelBlue => Self::from_u32(0x0046_82b4), + TuiColor::Tan => Self::from_u32(0x00d2_b48c), + TuiColor::Teal => Self::from_u32(0x0000_8080), + TuiColor::Thistle => Self::from_u32(0x00d8_bfd8), + TuiColor::Tomato => Self::from_u32(0x00ff_6347), + TuiColor::Turquoise => Self::from_u32(0x0040_e0d0), + TuiColor::Violet => Self::from_u32(0x00ee_82ee), + TuiColor::Wheat => Self::from_u32(0x00f5_deb3), + TuiColor::WhiteSmoke => Self::from_u32(0x00f5_f5f5), + TuiColor::YellowGreen => Self::from_u32(0x009a_cd32), TuiColor::Rgb(r, g, b) => Self::Rgb(r, g, b), } }