linutil/tui/src/theme.rs

97 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 {
fn get_color_variant(&self, default: Color, compatible: Color) -> Color {
2024-08-15 23:13:47 +01:00
match self {
Theme::Default => default,
Theme::Compatible => compatible,
2024-08-15 23:13:47 +01:00
}
}
fn get_icon_variant(&self, default: &'static str, compatible: &'static str) -> &'static str {
2024-08-15 23:13:47 +01:00
match self {
Theme::Default => default,
Theme::Compatible => compatible,
2024-08-15 23:13:47 +01:00
}
}
pub fn dir_color(&self) -> Color {
self.get_color_variant(Color::Blue, Color::Blue)
}
pub fn cmd_color(&self) -> Color {
self.get_color_variant(Color::Rgb(204, 224, 208), Color::LightGreen)
}
pub fn multi_select_disabled_color(&self) -> Color {
self.get_color_variant(Color::DarkGray, Color::DarkGray)
}
2024-08-15 23:25:18 +01:00
pub fn tab_color(&self) -> Color {
self.get_color_variant(Color::Rgb(255, 255, 85), Color::Yellow)
2024-08-15 23:13:47 +01:00
}
pub fn dir_icon(&self) -> &'static str {
self.get_icon_variant("", "[DIR]")
2024-08-15 23:13:47 +01:00
}
pub fn cmd_icon(&self) -> &'static str {
self.get_icon_variant("", "[CMD]")
2024-08-15 23:13:47 +01:00
}
pub fn tab_icon(&self) -> &'static str {
self.get_icon_variant("", ">> ")
2024-08-15 23:13:47 +01:00
}
pub fn multi_select_icon(&self) -> &'static str {
self.get_icon_variant("", "*")
}
2024-08-15 23:13:47 +01:00
pub fn success_color(&self) -> Color {
self.get_color_variant(Color::Rgb(5, 255, 55), Color::Green)
2024-08-15 23:13:47 +01:00
}
pub fn fail_color(&self) -> Color {
self.get_color_variant(Color::Rgb(199, 55, 44), Color::Red)
2024-08-15 23:13:47 +01:00
}
pub fn focused_color(&self) -> Color {
self.get_color_variant(Color::LightBlue, Color::LightBlue)
2024-08-15 23:13:47 +01:00
}
pub fn search_preview_color(&self) -> Color {
self.get_color_variant(Color::DarkGray, Color::DarkGray)
}
2024-08-15 23:13:47 +01:00
pub fn unfocused_color(&self) -> Color {
self.get_color_variant(Color::Gray, Color::Gray)
2024-08-15 23:13:47 +01:00
}
}
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
}
}