summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Gray <james@grayproductions.net>2008-11-05 17:38:19 +0000
committerJames Gray <james@grayproductions.net>2008-11-05 17:38:19 +0000
commit9994c6608f0dc12d228c1c12a7e75784a3fd1fef (patch)
treecbadd95b86ebf8016893f5abe2c3e1bf44359176
parente3658394932344d0201efe9a8fae66325dd69ff8 (diff)
downloadhighline-9994c6608f0dc12d228c1c12a7e75784a3fd1fef.tar.gz
Fixing completion to show choices when there are more than one.
-rw-r--r--highline/CHANGELOG2
-rw-r--r--highline/examples/using_readline.rb2
-rw-r--r--highline/lib/highline.rb5
3 files changed, 6 insertions, 3 deletions
diff --git a/highline/CHANGELOG b/highline/CHANGELOG
index aec7d6f..3d04911 100644
--- a/highline/CHANGELOG
+++ b/highline/CHANGELOG
@@ -4,6 +4,8 @@ Below is a complete listing of changes for each revision of HighLine.
== 1.5.0
+* Fixed a bug that would prevent Readline from showing all completions.
+ (reported by Yaohan Chen)
* Added the ability to pass a block to HighLine#agree().
(patch by Yaohan Chen)
diff --git a/highline/examples/using_readline.rb b/highline/examples/using_readline.rb
index 2a2a572..a84fd7d 100644
--- a/highline/examples/using_readline.rb
+++ b/highline/examples/using_readline.rb
@@ -9,7 +9,7 @@ require "rubygems"
require "highline/import"
loop do
- cmd = ask("Enter command: ", %w{save load reset quit}) do |q|
+ cmd = ask("Enter command: ", %w{save sample load reset quit}) do |q|
q.readline = true
end
say("Executing \"#{cmd}\"...")
diff --git a/highline/lib/highline.rb b/highline/lib/highline.rb
index ba2343d..385df3a 100644
--- a/highline/lib/highline.rb
+++ b/highline/lib/highline.rb
@@ -580,8 +580,9 @@ class HighLine
@output = old_output
# prep auto-completion
- completions = @question.selection.abbrev
- Readline.completion_proc = lambda { |string| completions[string] }
+ Readline.completion_proc = lambda do |string|
+ @question.selection.grep(/\A#{Regexp.escape(string)}/)
+ end
# work-around ugly readline() warnings
old_verbose = $VERBOSE