kbd-crossterm 0.1.0

crossterm bridge for kbd — converts crossterm key events and modifiers to kbd types.
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented4 out of 7 items with examples
  • Size
  • Source code size: 48.36 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.31 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 27s Average build duration of successful builds.
  • all releases: 27s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • joshuadavidthomas/kbd
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • joshuadavidthomas

kbd-crossterm

crates.io docs.rs

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.

[dependencies]
kbd = "0.1"
kbd-crossterm = "0.1"

Extension traits

  • CrosstermKeyExt — converts a crossterm::event::KeyCode to a kbd::Key
  • CrosstermModifiersExt — converts crossterm::event::KeyModifiers to a Vec<Modifier>
  • CrosstermEventExt — converts a full crossterm::event::KeyEvent to a kbd::Hotkey

Usage

use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use kbd::prelude::*;
use kbd_crossterm::{CrosstermEventExt, CrosstermKeyExt, CrosstermModifiersExt};

// Single key conversion
let key = KeyCode::Char('a').to_key();
assert_eq!(key, Some(Key::A));

// Modifier conversion
let mods = KeyModifiers::CONTROL.to_modifiers();
assert_eq!(mods, vec![Modifier::Ctrl]);

// Full event conversion
let event = KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL);
let hotkey = event.to_hotkey();
assert_eq!(hotkey, Some(Hotkey::new(Key::C).modifier(Modifier::Ctrl)));

Key mapping

Crossterm kbd Notes
Char('a')Char('z') Key::AKey::Z Case-insensitive
Char('0')Char('9') Key::DIGIT0Key::DIGIT9
Char('-'), Char('='), … Key::MINUS, Key::EQUAL, … Physical position
F(1)F(35) Key::F1Key::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.