From 53ea6db72d880c1489ab8ecc398ab8de88c01b35 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 13 Aug 2024 22:09:06 +0200 Subject: [PATCH] Show un-decodable inputs as bytes instead of the internal encoding When the input is invalid UTF8, we re-encode the raw bytes using the private use area. Let's make sure we convert back before printing. --- src/key.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/key.rs b/src/key.rs index 115ad0a15..7634f1485 100644 --- a/src/key.rs +++ b/src/key.rs @@ -4,7 +4,7 @@ use crate::{ common::{escape_string, EscapeFlags, EscapeStringStyle}, fallback::fish_wcwidth, reader::TERMINAL_MODE_ON_STARTUP, - wchar::prelude::*, + wchar::{decode_byte_from_char, prelude::*}, wutil::{fish_is_pua, fish_wcstoi}, }; @@ -453,6 +453,8 @@ pub fn char_to_symbol(c: char) -> WString { } else if c < '\u{80}' { // ASCII characters that are not control characters ascii_printable_to_symbol(buf, c); + } else if let Some(byte) = decode_byte_from_char(c) { + sprintf!(=> buf, "\\x%02x", byte); } else if ('\u{e000}'..='\u{f8ff}').contains(&c) { // Unmapped key from https://sw.kovidgoyal.net/kitty/keyboard-protocol/#functional-key-definitions sprintf!(=> buf, "\\u%04X", u32::from(c));