lol tmux jumbles the input codes immensely

This commit is contained in:
🪞👃🪞 2025-01-14 20:56:48 +01:00
parent a66bc5ca5e
commit 228b4bb47c
8 changed files with 98 additions and 61 deletions

View file

@ -1,6 +1,38 @@
use crate::*;
use EdnItem::*;
pub struct EdnKeyMapToCommand<'a>(Vec<EdnItem<&'a str>>);
impl<'a> EdnKeyMapToCommand<'a> {
/// Construct keymap from source text or fail
pub fn new (keymap: &'a str) -> Usually<Self> {
Ok(Self(EdnItem::<&str>::read_all(keymap)?))
}
/// Try to find a binding matching the currently pressed key
pub fn from <T, C> (&self, state: &T, input: &impl EdnInput) -> Option<C>
where
C: Command<T> + EdnCommand<T>
{
use EdnItem::*;
let mut command: Option<C> = None;
for item in self.0.iter() {
if let Exp(e) = item {
match e.as_slice() {
[Sym(key), c, args @ ..] if input.matches_edn(key) => {
command = C::from_edn(state, c, args);
if command.is_some() {
break
}
},
_ => {}
}
} else {
panic!("invalid config")
}
}
command
}
}
pub struct EdnKeymap<'a>(pub Vec<EdnItem<&'a str>>);
impl<'a> EdnKeymap<'a> {