use mlua::UserData; use ratatui::crossterm::event::KeyEvent; use self::{event_from_string::event_from_string, keymap_store::KeyMapStore}; use super::{GlobalConfig, DUMMY_CONFIG}; use crate::lua::{self, ownedfunction::OwnedFunction, runnable::Runnable}; use template::KeyMapSections; pub mod event_from_string; pub mod keymap_store; pub mod template; macro_rules! KeyMap { ($($name:ident => $key:ident),+ $(,)?) => { KeyMapSections!($($name => $key,)*); #[derive(Debug, Default, Clone)] pub struct KeyMap { $($key: $name,)* } impl KeyMap { pub const fn new() -> Self { Self { $($key: $name::new(),)* } } } impl UserData for KeyMap { fn add_fields<'lua, F: mlua::prelude::LuaUserDataFields<'lua, Self>>(fields: &mut F) { $( fields.add_field_function_get(stringify!($key), |_, _| Ok(DUMMY_CONFIG.keymap.$key.clone())); )* } } }; } KeyMap!( ViewKeyMap => view, GlobalKeyMap => global, EditorKeyMap => editor, );