Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom shortcuts/keybindings/hotkeys support #285

Open
Andrew15-5 opened this issue Sep 29, 2023 · 3 comments
Open

Custom shortcuts/keybindings/hotkeys support #285

Andrew15-5 opened this issue Sep 29, 2023 · 3 comments

Comments

@Andrew15-5
Copy link

I'm new to Rust, but after using inquirerpy for some time, I now assume that every CLI prompter allows custom keybinding/shortcuts/hotkeys. But now I know that this assumption is wrong. Why? Why I can't define custom shortcuts?

I like to use Ctrl + k and Ctrl + j to go up and down when selecting something. Specifically, when using FuzzySelect. I can first insert text to filter options and then use Ctrl + j to quickly select option if it is not the first in the list. I can use Tab, but this is not the point.

@pksunkara
Copy link
Collaborator

Why? Why I can't define custom shortcuts?

Because nobody needed it until you and therefore nobody contributed it. Please feel free to contribute.

@Andrew15-5
Copy link
Author

Huh, is that so? 6 years and I'm the first one, hmm.

I would love to contribute, but I need to gain some experience first.

@Andrew15-5
Copy link
Author

I tried doing what was said here: console-rs/console#125 (comment).

diff --git a/src/prompts/fuzzy_select.rs b/src/prompts/fuzzy_select.rs
index 9f06798..894561e 100644
--- a/src/prompts/fuzzy_select.rs
+++ b/src/prompts/fuzzy_select.rs
@@ -280,7 +280,7 @@ impl FuzzySelect<'_> {
                 (Key::Char('i' | 'a'), _, true) => {
                     vim_mode = false;
                 }
-                (Key::ArrowUp | Key::BackTab, _, _) | (Key::Char('k'), _, true)
+                (Key::ArrowUp | Key::BackTab | Key::Char('\u{b}'), _, _) | (Key::Char('k'), _, true)
                     if !filtered_list.is_empty() =>
                 {
                     if sel == Some(0) {
@@ -299,7 +299,7 @@ impl FuzzySelect<'_> {
                     };
                     term.flush()?;
                 }
-                (Key::ArrowDown | Key::Tab, _, _) | (Key::Char('j'), _, true)
+                (Key::ArrowDown | Key::Tab | Key::Enter, _, _) | (Key::Char('j'), _, true)
                     if !filtered_list.is_empty() =>
                 {
                     sel = match sel {

The problem is not only that Ctrl doesn't work and Ctrl+J is actually registered (at least by the console library) as Enter (which means I can't confirm my selection), but that modifiers are not supported (natively): console-rs/console#125.

https://www.physics.udel.edu/~watson/scen103/ascii.html:

image

So with that issue being opened, there is no sane way of adding shortcut support to the dialoguer (just noticed that both projects are under the same owner).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants