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 {
|
2024-11-10 11:04:16 +00:00
|
|
|
fn get_color_variant(&self, default: Color, compatible: Color) -> Color {
|
2024-08-15 23:13:47 +01:00
|
|
|
match self {
|
2024-11-10 11:04:16 +00:00
|
|
|
Theme::Default => default,
|
|
|
|
Theme::Compatible => compatible,
|
2024-08-15 23:13:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-10 11:04:16 +00:00
|
|
|
fn get_icon_variant(&self, default: &'static str, compatible: &'static str) -> &'static str {
|
2024-08-15 23:13:47 +01:00
|
|
|
match self {
|
2024-11-10 11:04:16 +00:00
|
|
|
Theme::Default => default,
|
|
|
|
Theme::Compatible => compatible,
|
2024-08-15 23:13:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-10 11:04:16 +00: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)
|
|
|
|
}
|
|
|
|
|
2024-11-05 19:59:57 +00:00
|
|
|
pub fn multi_select_disabled_color(&self) -> Color {
|
2024-11-10 11:04:16 +00:00
|
|
|
self.get_color_variant(Color::DarkGray, Color::DarkGray)
|
2024-11-05 19:59:57 +00:00
|
|
|
}
|
|
|
|
|
2024-08-15 23:25:18 +01:00
|
|
|
pub fn tab_color(&self) -> Color {
|
2024-11-10 11:04:16 +00:00
|
|
|
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 {
|
2024-11-10 11:04:16 +00:00
|
|
|
self.get_icon_variant(" ", "[DIR]")
|
2024-08-15 23:13:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn cmd_icon(&self) -> &'static str {
|
2024-11-10 11:04:16 +00:00
|
|
|
self.get_icon_variant(" ", "[CMD]")
|
2024-08-15 23:13:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tab_icon(&self) -> &'static str {
|
2024-11-10 11:04:16 +00:00
|
|
|
self.get_icon_variant(" ", ">> ")
|
2024-08-15 23:13:47 +01:00
|
|
|
}
|
|
|
|
|
2024-09-19 19:15:30 +01:00
|
|
|
pub fn multi_select_icon(&self) -> &'static str {
|
2024-11-10 11:04:16 +00:00
|
|
|
self.get_icon_variant("", "*")
|
2024-09-19 19:15:30 +01:00
|
|
|
}
|
|
|
|
|
2024-08-15 23:13:47 +01:00
|
|
|
pub fn success_color(&self) -> Color {
|
2024-11-10 11:04:16 +00:00
|
|
|
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 {
|
2024-11-10 11:04:16 +00:00
|
|
|
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 {
|
2024-11-10 11:04:16 +00:00
|
|
|
self.get_color_variant(Color::LightBlue, Color::LightBlue)
|
2024-08-15 23:13:47 +01:00
|
|
|
}
|
|
|
|
|
2024-11-10 10:59:14 +00:00
|
|
|
pub fn search_preview_color(&self) -> Color {
|
2024-11-10 11:04:16 +00:00
|
|
|
self.get_color_variant(Color::DarkGray, Color::DarkGray)
|
2024-11-10 10:59:14 +00:00
|
|
|
}
|
|
|
|
|
2024-08-15 23:13:47 +01:00
|
|
|
pub fn unfocused_color(&self) -> Color {
|
2024-11-10 11:04:16 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|