MCPcopy Create free account
hub / github.com/Canop/crokey / parse_key_code

Function parse_key_code

src/parse.rs:38–96  ·  view source on GitHub ↗
(raw: &str, shift: bool)

Source from the content-addressed store, hash-verified

36impl std::error::Error for ParseKeyError {}
37
38pub fn parse_key_code(raw: &str, shift: bool) -> Result<KeyCode, ParseKeyError> {
39 let code = match raw {
40 "esc" => Esc,
41 "enter" => Enter,
42 "left" => Left,
43 "right" => Right,
44 "up" => Up,
45 "down" => Down,
46 "home" => Home,
47 "end" => End,
48 "pageup" => PageUp,
49 "pagedown" => PageDown,
50 "backtab" => BackTab,
51 "backspace" => Backspace,
52 "del" => Delete,
53 "delete" => Delete,
54 "insert" => Insert,
55 "ins" => Insert,
56 "f1" => F(1),
57 "f2" => F(2),
58 "f3" => F(3),
59 "f4" => F(4),
60 "f5" => F(5),
61 "f6" => F(6),
62 "f7" => F(7),
63 "f8" => F(8),
64 "f9" => F(9),
65 "f10" => F(10),
66 "f11" => F(11),
67 "f12" => F(12),
68 "f13" => F(13),
69 "f14" => F(14),
70 "f15" => F(15),
71 "f16" => F(16),
72 "f17" => F(17),
73 "f18" => F(18),
74 "f19" => F(19),
75 "f20" => F(20),
76 "f21" => F(21),
77 "f22" => F(22),
78 "f23" => F(23),
79 "f24" => F(24),
80 "space" => Char(' '),
81 "hyphen" => Char('-'),
82 "minus" => Char('-'),
83 "tab" => Tab,
84 c if c.len() == 1 => {
85 let mut c = c.chars().next().unwrap();
86 if shift {
87 c = c.to_ascii_uppercase();
88 }
89 Char(c)
90 }
91 _ => {
92 return Err(ParseKeyError::new(raw));
93 }
94 };
95 Ok(code)

Callers 1

parseFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected