From 9994c6608f0dc12d228c1c12a7e75784a3fd1fef Mon Sep 17 00:00:00 2001 From: James Gray Date: Wed, 5 Nov 2008 17:38:19 +0000 Subject: [PATCH] Fixing completion to show choices when there are more than one. --- highline/CHANGELOG | 2 ++ highline/examples/using_readline.rb | 2 +- highline/lib/highline.rb | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/highline/CHANGELOG b/highline/CHANGELOG index aec7d6f7..3d04911e 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 2a2a572b..a84fd7d8 100644 --- a/highline/examples/using_readline.rb +++ b/highline/examples/using_readline.rb @@ -9,7 +9,7 @@ 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 ba2343d8..385df3a7 100644 --- a/highline/lib/highline.rb +++ b/highline/lib/highline.rb @@ -580,8 +580,9 @@ def get_line( ) @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