From 109ef888313dbfac846850f6b046fa4053a92219 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 1 Jan 2025 21:32:40 +0100 Subject: [PATCH] Add menu and printscreen keys These aren't typically used in the terminal but they are present on many keyboards. Also reorganize the named key constants a bit. Between F500 and ENCODE_DIRECT_BASE (F600) we have space for 256 named keys. --- share/completions/bind.fish | 2 +- src/input_common.rs | 2 ++ src/key.rs | 18 +++++++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/share/completions/bind.fish b/share/completions/bind.fish index 9f62e36d8..8699a1946 100644 --- a/share/completions/bind.fish +++ b/share/completions/bind.fish @@ -72,7 +72,7 @@ function __fish_bind_complete printf '%sshift-\tShift modifier…\n' $prefix set -l key_names minus comma backspace delete escape \ enter up down left right pageup pagedown home end insert tab \ - space f(seq 12) + space menu printscreen f(seq 12) printf '%s\tNamed key\n' $prefix$key_names end end diff --git a/src/input_common.rs b/src/input_common.rs index b9c4ba958..ed05959c8 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -1114,6 +1114,8 @@ fn parse_csi(&mut self, buffer: &mut Vec) -> Option { // Treat numpad keys the same as their non-numpad counterparts. Could add a numpad modifier here. let key = match params[0][0] { + 57361 => key::PrintScreen, + 57363 => key::Menu, 57399 => '0', 57400 => '1', 57401 => '2', diff --git a/src/key.rs b/src/key.rs index 93104773b..22ef27243 100644 --- a/src/key.rs +++ b/src/key.rs @@ -19,16 +19,18 @@ pub(crate) const Right: char = '\u{F507}'; pub(crate) const PageUp: char = '\u{F508}'; pub(crate) const PageDown: char = '\u{F509}'; -pub(crate) const Home: char = '\u{F50a}'; -pub(crate) const End: char = '\u{F50b}'; -pub(crate) const Insert: char = '\u{F50c}'; -pub(crate) const Tab: char = '\u{F50d}'; -pub(crate) const Space: char = '\u{F50e}'; -pub(crate) const Invalid: char = '\u{F50f}'; +pub(crate) const Home: char = '\u{F50A}'; +pub(crate) const End: char = '\u{F50B}'; +pub(crate) const Insert: char = '\u{F50C}'; +pub(crate) const Tab: char = '\u{F50D}'; +pub(crate) const Space: char = '\u{F50E}'; +pub(crate) const Menu: char = '\u{F50F}'; +pub(crate) const PrintScreen: char = '\u{F510}'; pub(crate) fn function_key(n: u32) -> char { assert!((1..=12).contains(&n)); - char::from_u32(u32::from(Invalid) + n).unwrap() + char::from_u32(u32::from('\u{F5FF}') - n).unwrap() } +pub(crate) const Invalid: char = '\u{F5FF}'; const KEY_NAMES: &[(char, &wstr)] = &[ ('-', L!("minus")), @@ -48,6 +50,8 @@ pub(crate) fn function_key(n: u32) -> char { (Insert, L!("insert")), (Tab, L!("tab")), (Space, L!("space")), + (Menu, L!("menu")), + (PrintScreen, L!("printscreen")), ]; #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]