MCPcopy Create free account
hub / github.com/JayanAXHF/modder-rs / parse_key_code_with_modifiers

Function parse_key_code_with_modifiers

tui/src/config.rs:182–230  ·  view source on GitHub ↗
(
    raw: &str,
    mut modifiers: KeyModifiers,
)

Source from the content-addressed store, hash-verified

180}
181
182fn parse_key_code_with_modifiers(
183 raw: &str,
184 mut modifiers: KeyModifiers,
185) -> Result<KeyEvent, String> {
186 let c = match raw {
187 "esc" => KeyCode::Esc,
188 "enter" => KeyCode::Enter,
189 "left" => KeyCode::Left,
190 "right" => KeyCode::Right,
191 "up" => KeyCode::Up,
192 "down" => KeyCode::Down,
193 "home" => KeyCode::Home,
194 "end" => KeyCode::End,
195 "pageup" => KeyCode::PageUp,
196 "pagedown" => KeyCode::PageDown,
197 "backtab" => {
198 modifiers.insert(KeyModifiers::SHIFT);
199 KeyCode::BackTab
200 }
201 "backspace" => KeyCode::Backspace,
202 "delete" => KeyCode::Delete,
203 "insert" => KeyCode::Insert,
204 "f1" => KeyCode::F(1),
205 "f2" => KeyCode::F(2),
206 "f3" => KeyCode::F(3),
207 "f4" => KeyCode::F(4),
208 "f5" => KeyCode::F(5),
209 "f6" => KeyCode::F(6),
210 "f7" => KeyCode::F(7),
211 "f8" => KeyCode::F(8),
212 "f9" => KeyCode::F(9),
213 "f10" => KeyCode::F(10),
214 "f11" => KeyCode::F(11),
215 "f12" => KeyCode::F(12),
216 "space" => KeyCode::Char(' '),
217 "hyphen" => KeyCode::Char('-'),
218 "minus" => KeyCode::Char('-'),
219 "tab" => KeyCode::Tab,
220 c if c.len() == 1 => {
221 let mut c = c.chars().next().unwrap();
222 if modifiers.contains(KeyModifiers::SHIFT) {
223 c = c.to_ascii_uppercase();
224 }
225 KeyCode::Char(c)
226 }
227 _ => return Err(format!("Unable to parse {raw}")),
228 };
229 Ok(KeyEvent::new(c, modifiers))
230}
231
232pub fn key_event_to_string(key_event: &KeyEvent) -> String {
233 let char;

Callers 1

parse_key_eventFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected