erikhuda/thor — pull request #360 by georgebrock (2013-08-11 22:38:38+00:00)
Title: Use Readline for user input

This pull request changes the behaviour of `#ask` to use `Readline` if it is available (and to fall back to `$stdin.gets` if it is not).

There are several benefits to using `Readline` over `$stdin`:

* Tab completion for paths (enabled when `:path => true` is passed to `#ask`).
* Tab completion for the legal values (enabled when `:limited_to` is passed to `#ask`).
* Potential to support user-provided tab completion (not included in this PR, but not too difficult to imagine adding from here).
* Input history is recorded, so the user can press ↑ or CtrlR to find and repeat previous input (this is off by default for `#yes?`, `#no?`, and `#file_collision`, and on by default for `#ask` unless `:add_to_history => false` is given).

All of this adds up to Thor prompts behave more like many other Unix prompts (`bash`, `irb`, etc.), following the [principle of least astonishment][1] and providing [powerful editing commands][2].

I wrote tests first, and I've tried to update documentation and follow the style of the surrounding code. If there's anything that I should change to get this merged, just let me know.

[1]: https://en.wikipedia.org/wiki/Principle_of_least_astonishment
[2]: http://jan.tomka.name/sites/default/files/readline-commands.html