diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-08-02 14:05:30 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-08-02 14:05:30 +0200 |
| commit | 555a45a9f2b68a48b098099804ce795e3d5a350b (patch) | |
| tree | c13dbfc5e380f9c2b21fa87ce889a6379fef44b2 | |
| parent | 04a5a938994ddb95cfaa9a74b180e457d3a2b5d0 (diff) | |
sheetview add background theme parameter
| -rw-r--r-- | src/config/theme/sheetview.rs | 10 | ||||
| -rw-r--r-- | src/lua/evalsto.rs | 10 | ||||
| -rw-r--r-- | src/sheet/luaref.rs | 6 | ||||
| -rw-r--r-- | src/sheet/map.rs (renamed from src/sheet/foreach.rs) | 8 | ||||
| -rw-r--r-- | src/sheet/mod.rs | 2 | ||||
| -rw-r--r-- | src/widgets/sheetview/mod.rs | 13 |
6 files changed, 31 insertions, 18 deletions
diff --git a/src/config/theme/sheetview.rs b/src/config/theme/sheetview.rs index bcd53e1..af0b585 100644 --- a/src/config/theme/sheetview.rs +++ b/src/config/theme/sheetview.rs @@ -10,6 +10,7 @@ pub struct SheetViewTheme { pub cursor: EvalTo<Style, CellRef>, pub selection: EvalTo<Style, CellRef>, pub cell: EvalTo<Style, CellRef>, + pub background: EvalTo<Style, ()>, } impl SheetViewTheme { @@ -18,6 +19,7 @@ impl SheetViewTheme { cursor: EvalTo::Value(Style::new().fg(Color::Black).bg(Color::White)), 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)), } } } @@ -44,17 +46,21 @@ impl UserData for SheetViewTheme { }); fields.add_field_function_get("selection", |_, _| Ok(cfg!().selection.clone())); - fields.add_field_function_set("selection", |_, _, pair: EvalTo<Style, CellRef>| { cfg_mut!().selection = pair; Ok(()) }); fields.add_field_function_get("cell", |_, _| Ok(cfg!().cell.clone())); - fields.add_field_function_set("cell", |_, _, cell: EvalTo<Style, CellRef>| { cfg_mut!().cell = cell; Ok(()) }); + + fields.add_field_function_get("background", |_, _| Ok(cfg!().background.clone())); + fields.add_field_function_set("background", |_, _, background: EvalTo<Style, ()>| { + cfg_mut!().background = background; + Ok(()) + }); } } diff --git a/src/lua/evalsto.rs b/src/lua/evalsto.rs index 6d8ab29..d72638e 100644 --- a/src/lua/evalsto.rs +++ b/src/lua/evalsto.rs @@ -1,6 +1,6 @@ use std::{fmt, marker::PhantomData, sync::Arc}; -use mlua::{FromLua, IntoLua, Lua, Result, Value}; +use mlua::{FromLua, IntoLua, IntoLuaMulti, Lua, Result, Value}; use crate::lua::ownedfunction::OwnedFunction; @@ -14,7 +14,7 @@ impl<T, A> EvalTo<T, A> { pub fn get<'lua>(&'lua self, args: A, lua: &'lua Lua) -> Result<T> where T: FromLua<'lua> + Clone, - A: IntoLua<'lua>, + A: IntoLuaMulti<'lua>, { match self { EvalTo::Function(value, _) => { @@ -33,7 +33,7 @@ impl<T, A> EvalTo<T, A> { impl<'lua, T, A> FromLua<'lua> for EvalTo<T, A> where T: FromLua<'lua> + Clone, - A: IntoLua<'lua>, + A: IntoLuaMulti<'lua>, { fn from_lua( value: mlua::prelude::LuaValue<'lua>, @@ -53,7 +53,7 @@ where impl<'lua, T, A> IntoLua<'lua> for EvalTo<T, A> where T: FromLua<'lua> + Clone + IntoLua<'lua>, - A: IntoLua<'lua>, + A: IntoLuaMulti<'lua>, { fn into_lua(self, lua: &'lua mlua::prelude::Lua) -> Result<Value<'lua>> { match self { @@ -74,7 +74,7 @@ where impl<T, A> fmt::Debug for EvalTo<T, A> where - T: fmt::Debug + T: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/src/sheet/luaref.rs b/src/sheet/luaref.rs index fa4b8f9..5fb6bed 100644 --- a/src/sheet/luaref.rs +++ b/src/sheet/luaref.rs @@ -1,7 +1,7 @@ use crate::state::GlobalState; use super::{ - foreach::LuaForEach, + map::LuaMap, register::{Register, SheetId}, }; use mlua::prelude::*; @@ -41,7 +41,7 @@ impl LuaUserData for SheetLuaRef { } }); - methods.add_method_mut("foreach", |_, luaref, func: LuaFunction| { + methods.add_method_mut("map", |_, luaref, func: LuaFunction| { let range: Vec<_> = { let state = GlobalState::instance(); let lock = state.sheetview.active_sheet().unwrap(); @@ -66,7 +66,7 @@ impl LuaUserData for SheetLuaRef { } }; - Register::get(luaref.id).unwrap().lua_foreach(func, range) + Register::get(luaref.id).unwrap().lua_map(func, range) }) } } diff --git a/src/sheet/foreach.rs b/src/sheet/map.rs index a2a3f90..09209a3 100644 --- a/src/sheet/foreach.rs +++ b/src/sheet/map.rs @@ -4,16 +4,16 @@ use mlua::prelude::*; use super::{cell::Cell, Sheet}; -pub trait LuaForEach { - fn lua_foreach<'lua>( +pub trait LuaMap { + fn lua_map<'lua>( &self, func: LuaFunction<'lua>, range: Vec<(usize, usize)>, ) -> Result<(), LuaError>; } -impl LuaForEach for Arc<RwLock<Sheet>> { - fn lua_foreach<'lua>( +impl LuaMap for Arc<RwLock<Sheet>> { + fn lua_map<'lua>( &self, func: LuaFunction<'lua>, range: Vec<(usize, usize)>, diff --git a/src/sheet/mod.rs b/src/sheet/mod.rs index 5f28e07..ffaec94 100644 --- a/src/sheet/mod.rs +++ b/src/sheet/mod.rs @@ -1,7 +1,7 @@ use cell::{Cell, CellRef}; pub mod cell; -pub mod foreach; +pub mod map; pub mod register; pub mod luaref; diff --git a/src/widgets/sheetview/mod.rs b/src/widgets/sheetview/mod.rs index aac2080..2239a0b 100644 --- a/src/widgets/sheetview/mod.rs +++ b/src/widgets/sheetview/mod.rs @@ -3,7 +3,7 @@ use ratatui::{ prelude::*, style::Stylize, text::ToLine, - widgets::Widget, + widgets::{Paragraph, Widget}, }; use crate::{ @@ -62,10 +62,10 @@ impl SheetView { fn open_editor(&self) { let mut state = GlobalState::instance_mut(); state.editor.buffer.set_lines_from_string( -r#"require('neosheet') + r#"require('neosheet') .state .view - .active:foreach(function(cell) + .active:map(function(cell) return "" end)"#, ); @@ -188,6 +188,13 @@ impl Widget for &mut SheetView { self.scroll.1 = cursor.x(); } + theme + .background + .get((), &lua::get()) + .unwrap_or_default() + .apply(Paragraph::default()) + .render(area, buf); + for row in 0..viewport_rows { for column in 0..(viewport_columns + 1) { let (cell_pos_y, cell_pos_x) = (row + self.scroll.0, column + self.scroll.1); |