kbd-crossterm
kbd bridge for crossterm — converts key events and modifiers to kbd types.
This lets you use kbd's Dispatcher, hotkey parsing, layers, and sequences in a TUI app.
Crossterm reports keys as characters (Char('a')) and modifier bitflags, while kbd uses physical key positions (Key::A) and typed Modifier values.
[]
= "0.1"
= "0.1"
Extension traits
CrosstermKeyExt— converts acrossterm::event::KeyCodeto akbd::KeyCrosstermModifiersExt— convertscrossterm::event::KeyModifiersto aVec<Modifier>CrosstermEventExt— converts a fullcrossterm::event::KeyEventto akbd::Hotkey
Usage
use ;
use *;
use ;
// Single key conversion
let key = Char.to_key;
assert_eq!;
// Modifier conversion
let mods = CONTROL.to_modifiers;
assert_eq!;
// Full event conversion
let event = new;
let hotkey = event.to_hotkey;
assert_eq!;
Key mapping
| Crossterm | kbd | Notes |
|---|---|---|
Char('a') – Char('z') |
Key::A – Key::Z |
Case-insensitive |
Char('0') – Char('9') |
Key::DIGIT0 – Key::DIGIT9 |
|
Char('-'), Char('='), … |
Key::MINUS, Key::EQUAL, … |
Physical position |
F(1) – F(35) |
Key::F1 – Key::F35 |
F(0) and F(36+) → None |
Enter, Esc, Tab, … |
Key::ENTER, Key::ESCAPE, Key::TAB, … |
Named keys |
Media(PlayPause), … |
Key::MEDIA_PLAY_PAUSE, … |
Media keys |
Modifier(LeftControl), … |
Key::CONTROL_LEFT, … |
Modifier keys as triggers |
BackTab, Null, KeypadBegin |
None |
No kbd equivalent |
Non-ASCII Char (e.g., 'é') |
None |
No physical key mapping |
Modifier mapping
| Crossterm | kbd |
|---|---|
CONTROL |
Modifier::Ctrl |
SHIFT |
Modifier::Shift |
ALT |
Modifier::Alt |
SUPER |
Modifier::Super |
HYPER, META |
(ignored) |
License
kbd-crossterm is licensed under the MIT license. See the LICENSE file for more information.