curses_menu 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- 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/lib/curses_menu.rb +248 -241
- data/lib/curses_menu/curses_row.rb +151 -150
- data/lib/curses_menu/version.rb +5 -0
- metadata +65 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 607c643000199bc2b3ef7cf3b2cd16346bcb8f1c4035eb30c2d033bac0df1626
|
4
|
+
data.tar.gz: e71f143c744eff5b971c2821ee1538990fc9906baf5596fec4622294f4ffc4e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66129319cbf7647404eb77ef0d1f8ef095bbd1e5cf3b61561a23bd5d7e7f675e4d7a62721baa377d228b7bea2b280423603f0a7280cf40ab3389d70174c1154f
|
7
|
+
data.tar.gz: bf877618677e1ca577f6e1899f85800f12b91c40a0c620deb9d07b52fa1b6ec1d28ed2a5c3cdb709c76daee35476644ead429b8e5a7e04573c32c0dc98e06a83
|
data/examples/actions.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
require 'curses_menu'
|
2
|
-
|
3
|
-
nbr = 0
|
4
|
-
CursesMenu.new 'Items can have several actions. Look at the footer!' do |menu|
|
5
|
-
menu.item "Current number is #{nbr} - Use a or d", actions: {
|
6
|
-
'd' => {
|
7
|
-
name: 'Increase',
|
8
|
-
execute: proc do
|
9
|
-
nbr += 1
|
10
|
-
:menu_refresh
|
11
|
-
end
|
12
|
-
},
|
13
|
-
'a' => {
|
14
|
-
name: 'Decrease',
|
15
|
-
execute: proc do
|
16
|
-
nbr -= 1
|
17
|
-
:menu_refresh
|
18
|
-
end
|
19
|
-
}
|
20
|
-
}
|
21
|
-
menu.item 'Quit' do
|
22
|
-
puts 'Quitting...'
|
23
|
-
:menu_exit
|
24
|
-
end
|
25
|
-
end
|
1
|
+
require 'curses_menu'
|
2
|
+
|
3
|
+
nbr = 0
|
4
|
+
CursesMenu.new 'Items can have several actions. Look at the footer!' do |menu|
|
5
|
+
menu.item "Current number is #{nbr} - Use a or d", actions: {
|
6
|
+
'd' => {
|
7
|
+
name: 'Increase',
|
8
|
+
execute: proc do
|
9
|
+
nbr += 1
|
10
|
+
:menu_refresh
|
11
|
+
end
|
12
|
+
},
|
13
|
+
'a' => {
|
14
|
+
name: 'Decrease',
|
15
|
+
execute: proc do
|
16
|
+
nbr -= 1
|
17
|
+
:menu_refresh
|
18
|
+
end
|
19
|
+
}
|
20
|
+
}
|
21
|
+
menu.item 'Quit' do
|
22
|
+
puts 'Quitting...'
|
23
|
+
:menu_exit
|
24
|
+
end
|
25
|
+
end
|
@@ -1,49 +1,49 @@
|
|
1
|
-
require 'curses_menu'
|
2
|
-
|
3
|
-
keys = [
|
4
|
-
# Select first
|
5
|
-
CursesMenu::KEY_ENTER,
|
6
|
-
# Select second
|
7
|
-
Curses::KEY_DOWN,
|
8
|
-
'a',
|
9
|
-
'b',
|
10
|
-
# Select third (sub-menu)
|
11
|
-
Curses::KEY_DOWN,
|
12
|
-
CursesMenu::KEY_ENTER,
|
13
|
-
# Select sub-menu first
|
14
|
-
CursesMenu::KEY_ENTER,
|
15
|
-
# Exit sub-menu
|
16
|
-
CursesMenu::KEY_ESCAPE,
|
17
|
-
# Navigate a bit
|
18
|
-
Curses::KEY_NPAGE,
|
19
|
-
Curses::KEY_HOME,
|
20
|
-
# Select last
|
21
|
-
Curses::KEY_END,
|
22
|
-
CursesMenu::KEY_ENTER
|
23
|
-
]
|
24
|
-
CursesMenu.new('Menu being used automatically', key_presses: keys) do |menu|
|
25
|
-
menu.item 'Simple item' do
|
26
|
-
puts 'Selected a simple item'
|
27
|
-
end
|
28
|
-
menu.item 'Several actions on this item', actions: {
|
29
|
-
'a' => {
|
30
|
-
name: 'Action A',
|
31
|
-
execute: proc { puts 'Selected action A' }
|
32
|
-
},
|
33
|
-
'b' => {
|
34
|
-
name: 'Action B',
|
35
|
-
execute: proc { puts 'Selected action B' }
|
36
|
-
}
|
37
|
-
}
|
38
|
-
menu.item 'Sub-menu' do
|
39
|
-
CursesMenu.new('Sub-menu!', key_presses: keys) do |sub_menu|
|
40
|
-
sub_menu.item 'Simple sub-menu item' do
|
41
|
-
puts 'Selected item from sub-menu'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
menu.item 'Quit' do
|
46
|
-
puts 'Quitting...'
|
47
|
-
:menu_exit
|
48
|
-
end
|
49
|
-
end
|
1
|
+
require 'curses_menu'
|
2
|
+
|
3
|
+
keys = [
|
4
|
+
# Select first
|
5
|
+
CursesMenu::KEY_ENTER,
|
6
|
+
# Select second
|
7
|
+
Curses::KEY_DOWN,
|
8
|
+
'a',
|
9
|
+
'b',
|
10
|
+
# Select third (sub-menu)
|
11
|
+
Curses::KEY_DOWN,
|
12
|
+
CursesMenu::KEY_ENTER,
|
13
|
+
# Select sub-menu first
|
14
|
+
CursesMenu::KEY_ENTER,
|
15
|
+
# Exit sub-menu
|
16
|
+
CursesMenu::KEY_ESCAPE,
|
17
|
+
# Navigate a bit
|
18
|
+
Curses::KEY_NPAGE,
|
19
|
+
Curses::KEY_HOME,
|
20
|
+
# Select last
|
21
|
+
Curses::KEY_END,
|
22
|
+
CursesMenu::KEY_ENTER
|
23
|
+
]
|
24
|
+
CursesMenu.new('Menu being used automatically', key_presses: keys) do |menu|
|
25
|
+
menu.item 'Simple item' do
|
26
|
+
puts 'Selected a simple item'
|
27
|
+
end
|
28
|
+
menu.item 'Several actions on this item', actions: {
|
29
|
+
'a' => {
|
30
|
+
name: 'Action A',
|
31
|
+
execute: proc { puts 'Selected action A' }
|
32
|
+
},
|
33
|
+
'b' => {
|
34
|
+
name: 'Action B',
|
35
|
+
execute: proc { puts 'Selected action B' }
|
36
|
+
}
|
37
|
+
}
|
38
|
+
menu.item 'Sub-menu' do
|
39
|
+
CursesMenu.new('Sub-menu!', key_presses: keys) do |sub_menu|
|
40
|
+
sub_menu.item 'Simple sub-menu item' do
|
41
|
+
puts 'Selected item from sub-menu'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
menu.item 'Quit' do
|
46
|
+
puts 'Quitting...'
|
47
|
+
:menu_exit
|
48
|
+
end
|
49
|
+
end
|
data/examples/formatting.rb
CHANGED
@@ -1,130 +1,148 @@
|
|
1
|
-
require 'curses_menu'
|
2
|
-
|
3
|
-
dynamic_row_1 = CursesMenu::CursesRow.new(
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
text: '
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
1
|
+
require 'curses_menu'
|
2
|
+
|
3
|
+
dynamic_row_1 = CursesMenu::CursesRow.new(
|
4
|
+
{
|
5
|
+
first_cell: { text: 'Select to' },
|
6
|
+
second_cell: {
|
7
|
+
text: 'change the',
|
8
|
+
color_pair: CursesMenu::COLORS_GREEN
|
9
|
+
},
|
10
|
+
third_cell: {
|
11
|
+
text: 'cells order',
|
12
|
+
color_pair: CursesMenu::COLORS_RED
|
13
|
+
}
|
14
|
+
}
|
15
|
+
)
|
16
|
+
dynamic_row_2 = CursesMenu::CursesRow.new(
|
17
|
+
{
|
18
|
+
first_cell: { text: 'Select to change' },
|
19
|
+
second_cell: {
|
20
|
+
text: 'the cells properties',
|
21
|
+
color_pair: CursesMenu::COLORS_GREEN,
|
22
|
+
fixed_size: 40
|
23
|
+
}
|
24
|
+
}
|
25
|
+
)
|
26
|
+
CursesMenu.new 'Extended formatting available too!' do |menu|
|
27
|
+
menu.item CursesMenu::CursesRow.new(
|
28
|
+
{
|
29
|
+
default_cell: {
|
30
|
+
text: 'Simple color change - GREEN!',
|
31
|
+
color_pair: CursesMenu::COLORS_GREEN
|
32
|
+
}
|
33
|
+
}
|
34
|
+
)
|
35
|
+
menu.item CursesMenu::CursesRow.new(
|
36
|
+
{
|
37
|
+
green_cell: {
|
38
|
+
text: 'Several cells ',
|
39
|
+
color_pair: CursesMenu::COLORS_GREEN
|
40
|
+
},
|
41
|
+
red_cell: {
|
42
|
+
text: 'with different ',
|
43
|
+
color_pair: CursesMenu::COLORS_RED
|
44
|
+
},
|
45
|
+
blue_cell: {
|
46
|
+
text: 'formatting',
|
47
|
+
color_pair: CursesMenu::COLORS_BLUE
|
48
|
+
}
|
49
|
+
}
|
50
|
+
)
|
51
|
+
menu.item CursesMenu::CursesRow.new(
|
52
|
+
{
|
53
|
+
default_cell: {
|
54
|
+
text: 'Use prefixes and suffixes',
|
55
|
+
begin_with: '[ ',
|
56
|
+
end_with: ' ]'
|
57
|
+
}
|
58
|
+
}
|
59
|
+
)
|
60
|
+
menu.item CursesMenu::CursesRow.new(
|
61
|
+
{
|
62
|
+
first_cell: {
|
63
|
+
text: 'This will have a fixed size!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!',
|
64
|
+
begin_with: '[ ',
|
65
|
+
end_with: ' ]',
|
66
|
+
fixed_size: 40
|
67
|
+
},
|
68
|
+
second_cell: {
|
69
|
+
text: 'And other cells will be aligned',
|
70
|
+
color_pair: CursesMenu::COLORS_GREEN
|
71
|
+
}
|
72
|
+
}
|
73
|
+
)
|
74
|
+
menu.item CursesMenu::CursesRow.new(
|
75
|
+
{
|
76
|
+
first_cell: {
|
77
|
+
text: 'Pretty nice',
|
78
|
+
fixed_size: 40
|
79
|
+
},
|
80
|
+
second_cell: {
|
81
|
+
text: 'for alignment',
|
82
|
+
color_pair: CursesMenu::COLORS_GREEN
|
83
|
+
}
|
84
|
+
}
|
85
|
+
)
|
86
|
+
menu.item CursesMenu::CursesRow.new(
|
87
|
+
{
|
88
|
+
first_cell: {
|
89
|
+
text: 'And you can justify',
|
90
|
+
justify: :right,
|
91
|
+
fixed_size: 40
|
92
|
+
},
|
93
|
+
second_cell: {
|
94
|
+
text: 'your text when size is fixed!',
|
95
|
+
justify: :left,
|
96
|
+
color_pair: CursesMenu::COLORS_GREEN
|
97
|
+
}
|
98
|
+
}
|
99
|
+
)
|
100
|
+
menu.item CursesMenu::CursesRow.new(
|
101
|
+
{
|
102
|
+
first_cell: {
|
103
|
+
text: 'You can even',
|
104
|
+
justify: :right,
|
105
|
+
fixed_size: 40,
|
106
|
+
pad: '_-'
|
107
|
+
},
|
108
|
+
second_cell: {
|
109
|
+
text: 'pad it!',
|
110
|
+
justify: :left,
|
111
|
+
color_pair: CursesMenu::COLORS_GREEN,
|
112
|
+
fixed_size: 40,
|
113
|
+
pad: '*'
|
114
|
+
}
|
115
|
+
}
|
116
|
+
)
|
117
|
+
menu.item CursesMenu::CursesRow.new(
|
118
|
+
{
|
119
|
+
first_cell: { text: 'Use a' },
|
120
|
+
second_cell: {
|
121
|
+
text: 'different separator',
|
122
|
+
color_pair: CursesMenu::COLORS_GREEN
|
123
|
+
},
|
124
|
+
third_cell: { text: 'between cells' }
|
125
|
+
},
|
126
|
+
separator: '|'
|
127
|
+
)
|
128
|
+
menu.item dynamic_row_1 do
|
129
|
+
dynamic_row_1.cells_order(%i[first_cell second_cell third_cell].sort_by { rand })
|
130
|
+
:menu_refresh
|
131
|
+
end
|
132
|
+
menu.item dynamic_row_2 do
|
133
|
+
dynamic_row_2.change_cells(
|
134
|
+
first_cell: {
|
135
|
+
color_pair: [CursesMenu::COLORS_GREEN, CursesMenu::COLORS_RED, CursesMenu::COLORS_BLUE].sample
|
136
|
+
},
|
137
|
+
second_cell: {
|
138
|
+
color_pair: [CursesMenu::COLORS_GREEN, CursesMenu::COLORS_RED, CursesMenu::COLORS_BLUE].sample,
|
139
|
+
pad: ['*', ' ', '|', '='].sample
|
140
|
+
}
|
141
|
+
)
|
142
|
+
:menu_refresh
|
143
|
+
end
|
144
|
+
menu.item 'Quit' do
|
145
|
+
puts 'Quitting...'
|
146
|
+
:menu_exit
|
147
|
+
end
|
148
|
+
end
|
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
|