mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-25 09:39:52 +08:00
Fix fish_key_reader --verbose output
This commit is contained in:
parent
e3196446fa
commit
423e5f6c03
|
@ -20,7 +20,7 @@ use fish::{
|
|||
eprintf, fprintf,
|
||||
input::input_terminfo_get_name,
|
||||
input_common::{terminal_protocols_enable_ifn, CharEvent, InputEventQueue, InputEventQueuer},
|
||||
key::{self, char_to_symbol, Key},
|
||||
key::{self, byte_to_symbol, Key},
|
||||
panic::panic_handler,
|
||||
print_help::print_help,
|
||||
printf,
|
||||
|
@ -104,7 +104,7 @@ fn process_input(continuous_mode: bool, verbose: bool) -> i32 {
|
|||
if verbose {
|
||||
printf!("# decoded from: ");
|
||||
for byte in kevt.seq.chars() {
|
||||
printf!("%s", &char_to_symbol(byte));
|
||||
printf!("%s", &byte_to_symbol(byte));
|
||||
}
|
||||
printf!("\n");
|
||||
}
|
||||
|
|
21
src/key.rs
21
src/key.rs
|
@ -418,7 +418,7 @@ 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] = {
|
||||
let ctrl_symbolic_names: [&wstr; 28] = {
|
||||
std::array::from_fn(|i| match i {
|
||||
8 => L!("\\b"),
|
||||
9 => L!("\\t"),
|
||||
|
@ -453,15 +453,26 @@ fn ascii_printable_to_symbol(buf: &mut WString, c: char) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn byte_to_symbol(c: char) -> WString {
|
||||
let mut buff = WString::new();
|
||||
let buf = &mut buff;
|
||||
if c <= '\x1b' {
|
||||
ctrl_to_symbol(buf, c);
|
||||
} else if ('\u{30}'..'\u{7f}').contains(&c) {
|
||||
// ASCII characters that are not control characters
|
||||
ascii_printable_to_symbol(buf, c);
|
||||
} else {
|
||||
sprintf!(=> buf, "\\x%02x", 0x7f);
|
||||
}
|
||||
buff
|
||||
}
|
||||
|
||||
/// Convert a wide-char to a symbol that can be used in our output.
|
||||
pub fn char_to_symbol(c: char) -> WString {
|
||||
pub(crate) fn char_to_symbol(c: char) -> WString {
|
||||
let mut buff = WString::new();
|
||||
let buf = &mut buff;
|
||||
if c <= ' ' {
|
||||
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 New Issue
Block a user