smrepl icon indicating copy to clipboard operation
smrepl copied to clipboard

Support for TAB in repl

Open avive opened this issue 3 years ago • 4 comments

Make TAB key behave like SPACE key in repl keyboard input so the auto-suggestor for the current level will be displayed.

So, if TAB is pressed after a command was typed or entered via suggestion, e.g. wallet then treat it as space - enter space and display the correct auto-suggestor (in our example, wallet commands). However, if tab is pressed when an auto-suggestor is open - don't modify anything as tab correctly rotates between all available commands.

avive avatar Jun 29 '21 19:06 avive

There is a corner case I think we are missing to discuss here: when we press tab for a auto-completion, for example when we press tab with a input of 'wall', go-prompt will automatically insert 'et' to the end of our input. At this moment 'tab' will be treated as "withdraw" or "switch" by go-prompt even though the auto-suggestor is closed, which will cause conflicts with our original intention.

Soptq avatar Jul 12 '21 09:07 Soptq

Good point, I think needs to be handled in the following way:

  1. If tab is pressed after some text is entered which is not a valid command at the current completion level then it should work like it does now - open the suggestor floating area with valid suggestion based on user text entry prefix.
  2. If tab is pressed just after a valid command was entered by the user (by typing or by completing from a suggestion) it should be treated as space (add space to the user input) and open the suggestor floating area for the next level of suggestions so user can select next-level suggestion or type it.

Makes sense?

avive avatar Jul 12 '21 14:07 avive

Yeah, but in order to achieve this, perhaps we need to maintain a fork of go-prompt since to my best knowledge there is no such a callback in go-prompt that capable of retrieving variables we need here. Nevertheless, I will do more research of it.

Soptq avatar Jul 12 '21 16:07 Soptq

I see. Maybe there are better prompt libs out there that we can use?

avive avatar Aug 02 '21 10:08 avive