Navigating the ancient Readline interface is a bit complicated. Here’s how to get filename completion when you hit the tab button:
require 'readline'
def ask_for_filename question, start_dir=""
Readline.completion_append_character = nil
Readline.completion_proc = lambda do |prefix|
files = Dir["#{start_dir}#{prefix}*"]
files.
map { |f| File.expand_path(f) }.
map { |f| File.directory?(f) ? f + "/" : f }
end
Readline.readline question
end
Also you can do something like:
to store the answer in the edit history. Unfortunately that doesn’t returnanswerso you invariably end up with a k-combinator-type situation. But if you’re using readline in the first place, you’ve probably already realized it ain’t gonna be pretty.Also you can do something like:
to store the answer in the edit history. Unfortunately that doesn’t returnanswerso you invariably end up with a k-combinator-type situation. But if you’re using readline in the first place, you’ve probably already realized it ain’t gonna be pretty.