Repository navigation
Allow ESC to be binded to custom action, when not in tab complete, at least when nothing being inputed #990
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Activity
It seems to work in nushell. I've had this set as a keybinding for a very long time. ESC clears the command line buffer.
{ name: clear modifier: none keycode: esc mode: [emacs vi_normal vi_insert] event: { edit: clear } }i use something like what follows, ESC key works with my custom host command. But, when i use tab complete, and after the menu show up, i cannot use ESC key to cancel the completion menu. I don't want my ESC keybinding to override its default behavior in completion menu.
... keybindings.add_binding(KeyModifiers::NONE, KeyCode::Esc, ReedlineEvent::ExecuteHostCommand("esc".to_string())); ... let engine = match history_result { Ok(history) => Reedline::create().use_bracketed_paste(true) .with_completer(Box::new(CombinedCompleter::new(CCompleter::new(rfm_functions, None)))) .with_menu(ReedlineMenu::EngineCompleter(completion_menu)) .with_history(Box::new(history)) .with_validator(Box::new(AlwaysIncompleteValidator)) .with_edit_mode(Box::new(Emacs::new(keybindings))) .with_quick_completions(true) .with_hinter(Box::new(CwdAwareHinter::default().with_style(Style::new().italic().\ fg(Color::LightGray)).with_min_chars(2))), Err(e) => { warn!("History load error: {}", e); Reedline::create().with_completer(Box::new(CombinedCompleter::new(CCompleter::new(rfm_functions, None)))) .with_menu(ReedlineMenu::EngineCompleter(completion_menu)) .with_validator(Box::new(AlwaysIncompleteValidator)) .with_edit_mode(Box::new(Emacs::new(keybindings))) .with_quick_completions(true) } };i solved this issue by customize nushell/reedline:
https://gitee.com/guyuming76/reedline/commit/68ef690146fc680cf2294ec2a9249a34dddcf805
I need to customize because i use UntilFound as follows, but code in engine.rs always return "handled", and my code never get executed.
keybindings.add_binding(KeyModifiers::NONE, KeyCode::Esc, ReedlineEvent::UntilFound(vec![ReedlineEvent::Esc, ReedlineEvent::ExecuteHostCommand("esc".to_string())]));
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
I am using reedline in my rfm file manager, to let user manipulate files shown in GUI with commands in terminal emulator. But i cannot keybind ESC to my custom code, it's said that ESC is used by reedline. I see that when i use tab completion and menu, ESC can cancel the menu. But at least when i start a new readline call and nothing has being inputted, i see nothing happens with ESC. I just need ESC for my custom action here: I want to use ESC to cancel the file selection in file manager GUI. Without this, i have to switch focus to the GUI window, ESC to cancel file selection and switch focus back. Currently, i am using ALT+E keybinding as an alternative, but it's not easy to remember as ESC.