piotrmurach / tty-prompt

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

Add press_any_key prompt #40

Closed kke closed 7 years ago

kke commented 7 years ago

Something like:

any_key('Somethings about to happen, press any key to continue')

and with countdown:

any_key('Somethings about to happen, press any key to continue, continuing automatically in...', countdown: 10) (which would continue automatically once the countdown reaches zero)

piotrmurach commented 7 years ago

That sounds like a good addition. Because this makes the prompt pause I would suggest the following api:

prompt.pause('Press any key to continue')

I also think it would provide higher flexibility to provide ability to specify keys that match already implemented key event names. By default any key would do the trick but you could ask user for specific confirmation.

prompt.pause('Press space or enter to continue', keys: [:space, :enter])

I would probably replace the countdown option with timeout as more generally understood convention:

prompt.pause('Press any key to continue', timeout: 10)

What do you think?

ps. I will schedule that for implementation for next release after Windows support is out of the door. I prefer to release more frequently.

kke commented 7 years ago

Yes pause is good.

piotrmurach commented 7 years ago

I went with already existing #keypress api as it seemed very appropriate and saved me introducing new types of prompts. It now support :keys and :timeout options. Please read docs and try out example. I've even introduced :countdown token so you can create any question you wish that includes automatic time countdown. Enjoy!

piotrmurach commented 7 years ago

Released v0.12.0 that includes new implementation for keypress. Enjoy!