mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Clean up fish_key_reader rendering code
This commit is contained in:
parent
da8fe7e845
commit
b8e280add6
1 changed files with 10 additions and 22 deletions
32
src/key.rs
32
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);
|
||||
|
|
Loading…
Reference in a new issue