23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/menu.rb', line 23
def self.(r: 0, c: 0, items:, curr: 0)
high = items.size + 2
wide = items.map(&:length).max + 4
saveback(high, wide, r, c)
win = RubyText.window(high, wide, r, c, fg: White, bg: Blue)
RubyText.set(:raw)
X.stdscr.keypad(true)
RubyText.hide_cursor
sel = curr
max = items.size - 1
loop do
items.each.with_index do |item, row|
win.go row, 0
color = sel == row ? Yellow : White
win.puts color, " #{item} "
end
ch = getch
case ch
when X::KEY_UP
sel -= 1 if sel > 0
when X::KEY_DOWN
sel += 1 if sel < max
when 27
restback(high, wide, r, c)
return [nil, nil]
when 10
restback(high, wide, r, c)
return [sel, items[sel]]
end
end
end
|