Class: Tomo::Console::Menu
- Inherits:
-
Object
- Object
- Tomo::Console::Menu
- Extended by:
- Forwardable
- Includes:
- Tomo::Colors
- Defined in:
- lib/tomo/console/menu.rb
Constant Summary collapse
- ARROW_UP =
"\e[A"- ARROW_DOWN =
"\e[B"- RETURN =
"\r"- ENTER =
"\n"
Instance Method Summary collapse
-
#initialize(question, options, key_reader: KeyReader.new, output: $stdout) ⇒ Menu
constructor
A new instance of Menu.
- #prompt_for_selection ⇒ Object
- #selected_option ⇒ Object
Methods included from Tomo::Colors
Constructor Details
#initialize(question, options, key_reader: KeyReader.new, output: $stdout) ⇒ Menu
Returns a new instance of Menu.
17 18 19 20 21 22 23 |
# File 'lib/tomo/console/menu.rb', line 17 def initialize(question, , key_reader: KeyReader.new, output: $stdout) @question = question @options = @position = 0 @key_reader = key_reader @output = output end |
Instance Method Details
#prompt_for_selection ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tomo/console/menu.rb', line 29 def prompt_for_selection render_loop do |key| case key when RETURN, ENTER then break when ARROW_UP then move(-1) when ARROW_DOWN then move(1) else self.position = find_match_index(key) end end print "#{yellow(question)} #{blue(selected_option)}\n" selected_option end |
#selected_option ⇒ Object
25 26 27 |
# File 'lib/tomo/console/menu.rb', line 25 def selected_option [position] end |