chrisant996 / clink

Bash's powerful command line editing in cmd.exe
https://chrisant996.github.io/clink/
GNU General Public License v3.0
3.44k stars 135 forks source link

Request: Add settings to configure clink-select-complete menu behavior #634

Closed fiso64 closed 1 month ago

fiso64 commented 1 month ago

I propose 3 new settings to configure the completion menu (clink-select-complete). I often find myself opening it when I don't exactly remember what I need to type (like the name of some obscure command line option). These settings would it make it more useful in this context:

  1. Completion preview: 'on' (default) or 'off'. When it is on, the currently selected item will be shown on the line, like it already does by default. The 'missing' part of the item will have an orange background (at least that's how it is displayed in my case). When off, no orange previews will be shown. This is useful when typing something that isn't a prefix of any of the available completions. Currently when I type *hello and there is an item that contains 'hello' but does not start with it, then I can't see what I typed anymore because the orange preview is displayed instead.
  2. Insert on space: 'true' (default) or 'false'. Whether the selected item should be inserted when space is pressed. If completion preview is off, it would make more sense for this to be false. The menu should still be closed when space is pressed, and enter would still insert the selected item.
  3. Auto close when no match: 'true' (default) or 'false'. When true, the menu will automatically close if no completions match the typed string (like it already does). When false, the menu will be empty if no items match the string and will be repopulated when the the string is modified.
chrisant996 commented 1 month ago

The combination of those suggestions sounds like what you really want is fzf and clink-fzf. The suggestions are basically trying to turn clink-select-complete into a very different kind of feature that instead behaves like fzf.

Have you considered using fzf? If yes, can you describe why you don't want to use fzf?




There are many reasons why the suggestions are problematic, and would completely redesign how the clink-select-complete command works and break several things and scenarios that have been carefully designed and carefully tuned.

You're right that the clink-select-complete command is not good at showing what you've typed if you included any wildcards. That's an edge case in clink-select-complete, and I'm not going to redesign the command based on that edge case.

  1. Completion preview

It isn't a "completion preview" at all. Instead it's the text that has already been inserted into the input line.

It's displayed in the color.selection color because it's selected text -- like when you select text in any other edit box by pressing Shift+Arrows or by clicking and dragging the mouse.

It's the text that will get replaced by something else if you choose a different item from the list.

The suggestions would break several other things. It sounds like you're looking for fzf, and I'd recommend trying it out. That might give you an experience you like even better.

fiso64 commented 1 month ago

I didn't know that clink-fzf allowed one to filter completions, including cli options! It's not quite as streamlined as I'd like though. It has a separate search bar and I can't edit my main command while it's active (I need to press esc first, and do that twice, for some reason), so if you typed the first few letters of some item they are 'locked in'. It also doesn't display cli option descriptions like the complete menu does, which are pretty important whenever you forget something.

If e.g not automatically inserting the text (what I called the 'preview') breaks many things then I'll close the issue, as clink-fzf seems good enough. I'm wondering if it can be improved though.

chrisant996 commented 1 month ago

I didn't know that clink-fzf allowed one to filter completions, including cli options! It's not quite as streamlined as I'd like though. It has a separate search bar and I can't edit my main command while it's active

The way I would implement your suggestion about "Completion Preview = off" would be to add a separate search bar. If that's not what you had in mind, then you'd need to describe more about the implementation you have in mind.

The goal seemed to be to have a way to see the filtering string that's been typed so far. A search bar is the typical way that's done in programs. clink-select-complete avoids a search bar by virtue of the fact that it inserts whichever match is highlighted, and it can delete one inserted match and then insert a different match. And it selects the characters that will be deleted in the delete-then-insert dance. If there were no wildcards in the original text that's being completed, then the selection begins after whatever you've typed, which then has a side effect of kind of showing what you've typed. But that's only a side effect of the streamlined input design. So if you "remove the preview" then if you try to complete *hello and then type xy then what you'd see in the input line is only *helloxy, with no indication of where the selected match will actually end up getting inserted or what text will be replaced, etc.

(I need to press esc first, and do that twice, for some reason),

Because fzf comes from the Linux world, and in the Linux world the only way to tell that the literal Esc key has been pressed is to wait ~500ms after receiving an ESC character to see if there's more input. Because the input sequence for all the special keys (Up, Home, F1, Alt-A, etc etc) starts with an ESC character. Windows allows more direct access to the keyboard, and so if a program is written using special Windows API functions, then the program can tell when the literal Esc character has been pressed. That's why Clink is able to differentiate between Esc and all the special keys, without needing to wait.

Also, in Linux Ctrl-G is the key binding for cancel or abort (rather than Esc as in Windows). Pressing Ctrl-G immediately cancels out of fzf with no delay. The fzf documentation has more information about the keys it responds to.

so if you typed the first few letters of some item they are 'locked in'.

I'm not sure what you're describing. You can hit Backspace in fzf, just like you can in clink-select-complete. I don't know what is meant by "locked in".

It also doesn't display cli option descriptions like the complete menu does, which are pretty important whenever you forget something.

Correct, it doesn't.

If e.g not automatically inserting the text (what I called the 'preview') breaks many things then I'll close the issue, as clink-fzf seems good enough. I'm wondering if it can be improved though.

Do you mean if fzf can be improved? Your comments are about fzf, not about clink-fzf. Fzf is the fuzzy filtering program, and clink-fzf simply enables Clink to launch fzf.

chrisant996 commented 1 month ago

@fiso64 thank you for the contribution to clink-fzf for the prototype PR that adds match descriptions in fzf! The feature was committed as https://github.com/chrisant996/clink-fzf/commit/b739ea9f2cec36fef4b016bac6805cf39dff346f.