diff options
author | DLFW <daniel@llin.info> | 2023-06-25 20:47:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-25 14:47:23 -0400 |
commit | ee607354077375be6afc2e62abba7ac4b5c0190a (patch) | |
tree | a0a4f375e47225fddb580887e821950b7baedee8 /src | |
parent | f95658b72c184b15183b5fc8db517cf9688638a7 (diff) |
Tab theme configurable (#317)
Text style for tabs can be configured within
`theme.toml` with the dotted keys `tab.active` and `tab.inactive`.
The default style is the same as the former hard-coded style.
`theme.toml` has been restructured and comments have been
added to give a short documentation on each style item.
The documentation (`theme.toml.md`) has been enhanced, and
the excerpt of `theme.toml` with additional comments has
been removed from there.
That way it should be easier for devs to keep docs and the default
`theme.toml` in sync, and easier for users when the detail comments
can be found in the configuration file itself.
The conversion from `AppStyle` to `tui::style::Style` is now provided as
a function of `AppStyle` and a `From`-implementation for `Style` to
avoid having the same factory code repeating all over.
Diffstat (limited to 'src')
-rw-r--r-- | src/config/theme/app_theme.rs | 27 | ||||
-rw-r--r-- | src/config/theme/style.rs | 15 | ||||
-rw-r--r-- | src/ui/widgets/tui_tab.rs | 8 |
3 files changed, 44 insertions, 6 deletions
diff --git a/src/config/theme/app_theme.rs b/src/config/theme/app_theme.rs index cdf5eac..fdf3ca0 100644 --- a/src/config/theme/app_theme.rs +++ b/src/config/theme/app_theme.rs @@ -9,6 +9,8 @@ use crate::error::JoshutoResult; #[derive(Clone, Debug, Deserialize, Default)] pub struct AppThemeRaw { #[serde(default)] + pub tabs: TabThemeRaw, + #[serde(default)] pub regular: AppStyleRaw, #[serde(default)] pub selection: AppStyleRaw, @@ -28,8 +30,25 @@ pub struct AppThemeRaw { pub ext: HashMap<String, AppStyleRaw>, } +#[derive(Clone, Debug, Deserialize, Default)] +pub struct TabThemeRaw { + #[serde(default)] + pub inactive: AppStyleRaw, + #[serde(default)] + pub active: AppStyleRaw, +} + +impl From<TabThemeRaw> for TabTheme { + fn from(crude: TabThemeRaw) -> Self { + let inactive = crude.inactive.to_style_theme(); + let active = crude.active.to_style_theme(); + Self { inactive, active } + } +} + impl From<AppThemeRaw> for AppTheme { fn from(crude: AppThemeRaw) -> Self { + let tabs = crude.tabs; let selection = crude.selection.to_style_theme(); let visual_mode_selection = crude.visual_mode_selection.to_style_theme(); let executable = crude.executable.to_style_theme(); @@ -57,12 +76,14 @@ impl From<AppThemeRaw> for AppTheme { link_invalid, socket, ext, + tabs: TabTheme::from(tabs), } } } #[derive(Clone, Debug)] pub struct AppTheme { + pub tabs: TabTheme, pub regular: AppStyle, pub selection: AppStyle, pub visual_mode_selection: AppStyle, @@ -94,3 +115,9 @@ impl std::default::Default for AppTheme { Self::default_res().unwrap() } } + +#[derive(Clone, Debug)] +pub struct TabTheme { + pub inactive: AppStyle, + pub active: AppStyle, +} diff --git a/src/config/theme/style.rs b/src/config/theme/style.rs index 5fecdf8..e4ee599 100644 --- a/src/config/theme/style.rs +++ b/src/config/theme/style.rs @@ -2,7 +2,7 @@ use colors_transform::{Color, Rgb}; use serde_derive::Deserialize; -use tui::style; +use tui::style::{self, Style}; const fn default_color() -> style::Color { style::Color::Reset @@ -117,6 +117,10 @@ impl AppStyle { self.modifier.insert(modifier); self } + + pub fn as_style(&self) -> Style { + Style::from(self) + } } impl std::default::Default for AppStyle { @@ -128,3 +132,12 @@ impl std::default::Default for AppStyle { } } } + +impl From<&AppStyle> for Style { + fn from(style: &AppStyle) -> Self { + Self::default() + .fg(style.fg) + .bg(style.bg) + .add_modifier(style.modifier) + } +} diff --git a/src/ui/widgets/tui_tab.rs b/src/ui/widgets/tui_tab.rs index 76bfca5..35f6630 100644 --- a/src/ui/widgets/tui_tab.rs +++ b/src/ui/widgets/tui_tab.rs @@ -2,11 +2,11 @@ use std::ffi::OsStr; use tui::buffer::Buffer; use tui::layout::Rect; -use tui::style::{Color, Modifier, Style}; use tui::text::{Line, Span}; use tui::widgets::{Paragraph, Widget, Wrap}; use crate::context::TabContext; +use crate::THEME_T; pub struct TuiTabBar<'a> { context: &'a TabContext, @@ -20,10 +20,8 @@ impl<'a> TuiTabBar<'a> { impl<'a> Widget for TuiTabBar<'a> { fn render(self, area: Rect, buf: &mut Buffer) { - let regular_style = Style::default().fg(Color::White); - let selected_style = Style::default() - .fg(Color::White) - .add_modifier(Modifier::REVERSED); + let regular_style = THEME_T.tabs.inactive.as_style(); + let selected_style = THEME_T.tabs.active.as_style(); let index = self.context.index; let tab_order = self.context.tab_order.as_slice(); |