Skip to content

Commit

Permalink
feat(tui): add support for more named colors (#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Mar 2, 2024
1 parent 49ab51e commit 854fa7f
Show file tree
Hide file tree
Showing 3 changed files with 391 additions and 3 deletions.
257 changes: 257 additions & 0 deletions src/config/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
}

Expand All @@ -351,6 +480,7 @@ impl TryFrom<String> for TuiColor {
impl TryFrom<&str> for TuiColor {
type Error = anyhow::Error;

#[allow(clippy::too_many_lines)]
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.to_ascii_lowercase().replace('-', "").as_ref() {
"black" => Ok(Self::Black),
Expand All @@ -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)?;
Expand Down
Loading

0 comments on commit 854fa7f

Please sign in to comment.