From b8e280add686caa0fa773253c7dcc88531459025 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 13 Aug 2024 22:08:25 +0200 Subject: [PATCH] Clean up fish_key_reader rendering code --- src/key.rs | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/key.rs b/src/key.rs index 086f5e869..115ad0a15 100644 --- a/src/key.rs +++ b/src/key.rs @@ -418,25 +418,16 @@ fn ctrl_to_symbol(buf: &mut WString, c: char) { // 2. key names that are given as raw escape sequence (\e123); those we want to display // similar to how they are given. - let ctrl_symbolic_names: [&wstr; 29] = { - std::array::from_fn(|i| match i { - 8 => L!("\\b"), - 9 => L!("\\t"), - 10 => L!("\\n"), - 13 => L!("\\r"), - 27 => L!("\\e"), - _ => L!(""), - }) - }; - let c = u8::try_from(c).unwrap(); - let cu = usize::from(c); - - if !ctrl_symbolic_names[cu].is_empty() { - sprintf!(=> buf, "%s", ctrl_symbolic_names[cu]); - } else { - sprintf!(=> buf, "\\x%02x", c); - } + let symbolic_name = match c { + 8 => L!("\\b"), + 9 => L!("\\t"), + 10 => L!("\\n"), + 13 => L!("\\r"), + 27 => L!("\\e"), + _ => return sprintf!(=> buf, "\\x%02x", c), + }; + buf.push_utfstr(symbolic_name); } /// Return true if the character must be escaped when used in the sequence of chars to be bound in @@ -457,11 +448,8 @@ fn ascii_printable_to_symbol(buf: &mut WString, c: char) { pub fn char_to_symbol(c: char) -> WString { let mut buff = WString::new(); let buf = &mut buff; - if c <= ' ' { + if c <= ' ' || c == '\x7F' { ctrl_to_symbol(buf, c); - } else if c == '\u{7f}' { - // DEL is at the end of the ASCII range - sprintf!(=> buf, "\\x%02x", 0x7f); } else if c < '\u{80}' { // ASCII characters that are not control characters ascii_printable_to_symbol(buf, c);