use ratatui::style::{Color, Modifier, Style};
use std::fmt;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
pub(crate) enum ThemeName {
#[default]
GoCyan,
JetBrainsNewIsland,
CursorDark,
Midnight,
TokyoNight,
CatppuccinMocha,
Nord,
Dracula,
GruvboxDark,
RosePine,
Matrix,
Amber,
Mono,
CursorLight,
CatppuccinLatte,
GitHubLight,
SolarizedLight,
RosePineDawn,
Light,
}
impl ThemeName {
pub(crate) const ALL: [ThemeName; 19] = [
ThemeName::GoCyan,
ThemeName::JetBrainsNewIsland,
ThemeName::CursorDark,
ThemeName::Midnight,
ThemeName::TokyoNight,
ThemeName::CatppuccinMocha,
ThemeName::Nord,
ThemeName::Dracula,
ThemeName::GruvboxDark,
ThemeName::RosePine,
ThemeName::Matrix,
ThemeName::Amber,
ThemeName::Mono,
ThemeName::CursorLight,
ThemeName::CatppuccinLatte,
ThemeName::GitHubLight,
ThemeName::SolarizedLight,
ThemeName::RosePineDawn,
ThemeName::Light,
];
#[must_use]
pub(crate) fn key(self) -> &'static str {
match self {
ThemeName::GoCyan => "gocyan",
ThemeName::JetBrainsNewIsland => "newisland",
ThemeName::CursorDark => "cursordark",
ThemeName::Midnight => "midnight",
ThemeName::TokyoNight => "tokyonight",
ThemeName::CatppuccinMocha => "mocha",
ThemeName::Nord => "nord",
ThemeName::Dracula => "dracula",
ThemeName::GruvboxDark => "gruvboxdark",
ThemeName::RosePine => "rosepine",
ThemeName::Matrix => "matrix",
ThemeName::Amber => "amber",
ThemeName::Mono => "mono",
ThemeName::CursorLight => "cursorlight",
ThemeName::CatppuccinLatte => "latte",
ThemeName::GitHubLight => "githublight",
ThemeName::SolarizedLight => "solarizedlight",
ThemeName::RosePineDawn => "rosedawn",
ThemeName::Light => "light",
}
}
#[must_use]
pub(crate) fn title(self) -> &'static str {
match self {
ThemeName::GoCyan => "Go Cyan",
ThemeName::JetBrainsNewIsland => "JetBrains New Island",
ThemeName::CursorDark => "Cursor Dark",
ThemeName::Midnight => "Midnight",
ThemeName::TokyoNight => "Tokyo Night",
ThemeName::CatppuccinMocha => "Catppuccin Mocha",
ThemeName::Nord => "Nord",
ThemeName::Dracula => "Dracula",
ThemeName::GruvboxDark => "Gruvbox Dark",
ThemeName::RosePine => "Rosé Pine",
ThemeName::Matrix => "Matrix Green",
ThemeName::Amber => "Amber Glow",
ThemeName::Mono => "Monochrome",
ThemeName::CursorLight => "Cursor Light",
ThemeName::CatppuccinLatte => "Catppuccin Latte",
ThemeName::GitHubLight => "GitHub Light",
ThemeName::SolarizedLight => "Solarized Light",
ThemeName::RosePineDawn => "Rosé Pine Dawn",
ThemeName::Light => "Light",
}
}
#[must_use]
pub(crate) fn from_key(raw: &str) -> Option<ThemeName> {
let key = raw.trim().to_lowercase();
Self::ALL
.iter()
.copied()
.find(|t| t.key() == key || t.title().to_lowercase() == key)
}
#[must_use]
pub(crate) fn is_light(self) -> bool {
matches!(
self,
ThemeName::CursorLight
| ThemeName::CatppuccinLatte
| ThemeName::GitHubLight
| ThemeName::SolarizedLight
| ThemeName::RosePineDawn
| ThemeName::Light
)
}
#[allow(dead_code)]
pub(crate) fn is_dark(self) -> bool {
!self.is_light()
}
#[must_use]
pub(crate) fn family(self) -> ThemeFamily {
if self.is_light() {
ThemeFamily::Light
} else {
ThemeFamily::Dark
}
}
#[must_use]
pub(crate) fn in_family(family: ThemeFamily) -> Vec<ThemeName> {
Self::ALL
.iter()
.copied()
.filter(|t| t.family() == family)
.collect()
}
#[must_use]
pub(crate) fn index_in_family(self) -> usize {
Self::in_family(self.family())
.iter()
.position(|t| *t == self)
.unwrap_or(0)
}
}
impl fmt::Display for ThemeName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.title())
}
}
impl clap::ValueEnum for ThemeName {
fn value_variants<'a>() -> &'a [Self] {
&Self::ALL
}
fn to_possible_value<'a>(&self) -> Option<clap::builder::PossibleValue> {
let possible_value = clap::builder::PossibleValue::new(self.key());
let possible_value = possible_value.help(self.title());
Some(possible_value)
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(crate) enum ThemeFamily {
Dark,
Light,
}
impl ThemeFamily {
pub(crate) const ALL: [ThemeFamily; 2] = [ThemeFamily::Dark, ThemeFamily::Light];
#[must_use]
pub(crate) fn label(self) -> &'static str {
match self {
ThemeFamily::Dark => "Dark",
ThemeFamily::Light => "Light",
}
}
#[must_use]
pub(crate) fn icon(self) -> &'static str {
match self {
ThemeFamily::Dark => "🌙",
ThemeFamily::Light => "☀️",
}
}
#[must_use]
pub(crate) fn index(self) -> usize {
Self::ALL.iter().position(|f| *f == self).unwrap_or(0)
}
#[must_use]
pub(crate) fn at(i: usize) -> ThemeFamily {
Self::ALL[i.min(Self::ALL.len() - 1)]
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
pub(crate) enum ThemePickerView {
#[default]
Categories,
Family(ThemeFamily),
}
#[derive(Clone, Copy)]
pub(crate) struct Theme {
pub(crate) brand: Color,
pub(crate) brand_dark: Color,
pub(crate) success: Color,
pub(crate) error: Color,
pub(crate) warning: Color,
pub(crate) accent: Color,
pub(crate) grey: Color,
pub(crate) fg: Color,
pub(crate) bg: Color,
pub(crate) dim: Color,
}
impl Theme {
#[must_use]
#[allow(clippy::too_many_lines)]
pub(crate) fn for_name(name: ThemeName) -> Theme {
match name {
ThemeName::GoCyan => Theme {
brand: Color::Rgb(0, 173, 216),
brand_dark: Color::Rgb(6, 84, 106),
success: Color::Rgb(63, 208, 127),
error: Color::Rgb(255, 89, 110),
warning: Color::Rgb(255, 184, 77),
accent: Color::Rgb(167, 139, 250),
grey: Color::Rgb(105, 115, 134),
fg: Color::Rgb(224, 232, 240),
bg: Color::Rgb(18, 22, 30),
dim: Color::Rgb(47, 55, 71),
},
ThemeName::JetBrainsNewIsland => Theme {
brand: Color::Rgb(204, 120, 50),
brand_dark: Color::Rgb(72, 52, 34),
success: Color::Rgb(106, 171, 115),
error: Color::Rgb(224, 85, 97),
warning: Color::Rgb(255, 198, 109),
accent: Color::Rgb(104, 151, 187),
grey: Color::Rgb(128, 134, 139),
fg: Color::Rgb(223, 225, 229),
bg: Color::Rgb(43, 45, 48),
dim: Color::Rgb(62, 65, 70),
},
ThemeName::CursorDark => Theme {
brand: Color::Rgb(97, 175, 239),
brand_dark: Color::Rgb(42, 44, 50),
success: Color::Rgb(152, 195, 121),
error: Color::Rgb(224, 108, 117),
warning: Color::Rgb(229, 192, 123),
accent: Color::Rgb(198, 120, 221),
grey: Color::Rgb(122, 126, 134),
fg: Color::Rgb(220, 222, 228),
bg: Color::Rgb(26, 27, 30),
dim: Color::Rgb(48, 50, 56),
},
ThemeName::Midnight => Theme {
brand: Color::Rgb(129, 140, 248),
brand_dark: Color::Rgb(49, 46, 129),
success: Color::Rgb(52, 211, 153),
error: Color::Rgb(248, 113, 113),
warning: Color::Rgb(250, 204, 21),
accent: Color::Rgb(192, 132, 252),
grey: Color::Rgb(92, 102, 128),
fg: Color::Rgb(203, 213, 225),
bg: Color::Rgb(13, 16, 28),
dim: Color::Rgb(43, 49, 73),
},
ThemeName::TokyoNight => Theme {
brand: Color::Rgb(122, 162, 247),
brand_dark: Color::Rgb(36, 40, 59),
success: Color::Rgb(158, 206, 106),
error: Color::Rgb(247, 118, 142),
warning: Color::Rgb(224, 175, 104),
accent: Color::Rgb(187, 154, 247),
grey: Color::Rgb(86, 95, 137),
fg: Color::Rgb(192, 202, 245),
bg: Color::Rgb(26, 27, 38),
dim: Color::Rgb(41, 46, 66),
},
ThemeName::CatppuccinMocha => Theme {
brand: Color::Rgb(203, 166, 247),
brand_dark: Color::Rgb(49, 50, 68),
success: Color::Rgb(166, 227, 161),
error: Color::Rgb(243, 139, 168),
warning: Color::Rgb(249, 226, 175),
accent: Color::Rgb(245, 194, 231),
grey: Color::Rgb(108, 112, 134),
fg: Color::Rgb(205, 214, 244),
bg: Color::Rgb(30, 30, 46),
dim: Color::Rgb(69, 71, 90),
},
ThemeName::Nord => Theme {
brand: Color::Rgb(136, 192, 208),
brand_dark: Color::Rgb(59, 66, 82),
success: Color::Rgb(163, 190, 140),
error: Color::Rgb(191, 97, 106),
warning: Color::Rgb(235, 203, 139),
accent: Color::Rgb(180, 142, 173),
grey: Color::Rgb(118, 128, 146),
fg: Color::Rgb(216, 222, 233),
bg: Color::Rgb(46, 52, 64),
dim: Color::Rgb(71, 79, 95),
},
ThemeName::Dracula => Theme {
brand: Color::Rgb(189, 147, 249),
brand_dark: Color::Rgb(68, 42, 110),
success: Color::Rgb(80, 250, 123),
error: Color::Rgb(255, 85, 85),
warning: Color::Rgb(241, 250, 140),
accent: Color::Rgb(255, 121, 198),
grey: Color::Rgb(98, 114, 164),
fg: Color::Rgb(248, 248, 242),
bg: Color::Rgb(40, 42, 54),
dim: Color::Rgb(59, 63, 85),
},
ThemeName::GruvboxDark => Theme {
brand: Color::Rgb(254, 128, 25),
brand_dark: Color::Rgb(60, 56, 54),
success: Color::Rgb(184, 187, 38),
error: Color::Rgb(251, 73, 52),
warning: Color::Rgb(250, 189, 47),
accent: Color::Rgb(211, 134, 155),
grey: Color::Rgb(146, 131, 116),
fg: Color::Rgb(235, 219, 178),
bg: Color::Rgb(40, 40, 40),
dim: Color::Rgb(80, 73, 69),
},
ThemeName::RosePine => Theme {
brand: Color::Rgb(196, 167, 231),
brand_dark: Color::Rgb(38, 35, 58),
success: Color::Rgb(156, 207, 216),
error: Color::Rgb(235, 111, 146),
warning: Color::Rgb(246, 193, 119),
accent: Color::Rgb(235, 188, 186),
grey: Color::Rgb(110, 106, 134),
fg: Color::Rgb(224, 222, 244),
bg: Color::Rgb(25, 23, 36),
dim: Color::Rgb(64, 61, 82),
},
ThemeName::Matrix => Theme {
brand: Color::Rgb(0, 220, 120),
brand_dark: Color::Rgb(0, 77, 42),
success: Color::Rgb(0, 230, 118),
error: Color::Rgb(255, 90, 90),
warning: Color::Rgb(220, 255, 0),
accent: Color::Rgb(0, 200, 190),
grey: Color::Rgb(88, 120, 96),
fg: Color::Rgb(190, 255, 205),
bg: Color::Rgb(4, 12, 8),
dim: Color::Rgb(35, 56, 44),
},
ThemeName::Amber => Theme {
brand: Color::Rgb(255, 183, 77),
brand_dark: Color::Rgb(110, 66, 18),
success: Color::Rgb(153, 220, 110),
error: Color::Rgb(235, 100, 80),
warning: Color::Rgb(255, 214, 90),
accent: Color::Rgb(214, 160, 255),
grey: Color::Rgb(140, 122, 96),
fg: Color::Rgb(236, 226, 206),
bg: Color::Rgb(24, 19, 12),
dim: Color::Rgb(66, 55, 40),
},
ThemeName::Mono => Theme {
brand: Color::Rgb(228, 228, 228),
brand_dark: Color::Rgb(70, 70, 70),
success: Color::Rgb(200, 200, 200),
error: Color::Rgb(245, 245, 245),
warning: Color::Rgb(165, 165, 165),
accent: Color::Rgb(150, 150, 150),
grey: Color::Rgb(112, 112, 112),
fg: Color::Rgb(226, 226, 226),
bg: Color::Rgb(20, 20, 20),
dim: Color::Rgb(58, 58, 58),
},
ThemeName::CursorLight => Theme {
brand: Color::Rgb(99, 102, 241),
brand_dark: Color::Rgb(224, 226, 255),
success: Color::Rgb(22, 163, 74),
error: Color::Rgb(220, 38, 38),
warning: Color::Rgb(217, 119, 6),
accent: Color::Rgb(168, 85, 247),
grey: Color::Rgb(115, 115, 130),
fg: Color::Rgb(26, 26, 46),
bg: Color::Rgb(250, 250, 250),
dim: Color::Rgb(213, 213, 226),
},
ThemeName::CatppuccinLatte => Theme {
brand: Color::Rgb(136, 57, 239),
brand_dark: Color::Rgb(204, 208, 218),
success: Color::Rgb(64, 160, 43),
error: Color::Rgb(210, 15, 57),
warning: Color::Rgb(223, 142, 29),
accent: Color::Rgb(234, 118, 203),
grey: Color::Rgb(108, 111, 133),
fg: Color::Rgb(76, 79, 105),
bg: Color::Rgb(239, 241, 245),
dim: Color::Rgb(188, 192, 204),
},
ThemeName::GitHubLight => Theme {
brand: Color::Rgb(9, 105, 218),
brand_dark: Color::Rgb(221, 244, 255),
success: Color::Rgb(26, 127, 55),
error: Color::Rgb(207, 34, 46),
warning: Color::Rgb(154, 103, 0),
accent: Color::Rgb(130, 80, 223),
grey: Color::Rgb(89, 99, 110),
fg: Color::Rgb(31, 35, 40),
bg: Color::Rgb(255, 255, 255),
dim: Color::Rgb(209, 217, 224),
},
ThemeName::SolarizedLight => Theme {
brand: Color::Rgb(38, 139, 210),
brand_dark: Color::Rgb(238, 232, 213),
success: Color::Rgb(133, 153, 0),
error: Color::Rgb(220, 50, 47),
warning: Color::Rgb(181, 137, 0),
accent: Color::Rgb(108, 113, 196),
grey: Color::Rgb(147, 161, 161),
fg: Color::Rgb(101, 123, 131),
bg: Color::Rgb(253, 246, 227),
dim: Color::Rgb(222, 216, 199),
},
ThemeName::RosePineDawn => Theme {
brand: Color::Rgb(144, 122, 169),
brand_dark: Color::Rgb(242, 233, 225),
success: Color::Rgb(86, 148, 159),
error: Color::Rgb(180, 99, 122),
warning: Color::Rgb(234, 157, 52),
accent: Color::Rgb(215, 130, 126),
grey: Color::Rgb(152, 147, 165),
fg: Color::Rgb(87, 82, 121),
bg: Color::Rgb(250, 244, 237),
dim: Color::Rgb(223, 218, 217),
},
ThemeName::Light => Theme {
brand: Color::Rgb(0, 121, 107),
brand_dark: Color::Rgb(178, 223, 219),
success: Color::Rgb(21, 116, 63),
error: Color::Rgb(197, 16, 32),
warning: Color::Rgb(176, 116, 0),
accent: Color::Rgb(119, 62, 160),
grey: Color::Rgb(120, 128, 138),
fg: Color::Rgb(24, 28, 34),
bg: Color::Rgb(250, 250, 248),
dim: Color::Rgb(205, 211, 218),
},
}
}
#[allow(dead_code)]
pub(crate) fn is_light(&self) -> bool {
matches!(self.bg, Color::Rgb(r, _, _) if r > 200)
}
#[must_use]
pub(crate) fn highlight(&self) -> Style {
Style::default().fg(self.brand)
}
#[must_use]
pub(crate) fn success(&self) -> Style {
Style::default().fg(self.success)
}
#[must_use]
pub(crate) fn error(&self) -> Style {
Style::default().fg(self.error)
}
#[must_use]
pub(crate) fn warning(&self) -> Style {
Style::default().fg(self.warning)
}
#[must_use]
pub(crate) fn title(&self) -> Style {
Style::default().fg(self.brand).add_modifier(Modifier::BOLD)
}
#[must_use]
pub(crate) fn border(&self) -> Style {
Style::default().fg(self.brand)
}
#[must_use]
pub(crate) fn muted(&self) -> Style {
Style::default().fg(self.grey)
}
#[must_use]
pub(crate) fn brand_bold(&self) -> Style {
Style::default().fg(self.brand).add_modifier(Modifier::BOLD)
}
#[must_use]
pub(crate) fn selected_row(&self) -> Style {
Style::default()
.fg(self.fg)
.bg(self.brand_dark)
.add_modifier(Modifier::BOLD)
}
#[must_use]
pub(crate) fn badge_unstable(&self) -> Style {
Style::default()
.fg(self.warning)
.add_modifier(Modifier::BOLD)
}
#[must_use]
pub(crate) fn badge_installed(&self) -> Style {
Style::default().fg(self.accent)
}
#[must_use]
pub(crate) fn badge_active(&self) -> Style {
Style::default()
.fg(self.success)
.add_modifier(Modifier::BOLD)
}
#[allow(dead_code)]
pub(crate) fn tab_inactive(&self) -> Style {
Style::default().fg(self.grey)
}
#[allow(dead_code)]
pub(crate) fn tab_active(&self) -> Style {
Style::default().fg(self.brand).add_modifier(Modifier::BOLD)
}
#[must_use]
pub(crate) fn key_hint(&self) -> Style {
Style::default().fg(self.brand).add_modifier(Modifier::BOLD)
}
#[must_use]
pub(crate) fn modal_body(&self) -> Style {
Style::default().fg(self.fg)
}
#[must_use]
pub(crate) fn dim_border(&self) -> Style {
Style::default().fg(self.dim)
}
}