diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-07-26 10:32:55 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-07-26 10:32:55 +0200 |
| commit | 6ca07d6af8a338e76817d06c6c6c6f13e64fba9c (patch) | |
| tree | 32680f0942da8c45af8425ebc20330f5456a9213 /src/config/mod.rs | |
| parent | 8b7c56df1940d2ac6e3ece3385464009e46382fa (diff) | |
add neosheetrc support
Diffstat (limited to 'src/config/mod.rs')
| -rw-r--r-- | src/config/mod.rs | 37 |
1 files changed, 37 insertions, 0 deletions
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<GlobalConfig> = 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)) + } +} |