Class: Minesweeprb::Menu
- Inherits:
-
Object
- Object
- Minesweeprb::Menu
- Includes:
- Curses
- Defined in:
- lib/minesweeprb/menu.rb
Constant Summary collapse
- QUIT_KEYS =
['q', 27, 127, KEY_BACKSPACE].freeze
- GEM_GAP =
2
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(title, options) ⇒ Menu
constructor
A new instance of Menu.
- #select ⇒ Object
Constructor Details
#initialize(title, options) ⇒ Menu
Returns a new instance of Menu.
17 18 19 20 21 |
# File 'lib/minesweeprb/menu.rb', line 17 def initialize(title, ) @title = title @options = @selected = .index { |o| !o[:disabled] } || 0 end |
Class Method Details
.select(title, options) ⇒ Object
13 14 15 |
# File 'lib/minesweeprb/menu.rb', line 13 def self.select(title, ) new(title, ).select end |
Instance Method Details
#select ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/minesweeprb/menu.rb', line 23 def select setup loop do draw case .getch when KEY_UP, 'k' move(-1) when KEY_DOWN, 'j' move(1) when 10, KEY_ENTER break @options[@selected][:value] unless @options[@selected][:disabled] when *QUIT_KEYS break nil end end end |