pub fn parse_key_string(s: &str) -> KeyPressExpand description
Parses string representations of keys into KeyPress instances.
This function converts human-readable key descriptions into structured KeyPress objects. It supports a wide variety of key formats and combinations.
§Supported Formats
§Simple Keys
- Arrow keys: “up”, “down”, “left”, “right”
- Special keys: “enter”, “tab”, “esc”/“escape”, “space”, “backspace”
- Navigation: “home”, “end”, “pgup”/“pageup”, “pgdown”/“pagedown”/“pgdn”
- Function keys: “f1” through “f12”
- Characters: “a”, “1”, “?”, “/”, etc.
§Modifier Combinations
- Single modifier: “ctrl+c”, “alt+f4”, “shift+tab”
- Double modifiers: “ctrl+alt+a”, “ctrl+shift+s”
§Arguments
s- The string representation of the key
§Returns
A KeyPress representing the parsed key combination. Unknown keys
result in KeyCode::Null.
§Examples
use bubbletea_widgets::key::parse_key_string;
use crossterm::event::{KeyCode, KeyModifiers};
let enter = parse_key_string("enter");
let ctrl_c = parse_key_string("ctrl+c");
let alt_f4 = parse_key_string("alt+f4");
let complex = parse_key_string("ctrl+alt+a");
assert_eq!(enter.code, KeyCode::Enter);
assert_eq!(ctrl_c.code, KeyCode::Char('c'));
assert_eq!(ctrl_c.mods, KeyModifiers::CONTROL);§Panics
This function does not panic. Invalid or unknown key combinations will
result in a KeyPress with KeyCode::Null.