linutil/tui/src/theme.rs

108 lines
2.6 KiB
Rust
Raw Normal View History

2024-08-15 23:13:47 +01:00
use clap::ValueEnum;
2024-06-06 23:56:45 +01:00
use ratatui::style::Color;
2024-08-15 23:13:47 +01:00
// Add the Theme name here for a new theme
// This is more secure than the previous list
// We cannot index out of bounds, and we are giving
// names to our various themes, making it very clear
// This will make it easy to add new themes
#[derive(Clone, Debug, PartialEq, Default, ValueEnum, Copy)]
pub enum Theme {
#[default]
Default,
Compatible,
2024-06-06 23:56:45 +01:00
}
2024-08-15 23:13:47 +01:00
impl Theme {
pub fn dir_color(&self) -> Color {
match self {
Theme::Default => Color::Blue,
Theme::Compatible => Color::Blue,
}
}
pub fn cmd_color(&self) -> Color {
match self {
Theme::Default => Color::Rgb(204, 224, 208),
Theme::Compatible => Color::LightGreen,
}
}
2024-08-15 23:25:18 +01:00
pub fn tab_color(&self) -> Color {
2024-08-15 23:13:47 +01:00
match self {
Theme::Default => Color::Rgb(255, 255, 85),
Theme::Compatible => Color::Yellow,
}
}
pub fn dir_icon(&self) -> &'static str {
match self {
Theme::Default => "",
Theme::Compatible => "[DIR]",
}
}
pub fn cmd_icon(&self) -> &'static str {
match self {
Theme::Default => "",
Theme::Compatible => "[CMD]",
}
}
pub fn tab_icon(&self) -> &'static str {
match self {
Theme::Default => "",
Theme::Compatible => ">> ",
}
}
pub fn multi_select_icon(&self) -> &'static str {
match self {
Theme::Default => "",
Theme::Compatible => "*",
}
}
2024-08-15 23:13:47 +01:00
pub fn success_color(&self) -> Color {
match self {
Theme::Default => Color::Rgb(199, 55, 44),
Theme::Compatible => Color::Green,
}
}
pub fn fail_color(&self) -> Color {
match self {
Theme::Default => Color::Rgb(5, 255, 55),
Theme::Compatible => Color::Red,
}
}
pub fn focused_color(&self) -> Color {
match self {
Theme::Default => Color::LightBlue,
Theme::Compatible => Color::LightBlue,
}
}
pub fn unfocused_color(&self) -> Color {
match self {
Theme::Default => Color::Gray,
Theme::Compatible => Color::Gray,
}
}
}
impl Theme {
2024-08-17 19:32:53 +01:00
pub fn next(&mut self) {
let position = *self as usize;
2024-08-15 23:13:47 +01:00
let types = Theme::value_variants();
2024-08-17 19:32:53 +01:00
*self = types[(position + 1) % types.len()];
2024-08-15 23:13:47 +01:00
}
2024-08-17 19:32:53 +01:00
pub fn prev(&mut self) {
let position = *self as usize;
2024-08-15 23:13:47 +01:00
let types = Theme::value_variants();
2024-08-17 19:32:53 +01:00
*self = types[(position + types.len() - 1) % types.len()];
2024-08-15 23:13:47 +01:00
}
}