From 821b9128b52f5d1966145e44dc09c98d8d1b06c9 Mon Sep 17 00:00:00 2001 From: davispuh Date: Tue, 5 Feb 2013 00:38:42 +0200 Subject: [PATCH] Separate auto-completion from answer type --- lib/highline.rb | 2 ++ lib/highline/question.rb | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/highline.rb b/lib/highline.rb index 319e19cb..e0aaf297 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -324,6 +324,8 @@ def choose( *items, &details ) @menu = @question = Menu.new(&details) @menu.choices(*items) unless items.empty? + # Set auto-completion + @menu.completion = @menu.options # Set _answer_type_ so we can double as the Question for ask(). @menu.answer_type = if @menu.shell lambda do |command| # shell-style selection diff --git a/lib/highline/question.rb b/lib/highline/question.rb index c0e30968..92060ed7 100755 --- a/lib/highline/question.rb +++ b/lib/highline/question.rb @@ -33,6 +33,7 @@ def initialize( question, answer_type ) # initialize instance data @question = question.dup @answer_type = answer_type + @completion = @answer_type @character = nil @limit = nil @@ -65,6 +66,8 @@ def initialize( question, answer_type ) attr_accessor :question # The type that will be used to convert this answer. attr_accessor :answer_type + # For Auto-completion + attr_accessor :completion # # Can be set to +true+ to use HighLine's cross-platform character reader # instead of fetching an entire line of input. (Note: HighLine's character @@ -421,9 +424,9 @@ def remove_whitespace( answer_string ) # Pathname. Any other time, this method will return an empty Array. # def selection( ) - if @answer_type.is_a?(Array) - @answer_type - elsif [File, Pathname].include?(@answer_type) + if @completion.is_a?(Array) + @completion + elsif [File, Pathname].include?(@completion) Dir[File.join(@directory.to_s, @glob)].map do |file| File.basename(file) end