Class: Minesweeprb::Menu

Inherits:
Object
  • Object
show all
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

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, options)
  @title = title
  @options = options
  @selected = options.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, options)
  new(title, options).select
end

Instance Method Details

#selectObject



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 w_menu.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