piotrmurach / tty-prompt

A beautiful and powerful interactive command line prompt
https://ttytoolkit.org
MIT License
1.47k stars 136 forks source link

Add auto completion input type #1

Open piotrmurach opened 8 years ago

piotrmurach commented 8 years ago

Search source for a matching input and display matching list as characters are entered.

thomasfl commented 8 years ago

+1 and the ability to switch through options using the tab key.

kylekyle commented 8 years ago

+1

piotrmurach commented 8 years ago

Appreciate the support of this feature but I may struggle to find time to add this atm. Suggestions for implementation or PRs would speed up the process.

kylekyle commented 8 years ago

Here's an easy solution if you don't mind adding readline as a dependency:

http://bogojoker.com/readline/#autocomplete_strategies

piotrmurach commented 8 years ago

I think that using readline may be unnecessary(need more time to think this through though) as we already have a nice way to respond to any keystrokes, I think the matching behaviour is the key to get right. Thanks for the reference!

piotrmurach commented 7 years ago

It's been a long time and few things have improved in this library such as pagination of select menus. However, recently I have found out about really poor behaviour of this gem on Windows. Though, this is not the system of my choice I appreciate the fact that a lot of users may wish to install and use it on windows. For example kontena cli tool is using tty-prompt as one of their dependencies. If there is a way to make this gem work on Windows well then I feel it is worth an effort as a lot of tty components are cross platform.

Therefore I'm currently rewriting how reading of character input works and testing it simultaneously on Windows. There is still plenty of code to be written but I'm making good progress and feel optimistic about the outcome. What that means to you? Well, once I finish the reading bit I have pretty much foundation ready to implement the autocomplete feature which will provide the readline capabilities, e.i. completion_proc but work across systems and won't require actual dependency on unix readline which makes me happy.

I wanted to update you on where I'm at and where things are going. I cannot promise a timeline but this is basically a next thing after Windows support is done. You can of course read the Windows issue to keep track.

Thanks for your patience!

jemc commented 7 years ago

@piotrmurach - I see some recent commits about Windows, so I'm wondering how Windows support is coming.

I'd be interested to put in some time here to help you out in making pretty auto-complete prompts like those provided by python-prompt-toolkit possible in Ruby:

example pretty prompt

Please let me know if there is work that I can pick up toward this effort (that doesn't involve Windows) that fits with your overall vision for this feature.

piotrmurach commented 7 years ago

@jemc - cheers for reaching out and offering to help!

Firstly, the windows support was implemented in v0.11.0 Feb this year. Recent work involved implementing blocking vs non-blocking keypress reading on Windows due to new pause feature which required some awkward windows apis.

The most recent changes removed all keyboard input reading capabilities into a separate abstraction tty-reader. I haven't officially let anyone in on this library yet. Why do I mention this? It has a lot to do with this issue, namely, providing completion features. I believe this to be a really useful abstraction that I will use in different projects.

My current thinking goes this way. The tty-reader as a component should provide low level api in some ways similar to readline but not replacing it. I would be looking into adding a method completion that based on the input provides possible matches. The completion method would contain default logic for matching that could be easily customised. For example, by default it would search for files in the current directory. The caller would have an easy way to hook into these matched results through callbacks or some other mechanics. Obviously there is a host of other configurations that TTY::Reader would accept to customise behaviour such as what character is used for completion.

As a second part of the story, there would be a consumer class in tty-prompt(let's say auto_complete prompt) that would hook into tty-reader completion method and take care of actually rendering the matches, including querying the user if they wish to display all results or subset etc... How would we display these results is of course left to debate. I'm not sure whether a dynamic table displayed right under the cursor is the best choice or maybe a list aligned in columns like it's done by some completion plugins in vim is a better choice.

I hope this kind of paints the picture a bit better. I don't think it's a quick job but definitely useful feature that would make this library super useful. If I were you I would probably look into tty-reader first and create issue over there on what and how you think the completion api can work.

ps. I'm currently working on releasing new tty version which will take me till the end of this month. I hope to show it off in a lightning talk at conference 😱 So I won't be working on this library until then.

rberger commented 6 years ago

Any news on this. Seems it would be the killer feature (at least for me :-)

jemc commented 6 years ago

My work that I was doing on this is fairly suspended in an unfinished state - I'm not actively working on it at this time, unfortunately - I've had other open source contributions take precedence in my "free time".

piotrmurach commented 6 years ago

@rberger Great to hear your support for this feature. I've recently finished rewrite of tty-reader that powers input editing in this library. Next, it will allow me to build in support for completion. However, there are few open source projects I need to get done by the end of this month and I will be fairly busy in February so the soonest I will probably look into implementing this feature will be in March. I hope you understand.

@jemc Whenever you have a minute to release what you've managed to do with tty gems would be great help. No pressure though as I fully understand the concept of open source in 'free time' as I've been doing it for quite a while 😅

64kramsystem commented 6 years ago

(moved my comment to a separate issue, #70)

zzyzwicz commented 6 years ago

+1

ninp0 commented 5 years ago

What's the status of this / how can I help? I want to implement a ruby alternative to the auto-completion menus found in python-prompt-toolkit. I'm currently interested in implementing this capability w/in a custom pry console used for prototyping automated security testing: https://github.com/ninp0/csi/blob/master/bin/csi

piotrmurach commented 5 years ago

@ninp0 Comments in this issue as well https://github.com/piotrmurach/tty-reader/issues/2 show the current state of thinking. I don't have time to work on this feature, even though I would like to tackle the challenge of figuring out elegant API for tty-reader to allow for arbitrary completion outputs.