From 3349ef0dca19b9b0572a55859ae5c3dd9aa42be5 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 16 May 2020 17:07:27 -0700 Subject: [PATCH] termwiz: fix categorization of F keys refs: https://github.com/wez/wezterm/issues/178 --- termwiz/src/input.rs | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/termwiz/src/input.rs b/termwiz/src/input.rs index f7dfd0320..385a74341 100644 --- a/termwiz/src/input.rs +++ b/termwiz/src/input.rs @@ -650,20 +650,53 @@ impl InputParser { ); } - // Function keys with modifiers encoded using CSI - for n in 1..=12 { + // Function keys 1-4 with modifiers + for (keycode, c) in &[ + (KeyCode::Function(1), b'P'), + (KeyCode::Function(2), b'Q'), + (KeyCode::Function(3), b'R'), + (KeyCode::Function(4), b'S'), + ] { for (suffix, modifiers) in modifier_combos_including_meta() { - let key = format!("\x1b[{code}{suffix}~", code = n + 10, suffix = suffix); + let key = format!("\x1b[1{suffix}{code}", code = *c as char, suffix = suffix); map.insert( key, InputEvent::Key(KeyEvent { - key: KeyCode::Function(n), + key: *keycode, modifiers: *modifiers, }), ); } } + // Function keys with modifiers encoded using CSI. + // http://aperiodic.net/phil/archives/Geekery/term-function-keys.html + for (range, offset) in &[ + // F1-F5 encoded as 11-15 + (1..=5, 10), + // F6-F10 encoded as 17-21 + (6..=10, 11), + // F11-F14 encoded as 23-26 + (11..=14, 12), + // F15-F16 encoded as 28-29 + (15..=16, 13), + // F17-F20 encoded as 31-34 + (17..=20, 14), + ] { + for n in range.clone() { + for (suffix, modifiers) in modifier_combos_including_meta() { + let key = format!("\x1b[{code}{suffix}~", code = n + offset, suffix = suffix); + map.insert( + key, + InputEvent::Key(KeyEvent { + key: KeyCode::Function(n), + modifiers: *modifiers, + }), + ); + } + } + } + for (keycode, c) in &[ (KeyCode::Insert, b'2'), (KeyCode::Delete, b'3'),