Add back fish_key_reader --verbose

See #10663
This commit is contained in:
Johannes Altmanninger 2024-08-11 14:39:29 +02:00
parent ba3683cfa5
commit ebd23c9f86
3 changed files with 21 additions and 11 deletions

View File

@ -100,7 +100,7 @@ Deprecations and removed features
This bind mode has been removed. The behavior on paste is currently not meant to be configurable. This bind mode has been removed. The behavior on paste is currently not meant to be configurable.
- When an interactive fish is stopped or terminated by a signal that cannot be caught (SIGSTOP or SIGKILL), it may leave the terminal in a state where keypresses with modifiers are sent as CSI u sequences instead of traditional control characters or escape sequecnes (that are recognized by bash/readline). - When an interactive fish is stopped or terminated by a signal that cannot be caught (SIGSTOP or SIGKILL), it may leave the terminal in a state where keypresses with modifiers are sent as CSI u sequences instead of traditional control characters or escape sequecnes (that are recognized by bash/readline).
If this happens, you can use the ``reset`` command from ``ncurses`` to restore the terminal state. If this happens, you can use the ``reset`` command from ``ncurses`` to restore the terminal state.
- ``fish_key_reader --verbose`` is now ignored, so it no longer shows raw byte values or timing information. - ``fish_key_reader --verbose`` no longer shows timing information.
Raw byte values should no longer be necessary because fish now decodes them to the new human-readable key names for builtin bind. Raw byte values should no longer be necessary because fish now decodes them to the new human-readable key names for builtin bind.
- Instant propagation of universal variables now only works on Linux and macOS. On other platforms, changes to universal variables may only become visible on the next prompt. - Instant propagation of universal variables now only works on Linux and macOS. On other platforms, changes to universal variables may only become visible on the next prompt.

View File

@ -20,7 +20,7 @@ use fish::{
eprintf, fprintf, eprintf, fprintf,
input::input_terminfo_get_name, input::input_terminfo_get_name,
input_common::{terminal_protocols_enable_ifn, CharEvent, InputEventQueue, InputEventQueuer}, input_common::{terminal_protocols_enable_ifn, CharEvent, InputEventQueue, InputEventQueuer},
key::{self, Key}, key::{self, char_to_symbol, Key},
panic::panic_handler, panic::panic_handler,
print_help::print_help, print_help::print_help,
printf, printf,
@ -83,7 +83,7 @@ fn sequence_name(recent_chars: &mut Vec<u8>, c: char) -> Option<WString> {
} }
/// Process the characters we receive as the user presses keys. /// Process the characters we receive as the user presses keys.
fn process_input(continuous_mode: bool) -> i32 { fn process_input(continuous_mode: bool, verbose: bool) -> i32 {
let mut first_char_seen = false; let mut first_char_seen = false;
let mut queue = InputEventQueue::new(STDIN_FILENO); let mut queue = InputEventQueue::new(STDIN_FILENO);
let mut recent_chars1 = vec![]; let mut recent_chars1 = vec![];
@ -101,6 +101,13 @@ fn process_input(continuous_mode: bool) -> i32 {
if c == key::Invalid { if c == key::Invalid {
continue; continue;
} }
if verbose {
printf!("# decoded from: ");
for byte in kevt.seq.chars() {
printf!("%s", &char_to_symbol(byte));
}
printf!("\n");
}
printf!("bind %s 'do something'\n", kevt.key); printf!("bind %s 'do something'\n", kevt.key);
if let Some(name) = sequence_name(&mut recent_chars1, c) { if let Some(name) = sequence_name(&mut recent_chars1, c) {
printf!("bind -k %ls 'do something'\n", name); printf!("bind -k %ls 'do something'\n", name);
@ -117,7 +124,7 @@ fn process_input(continuous_mode: bool) -> i32 {
} }
/// Setup our environment (e.g., tty modes), process key strokes, then reset the environment. /// Setup our environment (e.g., tty modes), process key strokes, then reset the environment.
fn setup_and_process_keys(continuous_mode: bool) -> i32 { fn setup_and_process_keys(continuous_mode: bool, verbose: bool) -> i32 {
set_interactive_session(true); set_interactive_session(true);
topic_monitor_init(); topic_monitor_init();
threads::init(); threads::init();
@ -141,16 +148,16 @@ fn setup_and_process_keys(continuous_mode: bool) -> i32 {
eprintf!("\n"); eprintf!("\n");
} }
process_input(continuous_mode) process_input(continuous_mode, verbose)
} }
fn parse_flags(continuous_mode: &mut bool) -> ControlFlow<i32> { fn parse_flags(continuous_mode: &mut bool, verbose: &mut bool) -> ControlFlow<i32> {
let short_opts: &wstr = L!("+chvV"); let short_opts: &wstr = L!("+chvV");
let long_opts: &[WOption] = &[ let long_opts: &[WOption] = &[
wopt(L!("continuous"), ArgType::NoArgument, 'c'), wopt(L!("continuous"), ArgType::NoArgument, 'c'),
wopt(L!("help"), ArgType::NoArgument, 'h'), wopt(L!("help"), ArgType::NoArgument, 'h'),
wopt(L!("version"), ArgType::NoArgument, 'v'), wopt(L!("version"), ArgType::NoArgument, 'v'),
wopt(L!("verbose"), ArgType::NoArgument, 'V'), // Removed wopt(L!("verbose"), ArgType::NoArgument, 'V'),
]; ];
let args: Vec<WString> = std::env::args_os() let args: Vec<WString> = std::env::args_os()
@ -178,7 +185,9 @@ fn parse_flags(continuous_mode: &mut bool) -> ControlFlow<i32> {
); );
return ControlFlow::Break(0); return ControlFlow::Break(0);
} }
'V' => {} 'V' => {
*verbose = true;
}
'?' => { '?' => {
printf!( printf!(
"%s", "%s",
@ -210,8 +219,9 @@ fn main() {
fn throwing_main() -> i32 { fn throwing_main() -> i32 {
let mut continuous_mode = false; let mut continuous_mode = false;
let mut verbose = false;
if let ControlFlow::Break(i) = parse_flags(&mut continuous_mode) { if let ControlFlow::Break(i) = parse_flags(&mut continuous_mode, &mut verbose) {
return i; return i;
} }
@ -220,5 +230,5 @@ fn throwing_main() -> i32 {
return 1; return 1;
} }
setup_and_process_keys(continuous_mode) setup_and_process_keys(continuous_mode, verbose)
} }

View File

@ -454,7 +454,7 @@ fn ascii_printable_to_symbol(buf: &mut WString, c: char) {
} }
/// Convert a wide-char to a symbol that can be used in our output. /// Convert a wide-char to a symbol that can be used in our output.
pub(crate) fn char_to_symbol(c: char) -> WString { pub fn char_to_symbol(c: char) -> WString {
let mut buff = WString::new(); let mut buff = WString::new();
let buf = &mut buff; let buf = &mut buff;
if c <= ' ' { if c <= ' ' {