summaryrefslogtreecommitdiff
path: root/src/config/keymap/keymap_store.rs
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-08-08 21:46:54 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2024-08-08 21:46:54 +0200
commit4763d8ce3b833df1e7321a407b08666f69657fdb (patch)
tree472e38eedef269c244726083bab94afa2942d945 /src/config/keymap/keymap_store.rs
parent41d707480f2138a8a9b00b4efac4c87ed0eb79fc (diff)
refactore runnable
Diffstat (limited to 'src/config/keymap/keymap_store.rs')
-rw-r--r--src/config/keymap/keymap_store.rs37
1 files changed, 4 insertions, 33 deletions
diff --git a/src/config/keymap/keymap_store.rs b/src/config/keymap/keymap_store.rs
index 233ac52..e5e32e5 100644
--- a/src/config/keymap/keymap_store.rs
+++ b/src/config/keymap/keymap_store.rs
@@ -4,14 +4,13 @@ use std::{
sync::{Arc, Mutex},
};
-use mlua::{Function, RegistryKey, Result};
use ratatui::crossterm::event::KeyEvent;
-use crate::lua;
+use crate::lua::runnable::Runnable;
#[derive(Default, Clone)]
pub struct KeyMapStore {
- store: Option<HashMap<KeyEvent, Arc<Mutex<dyn Runnable>>>>,
+ store: Option<HashMap<KeyEvent, Arc<Mutex<dyn Runnable<(), bool>>>>>,
}
impl KeyMapStore {
@@ -19,7 +18,7 @@ impl KeyMapStore {
Self { store: None }
}
- pub fn get(&mut self, event: KeyEvent) -> Option<Arc<Mutex<dyn Runnable>>> {
+ pub fn get(&mut self, event: KeyEvent) -> Option<Arc<Mutex<dyn Runnable<(), bool>>>> {
match &self.store {
Some(store) => match store.get(&event) {
Some(func) => Some(Arc::clone(func)),
@@ -32,7 +31,7 @@ impl KeyMapStore {
}
}
- pub fn map(&mut self, event: KeyEvent, func: impl Runnable + 'static) {
+ pub fn map(&mut self, event: KeyEvent, func: impl Runnable<(), bool> + 'static) {
match &self.store {
Some(_) => {}
None => self.store = Some(HashMap::new()),
@@ -44,34 +43,6 @@ impl KeyMapStore {
}
}
-pub trait Runnable
-where
- Self: Send,
-{
- fn run(&self) -> Result<bool>;
-}
-
-impl<T> Runnable for T
-where
- T: Fn() -> bool,
- Self: Send,
-{
- fn run(&self) -> Result<bool> {
- Ok(self())
- }
-}
-
-impl Runnable for RegistryKey
-where
- Self: Send,
-{
- fn run(&self) -> Result<bool> {
- let lua = lua::get();
- let func: Function = lua.registry_value(self)?;
- Ok(func.call::<(), bool>(()).unwrap_or(false))
- }
-}
-
impl fmt::Debug for KeyMapStore {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "KeyMapStore")