If I want to have a prompt on the terminal with a default value already typed in, how can I do that?
Ruby's standard Readline.readline()
lets me set the history but not fill in a default value (as far as I can tell, at least)
I would like something like this:
code:
input = Readline.readline_with_default('>', 'default_text')
console:
> default_text|
+1 to highline
try with something like:
Sounds like a job for ncurses. Seems like rbcurse (http://rbcurse.rubyforge.org/) is the best maintained API at the moment.
What you are asking is possible with
Readline
. There's a callback where you can get control after the prompt is displayed and insert some text into the read buffer.This worked for me:
BTW, I fairly tried to use HighLine, but it appeared to be a no-alternative to me. One of the disappointing reasons was the fact that
HighLine#ask
reads cursor movement keys as regular input. I stopped looking in that direction after that sort of discovery.I'm struggling with the same thing.
The way I'm doing it right now is:
yes, it's silly, but it has been the only way I've found to do it.
did anybody find any solution to this?
Highline doesn't do exactly what you describe, but maybe it's close enough.