curses_menu 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/LICENSE.md +31 -0
- data/README.md +78 -0
- data/examples/actions.rb +25 -25
- data/examples/automatic_key_presses.rb +49 -49
- data/examples/formatting.rb +148 -130
- data/examples/hello.rb +8 -8
- data/examples/refresh.rb +22 -22
- data/examples/scrolling.rb +9 -9
- data/examples/several_items.rb +18 -18
- data/examples/sub_menus.rb +20 -20
- data/examples/utf_8.rb +8 -0
- data/lib/curses_menu.rb +248 -241
- data/lib/curses_menu/curses_row.rb +151 -150
- data/lib/curses_menu/version.rb +5 -0
- data/spec/curses_menu_test.rb +131 -0
- data/spec/curses_menu_test/actions_spec.rb +221 -0
- data/spec/curses_menu_test/formatting_spec.rb +411 -0
- data/spec/curses_menu_test/rubocop_spec.rb +31 -0
- data/spec/curses_menu_test/scrolling_spec.rb +95 -0
- data/spec/curses_menu_test/simple_navigation_spec.rb +123 -0
- data/spec/spec_helper.rb +105 -0
- metadata +89 -10
data/examples/hello.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'curses_menu'
|
2
|
-
|
3
|
-
CursesMenu.new 'My awesome new menu!' do |menu|
|
4
|
-
menu.item 'How\'s life?' do
|
5
|
-
puts 'Couldn\'t be easier'
|
6
|
-
:menu_exit
|
7
|
-
end
|
8
|
-
end
|
1
|
+
require 'curses_menu'
|
2
|
+
|
3
|
+
CursesMenu.new 'My awesome new menu!' do |menu|
|
4
|
+
menu.item 'How\'s life?' do
|
5
|
+
puts 'Couldn\'t be easier'
|
6
|
+
:menu_exit
|
7
|
+
end
|
8
|
+
end
|
data/examples/refresh.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require 'curses_menu'
|
2
|
-
|
3
|
-
nbr = 0
|
4
|
-
switch = false
|
5
|
-
CursesMenu.new 'Menu being refreshed when selecting things' do |menu|
|
6
|
-
menu.item "Current number is #{nbr} - Select me for +1" do
|
7
|
-
nbr += 1
|
8
|
-
:menu_refresh
|
9
|
-
end
|
10
|
-
menu.item "Current number is #{nbr} - Select me for -1" do
|
11
|
-
nbr -= 1
|
12
|
-
:menu_refresh
|
13
|
-
end
|
14
|
-
menu.item "[#{switch ? '*' : ' '}] Switch me!" do
|
15
|
-
switch = !switch
|
16
|
-
:menu_refresh
|
17
|
-
end
|
18
|
-
menu.item 'Quit' do
|
19
|
-
puts 'Quitting...'
|
20
|
-
:menu_exit
|
21
|
-
end
|
22
|
-
end
|
1
|
+
require 'curses_menu'
|
2
|
+
|
3
|
+
nbr = 0
|
4
|
+
switch = false
|
5
|
+
CursesMenu.new 'Menu being refreshed when selecting things' do |menu|
|
6
|
+
menu.item "Current number is #{nbr} - Select me for +1" do
|
7
|
+
nbr += 1
|
8
|
+
:menu_refresh
|
9
|
+
end
|
10
|
+
menu.item "Current number is #{nbr} - Select me for -1" do
|
11
|
+
nbr -= 1
|
12
|
+
:menu_refresh
|
13
|
+
end
|
14
|
+
menu.item "[#{switch ? '*' : ' '}] Switch me!" do
|
15
|
+
switch = !switch
|
16
|
+
:menu_refresh
|
17
|
+
end
|
18
|
+
menu.item 'Quit' do
|
19
|
+
puts 'Quitting...'
|
20
|
+
:menu_exit
|
21
|
+
end
|
22
|
+
end
|
data/examples/scrolling.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'curses_menu'
|
2
|
-
|
3
|
-
CursesMenu.new 'Use all arrows, Page up/down, Home and End keys!' do |menu|
|
4
|
-
menu.item('Quit') { :menu_exit }
|
5
|
-
menu.item 'That\'s a big menu item! ' * 20
|
6
|
-
1000.times do |idx|
|
7
|
-
menu.item "Menu item #{idx}"
|
8
|
-
end
|
9
|
-
end
|
1
|
+
require 'curses_menu'
|
2
|
+
|
3
|
+
CursesMenu.new 'Use all arrows, Page up/down, Home and End keys!' do |menu|
|
4
|
+
menu.item('Quit') { :menu_exit }
|
5
|
+
menu.item 'That\'s a big menu item! ' * 20
|
6
|
+
1000.times do |idx|
|
7
|
+
menu.item "Menu item #{idx}"
|
8
|
+
end
|
9
|
+
end
|
data/examples/several_items.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'curses_menu'
|
2
|
-
|
3
|
-
CursesMenu.new 'We have several items, some of them have no action' do |menu|
|
4
|
-
menu.item 'Nothing to do with me'
|
5
|
-
menu.item 'Select me - I\'m option A!' do
|
6
|
-
puts 'You have selected A. Press enter to continue.'
|
7
|
-
$stdin.gets
|
8
|
-
end
|
9
|
-
menu.item 'Or select me - Option B!' do
|
10
|
-
puts 'You have selected B. Press enter to continue.'
|
11
|
-
$stdin.gets
|
12
|
-
end
|
13
|
-
menu.item '---- Separator'
|
14
|
-
menu.item 'Quit' do
|
15
|
-
puts 'Quitting...'
|
16
|
-
:menu_exit
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require 'curses_menu'
|
2
|
+
|
3
|
+
CursesMenu.new 'We have several items, some of them have no action' do |menu|
|
4
|
+
menu.item 'Nothing to do with me'
|
5
|
+
menu.item 'Select me - I\'m option A!' do
|
6
|
+
puts 'You have selected A. Press enter to continue.'
|
7
|
+
$stdin.gets
|
8
|
+
end
|
9
|
+
menu.item 'Or select me - Option B!' do
|
10
|
+
puts 'You have selected B. Press enter to continue.'
|
11
|
+
$stdin.gets
|
12
|
+
end
|
13
|
+
menu.item '---- Separator'
|
14
|
+
menu.item 'Quit' do
|
15
|
+
puts 'Quitting...'
|
16
|
+
:menu_exit
|
17
|
+
end
|
18
|
+
end
|
data/examples/sub_menus.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require 'curses_menu'
|
2
|
-
|
3
|
-
CursesMenu.new 'Top menu' do |menu|
|
4
|
-
menu.item 'Enter menu 1' do
|
5
|
-
CursesMenu.new 'Sub-menu 1' do |sub_menu|
|
6
|
-
sub_menu.item 'We are in sub-menu 1'
|
7
|
-
sub_menu.item('Back') { :menu_exit }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
menu.item 'Enter menu 2' do
|
11
|
-
CursesMenu.new 'Sub-menu 2' do |sub_menu|
|
12
|
-
sub_menu.item 'We are in sub-menu 2'
|
13
|
-
sub_menu.item('Back') { :menu_exit }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
menu.item 'Quit' do
|
17
|
-
puts 'Quitting...'
|
18
|
-
:menu_exit
|
19
|
-
end
|
20
|
-
end
|
1
|
+
require 'curses_menu'
|
2
|
+
|
3
|
+
CursesMenu.new 'Top menu' do |menu|
|
4
|
+
menu.item 'Enter menu 1' do
|
5
|
+
CursesMenu.new 'Sub-menu 1' do |sub_menu|
|
6
|
+
sub_menu.item 'We are in sub-menu 1'
|
7
|
+
sub_menu.item('Back') { :menu_exit }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
menu.item 'Enter menu 2' do
|
11
|
+
CursesMenu.new 'Sub-menu 2' do |sub_menu|
|
12
|
+
sub_menu.item 'We are in sub-menu 2'
|
13
|
+
sub_menu.item('Back') { :menu_exit }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
menu.item 'Quit' do
|
17
|
+
puts 'Quitting...'
|
18
|
+
:menu_exit
|
19
|
+
end
|
20
|
+
end
|
data/examples/utf_8.rb
ADDED
data/lib/curses_menu.rb
CHANGED
@@ -1,241 +1,248 @@
|
|
1
|
-
require 'curses'
|
2
|
-
require 'curses_menu/curses_row'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
action_shortcut
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
when Curses::
|
109
|
-
|
110
|
-
when Curses::
|
111
|
-
|
112
|
-
when Curses::
|
113
|
-
selected_idx
|
114
|
-
when Curses::
|
115
|
-
selected_idx
|
116
|
-
when Curses::
|
117
|
-
selected_idx
|
118
|
-
when
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
#
|
159
|
-
#
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
Curses.
|
206
|
-
|
207
|
-
Curses.
|
208
|
-
Curses.
|
209
|
-
Curses.init_pair(
|
210
|
-
Curses.init_pair(
|
211
|
-
Curses.init_pair(
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
@curses_initialized =
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
#
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
1
|
+
require 'curses'
|
2
|
+
require 'curses_menu/curses_row'
|
3
|
+
|
4
|
+
# Provide a menu using curses with keys navigation and selection
|
5
|
+
class CursesMenu
|
6
|
+
|
7
|
+
# Define some color pairs names.
|
8
|
+
# The integer value is meaningless in itself but they all have to be different.
|
9
|
+
COLORS_TITLE = 1
|
10
|
+
COLORS_LINE = 2
|
11
|
+
COLORS_MENU_ITEM = 3
|
12
|
+
COLORS_MENU_ITEM_SELECTED = 4
|
13
|
+
COLORS_INPUT = 5
|
14
|
+
COLORS_GREEN = 6
|
15
|
+
COLORS_RED = 7
|
16
|
+
COLORS_YELLOW = 8
|
17
|
+
COLORS_BLUE = 9
|
18
|
+
COLORS_WHITE = 10
|
19
|
+
|
20
|
+
# curses keys that are not defined by Curses, but that are returned by getch
|
21
|
+
KEY_ENTER = 10
|
22
|
+
KEY_ESCAPE = 27
|
23
|
+
|
24
|
+
# Constructor.
|
25
|
+
# Display a list of choices, ask for user input and execute the choice made.
|
26
|
+
# Repeat the operation unless one of the code returns the :menu_exit symbol.
|
27
|
+
#
|
28
|
+
# Parameters::
|
29
|
+
# * *title* (String): Title of those choices
|
30
|
+
# * *key_presses* (Array<Object>): List of key presses to automatically apply [default: []]
|
31
|
+
# Can be characters or ascii values, as returned by curses' getch.
|
32
|
+
# The list is modified in place along with its consumption, so that it can be reused in sub-menus if needed.
|
33
|
+
# * *&menu_items_def* (Proc): Code to be called to get the list of choices. This code can call the following methods to design the menu:
|
34
|
+
# * Parameters::
|
35
|
+
# * *menu* (CursesMenu): The CursesMenu instance
|
36
|
+
def initialize(title, key_presses: [], &menu_items_def)
|
37
|
+
@current_menu_items = nil
|
38
|
+
@curses_initialized = false
|
39
|
+
current_items = gather_menu_items(&menu_items_def)
|
40
|
+
selected_idx = 0
|
41
|
+
raise "Menu #{title} has no items to select" if selected_idx.nil?
|
42
|
+
|
43
|
+
window = curses_menu_initialize
|
44
|
+
begin
|
45
|
+
max_displayed_items = window.maxy - 5
|
46
|
+
display_first_idx = 0
|
47
|
+
display_first_char_idx = 0
|
48
|
+
loop do
|
49
|
+
# TODO: Don't redraw fixed items for performance
|
50
|
+
# Display the title
|
51
|
+
window.setpos(0, 0)
|
52
|
+
print(window, '', default_color_pair: COLORS_TITLE, pad: '=')
|
53
|
+
print(window, "= #{title}", default_color_pair: COLORS_TITLE, pad: ' ', single_line: true)
|
54
|
+
print(window, '', default_color_pair: COLORS_TITLE, pad: '-')
|
55
|
+
# Display the menu
|
56
|
+
current_items[display_first_idx..display_first_idx + max_displayed_items - 1].each.with_index do |item_info, idx|
|
57
|
+
selected = display_first_idx + idx == selected_idx
|
58
|
+
print(
|
59
|
+
window,
|
60
|
+
item_info[:title],
|
61
|
+
from: display_first_char_idx,
|
62
|
+
default_color_pair: item_info.key?(:actions) ? COLORS_MENU_ITEM : COLORS_LINE,
|
63
|
+
force_color_pair: selected ? COLORS_MENU_ITEM_SELECTED : nil,
|
64
|
+
pad: selected ? ' ' : nil,
|
65
|
+
single_line: true
|
66
|
+
)
|
67
|
+
end
|
68
|
+
# Display the footer
|
69
|
+
window.setpos(window.maxy - 2, 0)
|
70
|
+
print(window, '', default_color_pair: COLORS_TITLE, pad: '=')
|
71
|
+
display_actions = {
|
72
|
+
'Arrows/Home/End' => 'Navigate',
|
73
|
+
'Esc' => 'Exit'
|
74
|
+
}
|
75
|
+
if current_items[selected_idx][:actions]
|
76
|
+
display_actions.merge!(
|
77
|
+
current_items[selected_idx][:actions].map do |action_shortcut, action_info|
|
78
|
+
[
|
79
|
+
case action_shortcut
|
80
|
+
when KEY_ENTER
|
81
|
+
'Enter'
|
82
|
+
else
|
83
|
+
action_shortcut
|
84
|
+
end,
|
85
|
+
action_info[:name]
|
86
|
+
]
|
87
|
+
end.to_h
|
88
|
+
)
|
89
|
+
end
|
90
|
+
print(
|
91
|
+
window,
|
92
|
+
"= #{display_actions.sort.map { |(shortcut, name)| "#{shortcut}: #{name}" }.join(' | ')}",
|
93
|
+
from: display_first_char_idx,
|
94
|
+
default_color_pair: COLORS_TITLE,
|
95
|
+
pad: ' ',
|
96
|
+
add_nl: false,
|
97
|
+
single_line: true
|
98
|
+
)
|
99
|
+
window.refresh
|
100
|
+
user_choice = nil
|
101
|
+
loop do
|
102
|
+
user_choice = key_presses.empty? ? window.getch : key_presses.shift
|
103
|
+
break unless user_choice.nil?
|
104
|
+
|
105
|
+
sleep 0.01
|
106
|
+
end
|
107
|
+
case user_choice
|
108
|
+
when Curses::KEY_RIGHT
|
109
|
+
display_first_char_idx += 1
|
110
|
+
when Curses::KEY_LEFT
|
111
|
+
display_first_char_idx -= 1
|
112
|
+
when Curses::KEY_UP
|
113
|
+
selected_idx -= 1
|
114
|
+
when Curses::KEY_PPAGE
|
115
|
+
selected_idx -= max_displayed_items - 1
|
116
|
+
when Curses::KEY_DOWN
|
117
|
+
selected_idx += 1
|
118
|
+
when Curses::KEY_NPAGE
|
119
|
+
selected_idx += max_displayed_items - 1
|
120
|
+
when Curses::KEY_HOME
|
121
|
+
selected_idx = 0
|
122
|
+
when Curses::KEY_END
|
123
|
+
selected_idx = current_items.size - 1
|
124
|
+
when KEY_ESCAPE
|
125
|
+
break
|
126
|
+
else
|
127
|
+
# Check actions
|
128
|
+
if current_items[selected_idx][:actions]&.key?(user_choice)
|
129
|
+
curses_menu_finalize
|
130
|
+
result = current_items[selected_idx][:actions][user_choice][:execute].call
|
131
|
+
if result.is_a?(Symbol)
|
132
|
+
case result
|
133
|
+
when :menu_exit
|
134
|
+
break
|
135
|
+
when :menu_refresh
|
136
|
+
current_items = gather_menu_items(&menu_items_def)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
window = curses_menu_initialize
|
140
|
+
window.clear
|
141
|
+
end
|
142
|
+
end
|
143
|
+
# Stay in bounds
|
144
|
+
display_first_char_idx = 0 if display_first_char_idx.negative?
|
145
|
+
selected_idx = current_items.size - 1 if selected_idx >= current_items.size
|
146
|
+
selected_idx = 0 if selected_idx.negative?
|
147
|
+
if selected_idx < display_first_idx
|
148
|
+
display_first_idx = selected_idx
|
149
|
+
elsif selected_idx >= display_first_idx + max_displayed_items
|
150
|
+
display_first_idx = selected_idx - max_displayed_items + 1
|
151
|
+
end
|
152
|
+
end
|
153
|
+
ensure
|
154
|
+
curses_menu_finalize
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Register a new menu item.
|
159
|
+
# This method is meant to be called from a choose_from call.
|
160
|
+
#
|
161
|
+
# Parameters::
|
162
|
+
# * *title* (String or CursesRow): Text to be displayed for this item
|
163
|
+
# * *actions* (Hash<Object, Hash<Symbol,Object> >): Associated actions to this item, per shortcut [default: {}]
|
164
|
+
# * *name* (String): Name of this action (displayed at the bottom of the menu)
|
165
|
+
# * *execute* (Proc): Code called when this action is selected
|
166
|
+
# * *&action* (Proc): Code called if the item is selected (action for the enter key) [optional].
|
167
|
+
# * Result::
|
168
|
+
# * Symbol or Object: If the code returns a symbol, the menu will behave in a specific way:
|
169
|
+
# * *menu_exit*: the menu selection exits.
|
170
|
+
# * *menu_refresh*: The menu will compute again its items.
|
171
|
+
def item(title, actions: {}, &action)
|
172
|
+
menu_item_def = { title: title }
|
173
|
+
all_actions = action.nil? ? actions : actions.merge(KEY_ENTER => { name: 'Select', execute: action })
|
174
|
+
menu_item_def[:actions] = all_actions unless all_actions.empty?
|
175
|
+
@current_menu_items << menu_item_def
|
176
|
+
end
|
177
|
+
|
178
|
+
private
|
179
|
+
|
180
|
+
# Display a given curses string information.
|
181
|
+
#
|
182
|
+
# Parameters::
|
183
|
+
# * *window* (Window): The curses window in which we display.
|
184
|
+
# * *string* (String or CursesRow): The curses row, or as a single String.
|
185
|
+
# * See CursesRow#print_on for all the other parameters description
|
186
|
+
def print(window, string, from: 0, to: nil, default_color_pair: COLORS_LINE, force_color_pair: nil, pad: nil, add_nl: true, single_line: false)
|
187
|
+
string = CursesRow.new({ default: { text: string } }) if string.is_a?(String)
|
188
|
+
string.print_on(
|
189
|
+
window,
|
190
|
+
from: from,
|
191
|
+
to: to,
|
192
|
+
default_color_pair: default_color_pair,
|
193
|
+
force_color_pair: force_color_pair,
|
194
|
+
pad: pad,
|
195
|
+
add_nl: add_nl,
|
196
|
+
single_line: single_line
|
197
|
+
)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Initialize and get the curses menu window
|
201
|
+
#
|
202
|
+
# Result::
|
203
|
+
# * Window: The curses menu window
|
204
|
+
def curses_menu_initialize
|
205
|
+
Curses.init_screen
|
206
|
+
# Use non-blocking key read, otherwise using Popen3 later blocks
|
207
|
+
Curses.timeout = 0
|
208
|
+
Curses.start_color
|
209
|
+
Curses.init_pair(COLORS_TITLE, Curses::COLOR_BLACK, Curses::COLOR_CYAN)
|
210
|
+
Curses.init_pair(COLORS_LINE, Curses::COLOR_WHITE, Curses::COLOR_BLACK)
|
211
|
+
Curses.init_pair(COLORS_MENU_ITEM, Curses::COLOR_WHITE, Curses::COLOR_BLACK)
|
212
|
+
Curses.init_pair(COLORS_MENU_ITEM_SELECTED, Curses::COLOR_BLACK, Curses::COLOR_WHITE)
|
213
|
+
Curses.init_pair(COLORS_INPUT, Curses::COLOR_WHITE, Curses::COLOR_BLUE)
|
214
|
+
Curses.init_pair(COLORS_GREEN, Curses::COLOR_GREEN, Curses::COLOR_BLACK)
|
215
|
+
Curses.init_pair(COLORS_RED, Curses::COLOR_RED, Curses::COLOR_BLACK)
|
216
|
+
Curses.init_pair(COLORS_YELLOW, Curses::COLOR_YELLOW, Curses::COLOR_BLACK)
|
217
|
+
Curses.init_pair(COLORS_BLUE, Curses::COLOR_BLUE, Curses::COLOR_BLACK)
|
218
|
+
Curses.init_pair(COLORS_WHITE, Curses::COLOR_WHITE, Curses::COLOR_BLACK)
|
219
|
+
window = Curses.stdscr
|
220
|
+
window.keypad = true
|
221
|
+
@curses_initialized = true
|
222
|
+
window
|
223
|
+
end
|
224
|
+
|
225
|
+
# Finalize the curses menu window
|
226
|
+
def curses_menu_finalize
|
227
|
+
Curses.close_screen if @curses_initialized
|
228
|
+
@curses_initialized = false
|
229
|
+
end
|
230
|
+
|
231
|
+
# Get menu items.
|
232
|
+
#
|
233
|
+
# Parameters::
|
234
|
+
# * Proc: Code defining the menu items
|
235
|
+
# * *menu* (CursesMenu): The menu for which we gather items.
|
236
|
+
# Result::
|
237
|
+
# * Array< Hash<Symbol,Object> >: List of items to be displayed
|
238
|
+
# * *title* (String): Item title to display
|
239
|
+
# * *actions* (Hash<Object, Hash<Symbol,Object> >): Associated actions to this item, per shortcut [optional]
|
240
|
+
# * *name* (String): Name of this action (displayed at the bottom of the menu)
|
241
|
+
# * *execute* (Proc): Code called when this action is selected
|
242
|
+
def gather_menu_items
|
243
|
+
@current_menu_items = []
|
244
|
+
yield self
|
245
|
+
@current_menu_items
|
246
|
+
end
|
247
|
+
|
248
|
+
end
|