Do not insert key's PUA encoding into the command line

If a key's codepoint is in the PUA1 range, it could
be either from our own named keys (like key::Space)
or from a CSI u key that we haven't assigned a name yet
https://sw.kovidgoyal.net/kitty/keyboard-protocol/#functional-key-definitions
(The latter can still be bound using the \u1234 or the equivalent \e[4660u
raw CSI u sequence.)

It doesn't make sense to insert a PUA character into the commandline when
the user presses PrintScreen; ignore them silently.

This partially reverts b77d1d0e2 (Stop crashing on invalid Unicode input,
2024-02-27). That commit did:
1. convert input byte sequences that map to a PUA codepoint into several
   characters, using our on-char-per-byte PUA encoding.
2. do the same for inputs that are codepoints outside the valid Unicode range.
3. render them as replacement character (one per input byte)

In future, we should probably remove these features altogether, and simply
ignore invalid Unicode code points.
This commit is contained in:
Johannes Altmanninger 2024-04-09 00:33:02 +02:00
parent a583fe7230
commit adb40149a3
2 changed files with 7 additions and 7 deletions

View File

@ -1,10 +1,12 @@
use std::ops;
use std::rc::Rc;
use libc::VERASE;
use crate::{
fallback::fish_wcwidth, reader::TERMINAL_MODE_ON_STARTUP, wchar::prelude::*, wutil::fish_wcstoi,
fallback::fish_wcwidth,
reader::TERMINAL_MODE_ON_STARTUP,
wchar::prelude::*,
wutil::{fish_is_pua, fish_wcstoi},
};
pub(crate) const Backspace: char = '\u{F500}'; // below ENCODE_DIRECT_BASE
@ -28,8 +30,6 @@ pub(crate) fn function_key(n: u32) -> char {
char::from_u32(u32::from(Invalid) + n).unwrap()
}
const NAMED_KEYS_RANGE: ops::Range<u32> = 0xF500..(Invalid as u32 + 12);
const KEY_NAMES: &[(char, &wstr)] = &[
('+', L!("plus")),
('-', L!("minus")),
@ -212,7 +212,7 @@ pub(crate) fn canonicalize_key(mut key: Key) -> Result<Key, WString> {
// Shift + ASCII letters is just the uppercase letter.
key.modifiers.shift = false;
key.codepoint = key.codepoint.to_ascii_uppercase();
} else if !NAMED_KEYS_RANGE.contains(&u32::from(key.codepoint)) {
} else if !fish_is_pua(key.codepoint) {
// Shift + any other printable character is not allowed.
return Err(wgettext_fmt!(
"Shift modifier is only supported on special keys and lowercase ASCII, not '%s'",
@ -351,7 +351,7 @@ impl Key {
if c == Tab {
return Some('\t');
}
if NAMED_KEYS_RANGE.contains(&u32::from(c)) || u32::from(c) <= 27 {
if fish_is_pua(c) || u32::from(c) <= 27 {
return None;
}
Some(c)

View File

@ -478,7 +478,7 @@ const PUA1_END: char = '\u{F900}';
// const PUA3_END: char = '\u{10FFFE}';
/// Return one if the code point is in a Unicode private use area.
fn fish_is_pua(c: char) -> bool {
pub(crate) fn fish_is_pua(c: char) -> bool {
PUA1_START <= c && c < PUA1_END
}