Skip to content

Commit

Permalink
Merge pull request #1 from DannyBen/fix
Browse files Browse the repository at this point in the history
Remove special treatment for single-item menus
  • Loading branch information
DannyBen authored Apr 13, 2019
2 parents b413732 + b42484d commit f86c84e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/menu_commander/menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ def args
end

def get_user_response(key)
opts = args ? args[key] : nil
opts = opts.is_a?(String) ? `#{opts}`.split("\n") : opts
opts = get_opts key
opts ? select(opts, key) : ask(key)
end

if opts
opts.size == 1 ? opts[0] : select(opts, key)
else
ask(key)
end
def get_opts(key)
opts = args ? args[key] : nil
opts.is_a?(String) ? `#{opts}`.split("\n") : opts
end

def prompt
Expand All @@ -52,23 +51,27 @@ def prompt

def ask(title)
prompt.ask "> #{title}:"

rescue TTY::Reader::InputInterrupt
# :nocov:
puts "\nGoodbye"
exit
# :nocov:

end

def select(options, title = nil)
title = title ? "> #{title}:" : ">"
menu_config = { marker: '>', per_page: 10 }
menu_config['filter'] = true if options.size > 10
prompt.select title, options, menu_config

rescue TTY::Reader::InputInterrupt
# :nocov:
puts "\nGoodbye"
exit
# :nocov:

end
end
end

0 comments on commit f86c84e

Please sign in to comment.