From 6ca07d6af8a338e76817d06c6c6c6f13e64fba9c Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Fri, 26 Jul 2024 10:32:55 +0200 Subject: add neosheetrc support --- src/config/mod.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/config/mod.rs (limited to 'src/config/mod.rs') diff --git a/src/config/mod.rs b/src/config/mod.rs new file mode 100644 index 0000000..e6c4952 --- /dev/null +++ b/src/config/mod.rs @@ -0,0 +1,37 @@ +use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; + +use mlua::{UserData, UserDataFields}; + +use self::theme::Theme; + +pub mod theme; +pub mod constants; + +pub struct GlobalConfig { + pub theme: Theme, +} + +static GLOBAL_CONFIG: RwLock = RwLock::new(GlobalConfig::new()); +const DUMMY_CONFIG: GlobalConfig = GlobalConfig::new(); + +impl GlobalConfig { + pub const fn new() -> Self { + Self { + theme: Theme::new(), + } + } + + pub fn instance() -> RwLockReadGuard<'static, Self> { + GLOBAL_CONFIG.read().unwrap() + } + + pub fn instance_mut() -> RwLockWriteGuard<'static, Self> { + GLOBAL_CONFIG.write().unwrap() + } +} + +impl UserData for GlobalConfig { + fn add_fields<'lua, F: UserDataFields<'lua, Self>>(fields: &mut F) { + fields.add_field_function_get("theme", |_, _| Ok(DUMMY_CONFIG.theme)) + } +} -- cgit v1.2.3-70-g09d2