mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
even wackier focus logic
This commit is contained in:
parent
ce1c28edb9
commit
f5d02f9f08
3 changed files with 206 additions and 135 deletions
|
|
@ -90,20 +90,22 @@ pub type BoxedProcessHandler = Box<dyn FnMut(&Client, &ProcessScope)-> Control +
|
|||
|
||||
pub type Jack<N> = AsyncClient<N, ClosureProcessHandler<BoxedProcessHandler>>;
|
||||
|
||||
pub type KeyHandler<T> = &'static dyn Fn(&mut T)->Usually<bool>;
|
||||
|
||||
pub type KeyBinding<T> = (
|
||||
KeyCode, KeyModifiers, &'static str, &'static str, &'static dyn Fn(&mut T)
|
||||
KeyCode, KeyModifiers, &'static str, &'static str, KeyHandler<T>
|
||||
);
|
||||
|
||||
#[macro_export] macro_rules! key {
|
||||
($k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: ident) => {
|
||||
($k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: expr) => {
|
||||
(KeyCode::$k $(($char))?, KeyModifiers::$m, $n, $d, &$f)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! keymap {
|
||||
($T:ty { $([$k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: ident]),* }) => {
|
||||
($T:ty { $([$k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: expr]),* }) => {
|
||||
&[
|
||||
$((KeyCode::$k $(($char))?, KeyModifiers::$m, $n, $d, &$f as &'static dyn Fn(&mut $T))),*
|
||||
$((KeyCode::$k $(($char))?, KeyModifiers::$m, $n, $d, &$f as KeyHandler<$T>)),*
|
||||
] as &'static [KeyBinding<$T>]
|
||||
}
|
||||
}
|
||||
|
|
@ -111,11 +113,11 @@ pub type KeyBinding<T> = (
|
|||
pub use crate::{key, keymap};
|
||||
|
||||
pub fn handle_keymap <T> (
|
||||
commands: &[KeyBinding<T>], state: &mut T, event: &AppEvent
|
||||
) -> Result<bool, Box<dyn Error>> {
|
||||
state: &mut T, event: &AppEvent, keymap: &[KeyBinding<T>],
|
||||
) -> Usually<bool> {
|
||||
match event {
|
||||
AppEvent::Input(Event::Key(event)) => {
|
||||
for (code, modifiers, _, _, command) in commands.iter() {
|
||||
for (code, modifiers, _, _, command) in keymap.iter() {
|
||||
if *code == event.code && modifiers.bits() == event.modifiers.bits() {
|
||||
command(state);
|
||||
return Ok(true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue