pub mod catppuccin;
#[allow(deprecated)]
pub use catppuccin::*;
pub mod dracula;
#[allow(deprecated)]
pub use dracula::*;
pub mod gruvbox;
#[allow(deprecated)]
pub use gruvbox::*;
pub mod nord;
#[allow(deprecated)]
pub use nord::*;
pub mod palette;
pub use palette::{NamedColor, Palette, Severity};
pub mod solarized;
#[allow(deprecated)]
pub use solarized::*;
use ratatui::style::{Color, Modifier, Style};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Theme {
pub background: Color,
pub foreground: Color,
pub border: Color,
pub focused: Color,
pub selected: Color,
pub disabled: Color,
pub placeholder: Color,
pub primary: Color,
pub success: Color,
pub warning: Color,
pub error: Color,
pub info: Color,
pub progress_filled: Color,
pub progress_empty: Color,
pub palette: Palette,
}
impl Default for Theme {
fn default() -> Self {
Self {
background: Color::Reset,
foreground: Color::Reset,
border: Color::Reset,
focused: Color::Yellow,
selected: Color::Reset,
disabled: Color::DarkGray,
placeholder: Color::DarkGray,
primary: Color::Cyan,
success: Color::Green,
warning: Color::Yellow,
error: Color::Red,
info: Color::Cyan,
progress_filled: Color::Cyan,
progress_empty: Color::Black,
palette: Palette {
rosewater: Color::Red,
flamingo: Color::Red,
pink: Color::Magenta,
mauve: Color::Magenta,
red: Color::Red,
maroon: Color::Red,
peach: Color::Yellow,
yellow: Color::Yellow,
green: Color::Green,
teal: Color::Green,
sky: Color::Cyan,
sapphire: Color::Cyan,
blue: Color::Blue,
lavender: Color::Magenta,
text: Color::White,
subtext1: Color::Gray,
subtext0: Color::Gray,
overlay2: Color::DarkGray,
overlay1: Color::DarkGray,
overlay0: Color::DarkGray,
surface2: Color::DarkGray,
surface1: Color::Black,
surface0: Color::Black,
base: Color::Reset,
mantle: Color::Reset,
crust: Color::Black,
},
}
}
}
impl Theme {
#[allow(deprecated)]
pub fn nord() -> Self {
Self {
background: NORD0,
foreground: NORD6,
border: NORD3,
focused: NORD8,
selected: NORD9,
disabled: NORD3,
placeholder: NORD3,
primary: NORD10,
success: NORD14,
warning: NORD13,
error: NORD11,
info: NORD8,
progress_filled: NORD8,
progress_empty: NORD1,
palette: Palette {
rosewater: NORD4,
flamingo: NORD4,
pink: NORD15,
mauve: NORD15,
red: NORD11,
maroon: NORD11,
peach: NORD12,
yellow: NORD13,
green: NORD14,
teal: NORD7,
sky: NORD8,
sapphire: NORD9,
blue: NORD10,
lavender: NORD15,
text: NORD6,
subtext1: NORD5,
subtext0: NORD4,
overlay2: NORD3,
overlay1: NORD3,
overlay0: NORD3,
surface2: NORD2,
surface1: NORD1,
surface0: NORD1,
base: NORD0,
mantle: NORD0,
crust: NORD0,
},
}
}
#[allow(deprecated)]
pub fn dracula() -> Self {
Self {
background: DRACULA_BG,
foreground: DRACULA_FG,
border: DRACULA_COMMENT,
focused: DRACULA_PURPLE,
selected: DRACULA_PINK,
disabled: DRACULA_COMMENT,
placeholder: DRACULA_COMMENT,
primary: DRACULA_CYAN,
success: DRACULA_GREEN,
warning: DRACULA_YELLOW,
error: DRACULA_RED,
info: DRACULA_CYAN,
progress_filled: DRACULA_PURPLE,
progress_empty: DRACULA_CURRENT,
palette: Palette {
rosewater: DRACULA_PINK,
flamingo: DRACULA_PINK,
pink: DRACULA_PINK,
mauve: DRACULA_PURPLE,
red: DRACULA_RED,
maroon: DRACULA_RED,
peach: DRACULA_ORANGE,
yellow: DRACULA_YELLOW,
green: DRACULA_GREEN,
teal: DRACULA_CYAN,
sky: DRACULA_CYAN,
sapphire: DRACULA_CYAN,
blue: DRACULA_CYAN,
lavender: DRACULA_PURPLE,
text: DRACULA_FG,
subtext1: DRACULA_FG,
subtext0: DRACULA_COMMENT,
overlay2: DRACULA_COMMENT,
overlay1: DRACULA_COMMENT,
overlay0: DRACULA_COMMENT,
surface2: DRACULA_CURRENT,
surface1: DRACULA_CURRENT,
surface0: DRACULA_CURRENT,
base: DRACULA_BG,
mantle: DRACULA_BG,
crust: DRACULA_BG,
},
}
}
#[allow(deprecated)]
pub fn solarized_dark() -> Self {
Self {
background: SOLARIZED_BASE03,
foreground: SOLARIZED_BASE0,
border: SOLARIZED_BASE01,
focused: SOLARIZED_BLUE,
selected: SOLARIZED_CYAN,
disabled: SOLARIZED_BASE01,
placeholder: SOLARIZED_BASE01,
primary: SOLARIZED_BLUE,
success: SOLARIZED_GREEN,
warning: SOLARIZED_YELLOW,
error: SOLARIZED_RED,
info: SOLARIZED_CYAN,
progress_filled: SOLARIZED_BLUE,
progress_empty: SOLARIZED_BASE02,
palette: Palette {
rosewater: SOLARIZED_MAGENTA,
flamingo: SOLARIZED_MAGENTA,
pink: SOLARIZED_MAGENTA,
mauve: SOLARIZED_MAGENTA,
red: SOLARIZED_RED,
maroon: SOLARIZED_RED,
peach: SOLARIZED_ORANGE,
yellow: SOLARIZED_YELLOW,
green: SOLARIZED_GREEN,
teal: SOLARIZED_CYAN,
sky: SOLARIZED_CYAN,
sapphire: SOLARIZED_BLUE,
blue: SOLARIZED_BLUE,
lavender: SOLARIZED_MAGENTA,
text: SOLARIZED_BASE1,
subtext1: SOLARIZED_BASE0,
subtext0: SOLARIZED_BASE01,
overlay2: SOLARIZED_BASE01,
overlay1: SOLARIZED_BASE01,
overlay0: SOLARIZED_BASE01,
surface2: SOLARIZED_BASE02,
surface1: SOLARIZED_BASE02,
surface0: SOLARIZED_BASE02,
base: SOLARIZED_BASE03,
mantle: SOLARIZED_BASE03,
crust: SOLARIZED_BASE03,
},
}
}
#[allow(deprecated)]
pub fn gruvbox_dark() -> Self {
Self {
background: GRUVBOX_BG,
foreground: GRUVBOX_FG,
border: GRUVBOX_GRAY,
focused: GRUVBOX_YELLOW,
selected: GRUVBOX_BLUE,
disabled: GRUVBOX_GRAY,
placeholder: GRUVBOX_GRAY,
primary: GRUVBOX_AQUA,
success: GRUVBOX_GREEN,
warning: GRUVBOX_ORANGE,
error: GRUVBOX_RED,
info: GRUVBOX_BLUE,
progress_filled: GRUVBOX_YELLOW,
progress_empty: GRUVBOX_BG1,
palette: Palette {
rosewater: GRUVBOX_PURPLE,
flamingo: GRUVBOX_PURPLE,
pink: GRUVBOX_PURPLE,
mauve: GRUVBOX_PURPLE,
red: GRUVBOX_RED,
maroon: GRUVBOX_RED,
peach: GRUVBOX_ORANGE,
yellow: GRUVBOX_YELLOW,
green: GRUVBOX_GREEN,
teal: GRUVBOX_AQUA,
sky: GRUVBOX_AQUA,
sapphire: GRUVBOX_BLUE,
blue: GRUVBOX_BLUE,
lavender: GRUVBOX_PURPLE,
text: GRUVBOX_FG,
subtext1: GRUVBOX_FG,
subtext0: GRUVBOX_GRAY,
overlay2: GRUVBOX_GRAY,
overlay1: GRUVBOX_GRAY,
overlay0: GRUVBOX_GRAY,
surface2: GRUVBOX_BG1,
surface1: GRUVBOX_BG1,
surface0: GRUVBOX_BG1,
base: GRUVBOX_BG,
mantle: GRUVBOX_BG,
crust: GRUVBOX_BG,
},
}
}
#[allow(deprecated)]
pub fn catppuccin_mocha() -> Self {
Self {
background: CATPPUCCIN_BASE,
foreground: CATPPUCCIN_TEXT,
border: CATPPUCCIN_SURFACE2,
focused: CATPPUCCIN_LAVENDER,
selected: CATPPUCCIN_MAUVE,
disabled: CATPPUCCIN_SURFACE2,
placeholder: CATPPUCCIN_OVERLAY0,
primary: CATPPUCCIN_BLUE,
success: CATPPUCCIN_GREEN,
warning: CATPPUCCIN_YELLOW,
error: CATPPUCCIN_RED,
info: CATPPUCCIN_SAPPHIRE,
progress_filled: CATPPUCCIN_LAVENDER,
progress_empty: CATPPUCCIN_SURFACE0,
palette: Palette {
rosewater: CATPPUCCIN_ROSEWATER,
flamingo: CATPPUCCIN_FLAMINGO,
pink: CATPPUCCIN_PINK,
mauve: CATPPUCCIN_MAUVE,
red: CATPPUCCIN_RED,
maroon: CATPPUCCIN_MAROON,
peach: CATPPUCCIN_PEACH,
yellow: CATPPUCCIN_YELLOW,
green: CATPPUCCIN_GREEN,
teal: CATPPUCCIN_TEAL,
sky: CATPPUCCIN_SKY,
sapphire: CATPPUCCIN_SAPPHIRE,
blue: CATPPUCCIN_BLUE,
lavender: CATPPUCCIN_LAVENDER,
text: CATPPUCCIN_TEXT,
subtext1: CATPPUCCIN_SUBTEXT1,
subtext0: CATPPUCCIN_SUBTEXT0,
overlay2: CATPPUCCIN_OVERLAY2,
overlay1: CATPPUCCIN_OVERLAY1,
overlay0: CATPPUCCIN_OVERLAY0,
surface2: CATPPUCCIN_SURFACE2,
surface1: CATPPUCCIN_SURFACE1,
surface0: CATPPUCCIN_SURFACE0,
base: CATPPUCCIN_BASE,
mantle: CATPPUCCIN_MANTLE,
crust: CATPPUCCIN_CRUST,
},
}
}
pub fn focused_style(&self) -> Style {
Style::default().fg(self.focused)
}
pub fn focused_bold_style(&self) -> Style {
Style::default()
.fg(self.focused)
.add_modifier(Modifier::BOLD)
}
pub fn focused_border_style(&self) -> Style {
Style::default().fg(self.focused).bg(self.background)
}
pub fn selected_style(&self, focused: bool) -> Style {
if focused {
Style::default()
.fg(self.focused)
.add_modifier(Modifier::BOLD)
} else {
Style::default().add_modifier(Modifier::BOLD)
}
}
pub fn selected_highlight_style(&self, focused: bool) -> Style {
if focused {
Style::default()
.bg(self.selected)
.fg(self.foreground)
.add_modifier(Modifier::BOLD)
} else {
Style::default().bg(self.disabled).fg(self.foreground)
}
}
pub fn selection_style(&self) -> Style {
Style::default().bg(self.selected).fg(self.foreground)
}
pub fn disabled_style(&self) -> Style {
Style::default().fg(self.disabled)
}
pub fn placeholder_style(&self) -> Style {
Style::default().fg(self.placeholder)
}
pub fn normal_style(&self) -> Style {
Style::default().fg(self.foreground).bg(self.background)
}
pub fn primary_style(&self) -> Style {
Style::default().fg(self.primary)
}
pub fn border_style(&self) -> Style {
Style::default().fg(self.border)
}
pub fn success_style(&self) -> Style {
Style::default().fg(self.success)
}
pub fn warning_style(&self) -> Style {
Style::default().fg(self.warning)
}
pub fn error_style(&self) -> Style {
Style::default().fg(self.error)
}
pub fn info_style(&self) -> Style {
Style::default().fg(self.info)
}
pub fn progress_filled_style(&self) -> Style {
Style::default()
.fg(self.progress_filled)
.bg(self.progress_empty)
}
}
#[cfg(test)]
mod tests;