summaryrefslogtreecommitdiff
path: root/src/config/theme/view/mod.rs
blob: 931e7dd4b8f0974de339f56cf859418edccfc662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use mlua::UserData;
use ratatui::style::Color;

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 {
    pub const fn new() -> Self {
        Self {
            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)),
            bar: SheetViewBarTheme::new(),
        }
    }
}

macro_rules! cfg {
    () => {
        GlobalConfig::get().theme.view
    };
}

impl UserData for SheetViewTheme {
    fn add_fields<'lua, F: mlua::prelude::LuaUserDataFields<'lua, Self>>(fields: &mut F) {
        fields.add_field_function_get("cursor", |_, _| Ok(cfg!().cursor.clone()));

        fields.add_field_function_set("cursor", |_, _, pair: EvalTo<Style, CellRef>| {
            cfg!().cursor = pair;
            Ok(())
        });

        fields.add_field_function_get("selection", |_, _| Ok(cfg!().selection.clone()));
        fields.add_field_function_set("selection", |_, _, pair: EvalTo<Style, CellRef>| {
            cfg!().selection = pair;
            Ok(())
        });

        fields.add_field_function_get("cell", |_, _| Ok(cfg!().cell.clone()));
        fields.add_field_function_set("cell", |_, _, cell: EvalTo<Style, CellRef>| {
            cfg!().cell = cell;
            Ok(())
        });

        fields.add_field_function_get("background", |_, _| Ok(cfg!().background.clone()));
        fields.add_field_function_set("background", |_, _, background: EvalTo<Style, ()>| {
            cfg!().background = background;
            Ok(())
        });

        fields.add_field_function_get("bar", |_, _| Ok(DUMMY_CONFIG.theme.view.bar))
    }
}