Clean up fish_key_reader rendering code

This commit is contained in:
Johannes Altmanninger 2024-08-13 22:08:25 +02:00
parent da8fe7e845
commit b8e280add6

View file

@ -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 {
let c = u8::try_from(c).unwrap();
let symbolic_name = match c {
8 => L!("\\b"),
9 => L!("\\t"),
10 => L!("\\n"),
13 => L!("\\r"),
27 => L!("\\e"),
_ => L!(""),
})
_ => return sprintf!(=> buf, "\\x%02x", c),
};
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);
}
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);