summaryrefslogtreecommitdiffstats
path: root/src/config/raw/theme
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/raw/theme')
-rw-r--r--src/config/raw/theme/style.rs131
-rw-r--r--src/config/raw/theme/tab.rs48
2 files changed, 134 insertions, 45 deletions
diff --git a/src/config/raw/theme/style.rs b/src/config/raw/theme/style.rs
index a588bd5..fd037a7 100644
--- a/src/config/raw/theme/style.rs
+++ b/src/config/raw/theme/style.rs
@@ -1,11 +1,96 @@
use colors_transform::{Color, Rgb};
-
+use ratatui::style::{self, Style};
use serde::Deserialize;
-use ratatui::style;
-
use crate::config::clean::theme::style::AppStyle;
+fn str_to_color(s: &str) -> style::Color {
+ match s {
+ "black" => style::Color::Black,
+ "red" => style::Color::Red,
+ "green" => style::Color::Green,
+ "yellow" => style::Color::Yellow,
+ "blue" => style::Color::Blue,
+ "magenta" => style::Color::Magenta,
+ "cyan" => style::Color::Cyan,
+ "gray" => style::Color::Gray,
+ "dark_gray" => style::Color::DarkGray,
+ "light_red" => style::Color::LightRed,
+ "light_green" => style::Color::LightGreen,
+ "light_yellow" => style::Color::LightYellow,
+ "light_blue" => style::Color::LightBlue,
+ "light_magenta" => style::Color::LightMagenta,
+ "light_cyan" => style::Color::LightCyan,
+ "white" => style::Color::White,
+ "reset" => style::Color::Reset,
+ s if s.starts_with('#') => {
+ let rgb = match Rgb::from_hex_str(s) {
+ Ok(s) => s,
+ _ => return style::Color::Reset,
+ };
+ let r = rgb.get_red() as u8;
+ let g = rgb.get_green() as u8;
+ let b = rgb.get_blue() as u8;
+ style::Color::Rgb(r, g, b)
+ }
+ s if s.is_empty() => style::Color::Reset,
+ s => match s.parse::<Rgb>() {
+ Ok(rgb) => {
+ let r = rgb.get_red() as u8;
+ let g = rgb.get_green() as u8;
+ let b = rgb.get_blue() as u8;
+ style::Color::Rgb(r, g, b)
+ }
+ Err(_) => style::Color::Reset,
+ },
+ }
+}
+
+#[derive(Clone, Debug, Deserialize)]
+
+pub struct AppStyleOptionsRaw {
+ pub fg: Option<String>,
+ pub bg: Option<String>,
+ pub bold: Option<bool>,
+ pub underline: Option<bool>,
+ pub invert: Option<bool>,
+}
+
+impl AppStyleOptionsRaw {
+ pub fn as_style(&self) -> Style {
+ let mut add_modifier = style::Modifier::empty();
+ let mut sub_modifier = style::Modifier::empty();
+ if let Some(bold) = self.bold {
+ if bold {
+ add_modifier.insert(style::Modifier::BOLD);
+ } else {
+ sub_modifier.insert(style::Modifier::BOLD);
+ }
+ }
+ if let Some(underline) = self.underline {
+ if underline {
+ add_modifier.insert(style::Modifier::UNDERLINED);
+ } else {
+ sub_modifier.insert(style::Modifier::UNDERLINED);
+ }
+ }
+ if let Some(invert) = self.invert {
+ if invert {
+ add_modifier.insert(style::Modifier::REVERSED);
+ } else {
+ sub_modifier.insert(style::Modifier::REVERSED);
+ }
+ }
+ Style {
+ fg: self.fg.clone().map(|s| str_to_color(s.as_ref())),
+ bg: self.bg.clone().map(|s| str_to_color(s.as_ref())),
+ add_modifier,
+ sub_modifier,
+ //underline_color: None, # only when ratatui with crossterm
+ }
+ }
+}
+
#[derive(Clone, Debug, Deserialize)]
pub struct AppStyleRaw {
#[serde(default)]
@@ -40,45 +125,7 @@ impl AppStyleRaw {
}
pub fn str_to_color(s: &str) -> style::Color {
- match s {
- "black" => style::Color::Black,
- "red" => style::Color::Red,
- "green" => style::Color::Green,
- "yellow" => style::Color::Yellow,
- "blue" => style::Color::Blue,
- "magenta" => style::Color::Magenta,
- "cyan" => style::Color::Cyan,
- "gray" => style::Color::Gray,
- "dark_gray" => style::Color::DarkGray,
- "light_red" => style::Color::LightRed,
- "light_green" => style::Color::LightGreen,
- "light_yellow" => style::Color::LightYellow,
- "light_blue" => style::Color::LightBlue,
- "light_magenta" => style::Color::LightMagenta,
- "light_cyan" => style::Color::LightCyan,
- "white" => style::Color::White,
- "reset" => style::Color::Reset,
- s if s.starts_with('#') => {
- let rgb = match Rgb::from_hex_str(s) {
- Ok(s) => s,
- _ => return style::Color::Reset,
- };
- let r = rgb.get_red() as u8;
- let g = rgb.get_green() as u8;
- let b = rgb.get_blue() as u8;
- style::Color::Rgb(r, g, b)
- }
- s if s.is_empty() => style::Color::Reset,
- s => match s.parse::<Rgb>() {
- Ok(rgb) => {
- let r = rgb.get_red() as u8;
- let g = rgb.get_green() as u8;
- let b = rgb.get_blue() as u8;
- style::Color::Rgb(r, g, b)
- }
- Err(_) => style::Color::Reset,
- },
- }
+ str_to_color(s)
}
}
diff --git a/src/config/raw/theme/tab.rs b/src/config/raw/theme/tab.rs
index 1e1fef6..be71113 100644
--- a/src/config/raw/theme/tab.rs
+++ b/src/config/raw/theme/tab.rs
@@ -1,11 +1,53 @@
use serde::Deserialize;
-use super::style::AppStyleRaw;
+use super::style::AppStyleOptionsRaw;
#[derive(Clone, Debug, Deserialize, Default)]
pub struct TabThemeRaw {
#[serde(default)]
- pub inactive: AppStyleRaw,
+ pub styles: TabThemeColorRaw,
#[serde(default)]
- pub active: AppStyleRaw,
+ pub chars: TabThemeCharsRaw,
+}
+
+#[derive(Clone, Debug, Deserialize, Default)]
+pub struct TabThemeColorRaw {
+ pub active_prefix: Option<AppStyleOptionsRaw>,
+ pub active_postfix: Option<AppStyleOptionsRaw>,
+ pub active: Option<AppStyleOptionsRaw>,
+ pub inactive_prefix: Option<AppStyleOptionsRaw>,
+ pub inactive_postfix: Option<AppStyleOptionsRaw>,
+ pub inactive: Option<AppStyleOptionsRaw>,
+ pub divider_ii: Option<AppStyleOptionsRaw>,
+ pub divider_ia: Option<AppStyleOptionsRaw>,
+ pub divider_ai: Option<AppStyleOptionsRaw>,
+ pub scroll_front_prefix: Option<AppStyleOptionsRaw>,
+ pub scroll_front_postfix: Option<AppStyleOptionsRaw>,
+ pub scroll_front: Option<AppStyleOptionsRaw>,
+ pub scroll_back_prefix: Option<AppStyleOptionsRaw>,
+ pub scroll_back_postfix: Option<AppStyleOptionsRaw>,
+ pub scroll_back: Option<AppStyleOptionsRaw>,
+ pub padding_prefix: Option<AppStyleOptionsRaw>,
+ pub padding_postfix: Option<AppStyleOptionsRaw>,
+ pub padding_fill: Option<AppStyleOptionsRaw>,
+}
+
+#[derive(Clone, Debug, Deserialize, Default)]
+pub struct TabThemeCharsRaw {
+ pub active_prefix: Option<String>,
+ pub active_postfix: Option<String>,
+ pub inactive_prefix: Option<String>,
+ pub inactive_postfix: Option<String>,
+ pub divider: Option<String>,
+ pub scroll_front_prefix: Option<String>,
+ pub scroll_front_postfix: Option<String>,
+ pub scroll_front_prestring: Option<String>,
+ pub scroll_front_poststring: Option<String>,
+ pub scroll_back_prefix: Option<String>,
+ pub scroll_back_postfix: Option<String>,
+ pub scroll_back_prestring: Option<String>,
+ pub scroll_back_poststring: Option<String>,
+ pub padding_prefix: Option<char>,
+ pub padding_postfix: Option<char>,
+ pub padding_fill: Option<char>,
}