mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
wip: let's figure out how edn keymaps will work
This commit is contained in:
parent
4ab08e48e5
commit
794d4210c6
33 changed files with 161 additions and 85 deletions
|
|
@ -0,0 +1,46 @@
|
|||
use crate::*;
|
||||
impl EdnInput for TuiIn {
|
||||
fn matches (&self, token: &str) -> bool {
|
||||
false
|
||||
}
|
||||
fn get_event <S: AsRef<str>> (item: &EdnItem<S>) -> Option<Event> {
|
||||
match item { EdnItem::Sym(s) => parse_key_spec(s.as_ref().to_string(), KeyModifiers::NONE), _ => None }
|
||||
}
|
||||
}
|
||||
fn parse_key_spec (spec: String, mut mods: KeyModifiers) -> Option<Event> {
|
||||
Some(Event::Key(match spec.as_str() {
|
||||
":enter" | ":return" => KeyEvent::new(KeyCode::Enter, mods),
|
||||
":delete" | ":del" => KeyEvent::new(KeyCode::Enter, mods),
|
||||
|
||||
":comma" => KeyEvent::new(KeyCode::Char(','), mods),
|
||||
":period" => KeyEvent::new(KeyCode::Char('.'), mods),
|
||||
|
||||
":plus" => KeyEvent::new(KeyCode::Char('+'), mods),
|
||||
":underscore" => KeyEvent::new(KeyCode::Char('_'), mods),
|
||||
|
||||
":up" => KeyEvent::new(KeyCode::Up, mods),
|
||||
":down" => KeyEvent::new(KeyCode::Down, mods),
|
||||
":left" => KeyEvent::new(KeyCode::Left, mods),
|
||||
":right" => KeyEvent::new(KeyCode::Right, mods),
|
||||
|
||||
_ => {
|
||||
let chars = spec.chars().collect::<Vec<_>>();
|
||||
match chars.as_slice() {
|
||||
[':', c] => KeyEvent::new(KeyCode::Char(*c), mods),
|
||||
[':', c @ ..] => {
|
||||
let mut splits = c.split(|c|*c=='-');
|
||||
while let Some(split) = splits.next() {
|
||||
match split {
|
||||
['c','t','r','l'] => mods |= KeyModifiers::CONTROL,
|
||||
['a','l','t'] => mods |= KeyModifiers::ALT,
|
||||
['s','h','i','f','t'] => mods |= KeyModifiers::SHIFT,
|
||||
_ => return parse_key_spec(split.iter().collect(), mods)
|
||||
}
|
||||
}
|
||||
panic!("invalid key event {spec:?}")
|
||||
}
|
||||
_ => panic!("invalid key event {spec:?}")
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue