Skip to content

Commit

Permalink
Merge pull request #66 from davispuh/master
Browse files Browse the repository at this point in the history
Separate auto-completion from answer type
  • Loading branch information
JEG2 committed Feb 10, 2013
2 parents c480dee + 821b912 commit 4b42ae9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/highline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions lib/highline/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4b42ae9

Please sign in to comment.