summaryrefslogtreecommitdiffstats
path: root/src/keys.rs
blob: 4583ac44ff5d1efb31b30414300a8eaa6d2ba42e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use {
    crate::{
        app::Mode,
    },
    crokey::*,
    crossterm::event::{
        KeyCode,
        KeyEvent,
        KeyModifiers,
    },
    once_cell::sync::Lazy,
};

pub static KEY_FORMAT: Lazy<KeyEventFormat> = Lazy::new(|| {
    KeyEventFormat::default().with_lowercase_modifiers()
});

pub fn is_reserved(key: KeyEvent) -> bool {
    key == BACKSPACE || key == DELETE || key == ESC
}

pub fn is_key_allowed_for_verb(
    key: KeyEvent,
    mode: Mode,
    input_is_empty: bool,
) -> bool {
    match mode {
        Mode::Input => {
            // in input mode, keys normally used in the input are forbidden
            if key==LEFT || key==RIGHT {
                input_is_empty
            } else {
                !matches!(key, KeyEvent { code: KeyCode::Char(_), modifiers: KeyModifiers::NONE })
            }
        }
        Mode::Command => true,
    }
}