What will give me something like ruby readline with a default value?
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:
Readline.pre_input_hook = -> do Readline.insert_text "hello.txt" Readline.redisplay # Remove the hook right away. Readline.pre_input_hook = nilendinput = Readline.readline("Filename: ", false)puts "-- input:#{input.inspect}"
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.
+1 to highline
try with something like:
require 'highline/import'input = ask('> ') {|q| q.default = 'default_text'} # > |default_text|
Sounds like a job for ncurses. Seems like rbcurse (http://rbcurse.rubyforge.org/) is the best maintained API at the moment.