summaryrefslogtreecommitdiff
path: root/src/config
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 15:51:45 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 15:51:45 +0200
commitd1492a10cdaf714074d29ad3366ab9c169d95b75 (patch)
tree4192aa6825479f56332b3cd40d56913e48b95222 /src/config
parentc920f258f6c9b0623a841b7c27561fa1d09cef72 (diff)
add bartheme and barstate to sheetview
Diffstat (limited to 'src/config')
-rw-r--r--src/config/theme/bar.rs62
-rw-r--r--src/config/theme/mod.rs1
-rw-r--r--src/config/theme/sheetview/bar.rs8
-rw-r--r--src/config/theme/sheetview/mod.rs (renamed from src/config/theme/sheetview.rs)10
-rw-r--r--src/config/theme/style.rs6
5 files changed, 85 insertions, 2 deletions
diff --git a/src/config/theme/bar.rs b/src/config/theme/bar.rs
new file mode 100644
index 0000000..68a3b13
--- /dev/null
+++ b/src/config/theme/bar.rs
@@ -0,0 +1,62 @@
+macro_rules! BarTheme {
+ ($name:ident, $cfg:expr, $cfg_mut:expr) => {
+ use crate::config::theme::style::Style;
+ use crate::lua::evalsto::EvalTo;
+ use crate::state::view::mode::Mode;
+ use crate::widgets::statusbar::StatusBar;
+ use mlua::{Lua, UserData};
+
+ #[derive(Debug, Default, Clone)]
+ pub struct $name {
+ pub left: EvalTo<Style, Mode>,
+ pub middle: EvalTo<Style, Mode>,
+ pub right: EvalTo<Style, Mode>,
+ }
+
+ impl $name {
+ pub const fn new() -> Self {
+ Self {
+ left: EvalTo::Value(Style::new()),
+ middle: EvalTo::Value(Style::new()),
+ right: EvalTo::Value(Style::new()),
+ }
+ }
+
+ pub fn apply(bar: &mut StatusBar, mode: Mode, lua: &Lua) {
+ let (left, middle, right) = (
+ $cfg.left.get(mode, lua).unwrap_or_default().style(),
+ $cfg.middle.get(mode, lua).unwrap_or_default().style(),
+ $cfg.right.get(mode, lua).unwrap_or_default().style(),
+ );
+
+ bar.set_left_style(left);
+ bar.set_middle_style(middle);
+ bar.set_right_style(right);
+ }
+ }
+
+ impl UserData for $name {
+ fn add_fields<'lua, F: mlua::prelude::LuaUserDataFields<'lua, Self>>(fields: &mut F) {
+ fields.add_field_function_get("left", |_, _| Ok($cfg.left.clone()));
+ fields.add_field_function_set("left", |_, _, style: EvalTo<Style, Mode>| {
+ $cfg_mut.left = style;
+ Ok(())
+ });
+
+ fields.add_field_function_get("middle", |_, _| Ok($cfg.middle.clone()));
+ fields.add_field_function_set("middle", |_, _, style: EvalTo<Style, Mode>| {
+ $cfg_mut.middle = style;
+ Ok(())
+ });
+
+ fields.add_field_function_get("right", |_, _| Ok($cfg.right.clone()));
+ fields.add_field_function_set("right", |_, _, style: EvalTo<Style, Mode>| {
+ $cfg_mut.right = style;
+ Ok(())
+ });
+ }
+ }
+ };
+}
+
+pub(super) use BarTheme;
diff --git a/src/config/theme/mod.rs b/src/config/theme/mod.rs
index 75f65a0..082cd17 100644
--- a/src/config/theme/mod.rs
+++ b/src/config/theme/mod.rs
@@ -7,6 +7,7 @@ use super::DUMMY_CONFIG;
pub mod style;
pub mod sheetview;
+pub(self) mod bar;
#[derive(Clone, Debug, Default)]
pub struct Theme {
diff --git a/src/config/theme/sheetview/bar.rs b/src/config/theme/sheetview/bar.rs
new file mode 100644
index 0000000..c3d1d50
--- /dev/null
+++ b/src/config/theme/sheetview/bar.rs
@@ -0,0 +1,8 @@
+use super::super::bar::BarTheme;
+use crate::config::GlobalConfig;
+
+BarTheme!(
+ SheetViewBarTheme,
+ GlobalConfig::instance().theme.sheetview.bar,
+ GlobalConfig::instance_mut().theme.sheetview.bar
+);
diff --git a/src/config/theme/sheetview.rs b/src/config/theme/sheetview/mod.rs
index af0b585..fc999ca 100644
--- a/src/config/theme/sheetview.rs
+++ b/src/config/theme/sheetview/mod.rs
@@ -1,16 +1,21 @@
use mlua::UserData;
use ratatui::style::Color;
-use crate::{config::GlobalConfig, lua::evalsto::EvalTo, sheet::cell::CellRef};
+use crate::{config::{GlobalConfig, DUMMY_CONFIG}, lua::evalsto::EvalTo, sheet::cell::CellRef};
+
+use self::bar::SheetViewBarTheme;
use super::style::Style;
+pub mod bar;
+
#[derive(Debug, Clone, Default)]
pub struct SheetViewTheme {
pub cursor: EvalTo<Style, CellRef>,
pub selection: EvalTo<Style, CellRef>,
pub cell: EvalTo<Style, CellRef>,
pub background: EvalTo<Style, ()>,
+ pub bar: SheetViewBarTheme,
}
impl SheetViewTheme {
@@ -20,6 +25,7 @@ impl SheetViewTheme {
selection: EvalTo::Value(Style::new().fg(Color::White).bg(Color::DarkGray)),
cell: EvalTo::Value(Style::new().fg(Color::White).bg(Color::Black)),
background: EvalTo::Value(Style::new().bg(Color::Black)),
+ bar: SheetViewBarTheme::new(),
}
}
}
@@ -62,5 +68,7 @@ impl UserData for SheetViewTheme {
cfg_mut!().background = background;
Ok(())
});
+
+ fields.add_field_function_get("bar", |_, _| Ok(DUMMY_CONFIG.theme.sheetview.bar))
}
}
diff --git a/src/config/theme/style.rs b/src/config/theme/style.rs
index 87cd068..aadd73b 100644
--- a/src/config/theme/style.rs
+++ b/src/config/theme/style.rs
@@ -38,6 +38,10 @@ impl Style {
S: Styled<Item = I>,
I: Styled,
{
+ s.set_style(self.style())
+ }
+
+ pub fn style(&self) -> ratatui::style::Style {
let mut style = ratatui::style::Style::default();
if let Some(fg) = self.fg {
@@ -60,7 +64,7 @@ impl Style {
style = style.underlined()
}
- s.set_style(style)
+ style
}
}