curses_menu 0.0.1 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2226bebb142878eb4467c0471c3978f683746634acc51e6852f3b9298fbd3cf
4
- data.tar.gz: 23f6626cf28f160149106907a307cdc49ce64741f62ffb6053e16ad276267223
3
+ metadata.gz: d07858a5e2aad9b9633584a1e0b2c06b9a13ad5b69752ef7b4808ed614e7a889
4
+ data.tar.gz: 65f6f0b04deea7b529d136fe6fa3fea72fcfc98cfc0fc8d651863814a4bde162
5
5
  SHA512:
6
- metadata.gz: 31d298f6320962b6061936eff73ba7a517f10c0ec0b8b681455ae71df372b8ef5e0ee674d598fe094c76de18531a1d4a3a07b58ae2d405a6112a03b00bfd5275
7
- data.tar.gz: 6f49adde82fac8dfd6e7f513184735b3f9e9f0024857b00604b9180bd926659a1a9ddece7ef112ad671f1921d60c236204359c8d6fe361a491c9fe393a31cd4f
6
+ metadata.gz: f322978d91a509bf1696d1da056f65a7dc097bf65e61ebf46194c1bc555dad59caadadd8cca9f2c5b8bf4aea87a0d086a22555b8084e06c6a15c56c5a9ccd3f3
7
+ data.tar.gz: 744ed073c7e764068f3b97a528255371b70dedd99c1d164e4cc2f8981069dfd8e1ec5c606df74f3b4df00c232d3995cd31037c53401fc7bc092b1e6313da596a
data/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # [v0.0.5](https://github.com/Muriel-Salvan/curses_menu/compare/v0.0.4...v0.0.5) (2021-08-18 11:48:24)
2
+
3
+ ### Patches
4
+
5
+ * [[Hotfix] Add Windows support](https://github.com/Muriel-Salvan/curses_menu/commit/b47b51a79988363c0e292987fe4a97dd6f05c6d8)
6
+
7
+ # [v0.0.4](https://github.com/Muriel-Salvan/curses_menu/compare/v0.0.3...v0.0.4) (2021-08-18 10:25:59)
8
+
9
+ ### Patches
10
+
11
+ * [Test UTF-8 support](https://github.com/Muriel-Salvan/curses_menu/commit/f94129db540d41f17f0ed46563461601f140029f)
12
+
13
+ # [v0.0.3](https://github.com/Muriel-Salvan/curses_menu/compare/v0.0.2...v0.0.3) (2021-08-15 16:16:16)
14
+
15
+ ### Patches
16
+
17
+ * [Add the spec direcotry in the gem as it contains files that can be useful to users](https://github.com/Muriel-Salvan/curses_menu/commit/aeb73ea4507029be97dba2d8243fa3e33ac151ba)
18
+
19
+ # [v0.0.2](https://github.com/Muriel-Salvan/curses_menu/compare/v0.0.1...v0.0.2) (2021-08-15 15:24:19)
20
+
21
+ ### Patches
22
+
23
+ * [Added colors testing + Proper CI/CD + Ruby 3 compatibility](https://github.com/Muriel-Salvan/curses_menu/commit/035b19fc27a61c9d10c6b5517993dd0f54537eec)
24
+ * [Add white colors](https://github.com/Muriel-Salvan/curses_menu/commit/5adf552c01f7a254621e53ecd45e04e9c2358bb8)
25
+
26
+ # 0.0.1
27
+
28
+ * Initial version
data/LICENSE.md ADDED
@@ -0,0 +1,31 @@
1
+
2
+ The license stated herein is a copy of the BSD License (modified on July 1999).
3
+ The AUTHOR mentionned below refers to the list of people involved in the
4
+ creation and modification of any file included in the delivered package.
5
+ This list is found in the file named AUTHORS.
6
+ The AUTHORS and LICENSE files have to be included in any release of software
7
+ embedding source code of this package, or using it as a derivative software.
8
+
9
+ Copyright (c) 2019 - 2019 Muriel Salvan (muriel@x-aeon.com)
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright notice,
15
+ this list of conditions and the following disclaimer.
16
+ 2. Redistributions in binary form must reproduce the above copyright notice,
17
+ this list of conditions and the following disclaimer in the documentation
18
+ and/or other materials provided with the distribution.
19
+ 3. The name of the author may not be used to endorse or promote products
20
+ derived from this software without specific prior written permission.
21
+
22
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25
+ EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31
+ OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # curses_menu
2
+
3
+ Ruby API to create terminal-based menus, using [curses][link-curses].
4
+
5
+ * Easy navigation using arrows, page up/down, home, end, enter and escape keys.
6
+ * Several actions per menu item.
7
+ * Scrolling support.
8
+ * Extensive formatting options with colors, alignments, decorations...
9
+ * Easy support for sub-menus.
10
+ * Automatic key presses for autmating tasks in the menu.
11
+ * Ruby-like API.
12
+
13
+ ## Install
14
+
15
+ Via gem
16
+
17
+ ``` bash
18
+ $ gem install curses_menu
19
+ ```
20
+
21
+ Via a Gemfile
22
+
23
+ ``` ruby
24
+ $ gem 'curses_menu'
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ``` ruby
30
+ require 'curses_menu'
31
+
32
+ CursesMenu.new 'My awesome new menu!' do |menu|
33
+ menu.item 'How\'s life?' do
34
+ puts 'Couldn\'t be easier'
35
+ :menu_exit
36
+ end
37
+ end
38
+ ```
39
+
40
+ Check the [examples][link-examples] folder for more examples.
41
+
42
+ ## Change log
43
+
44
+ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
45
+
46
+ ## Testing
47
+
48
+ Automated tests are done using rspec.
49
+
50
+ Do execute them, first install development dependencies:
51
+
52
+ ```bash
53
+ bundle install
54
+ ```
55
+
56
+ Then execute rspec
57
+
58
+ ```bash
59
+ bundle exec rspec
60
+ ```
61
+
62
+ ## Contributing
63
+
64
+ Any contribution is welcome:
65
+ * Fork the github project and create pull requests.
66
+ * Report bugs by creating tickets.
67
+ * Suggest improvements and new features by creating tickets.
68
+
69
+ ## Credits
70
+
71
+ - [Muriel Salvan][link-author]
72
+
73
+ ## License
74
+
75
+ The BSD License. Please see [License File](LICENSE.md) for more information.
76
+
77
+ [link-curses]: https://rubygems.org/gems/curses/versions/1.2.4
78
+ [link-examples]: ./examples
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
@@ -1,130 +1,148 @@
1
- require 'curses_menu'
2
-
3
- dynamic_row_1 = CursesMenu::CursesRow.new(
4
- first_cell: { text: 'Select to' },
5
- second_cell: {
6
- text: 'change the',
7
- color_pair: CursesMenu::COLORS_GREEN
8
- },
9
- third_cell: {
10
- text: 'cells order',
11
- color_pair: CursesMenu::COLORS_RED
12
- }
13
- )
14
- dynamic_row_2 = CursesMenu::CursesRow.new(
15
- first_cell: { text: 'Select to change' },
16
- second_cell: {
17
- text: 'the cells properties',
18
- color_pair: CursesMenu::COLORS_GREEN,
19
- fixed_size: 40
20
- }
21
- )
22
- CursesMenu.new 'Extended formatting available too!' do |menu|
23
- menu.item CursesMenu::CursesRow.new(
24
- default_cell: {
25
- text: 'Simple color change - GREEN!',
26
- color_pair: CursesMenu::COLORS_GREEN
27
- }
28
- )
29
- menu.item CursesMenu::CursesRow.new(
30
- green_cell: {
31
- text: 'Several cells ',
32
- color_pair: CursesMenu::COLORS_GREEN
33
- },
34
- red_cell: {
35
- text: 'with different ',
36
- color_pair: CursesMenu::COLORS_RED
37
- },
38
- blue_cell: {
39
- text: 'formatting',
40
- color_pair: CursesMenu::COLORS_BLUE
41
- }
42
- )
43
- menu.item CursesMenu::CursesRow.new(
44
- default_cell: {
45
- text: 'Use prefixes and suffixes',
46
- begin_with: '[ ',
47
- end_with: ' ]'
48
- }
49
- )
50
- menu.item CursesMenu::CursesRow.new(
51
- first_cell: {
52
- text: 'This will have a fixed size!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!',
53
- begin_with: '[ ',
54
- end_with: ' ]',
55
- fixed_size: 40
56
- },
57
- second_cell: {
58
- text: 'And other cells will be aligned',
59
- color_pair: CursesMenu::COLORS_GREEN
60
- }
61
- )
62
- menu.item CursesMenu::CursesRow.new(
63
- first_cell: {
64
- text: 'Pretty nice',
65
- fixed_size: 40
66
- },
67
- second_cell: {
68
- text: 'for alignment',
69
- color_pair: CursesMenu::COLORS_GREEN
70
- }
71
- )
72
- menu.item CursesMenu::CursesRow.new(
73
- first_cell: {
74
- text: 'And you can justify',
75
- justify: :right,
76
- fixed_size: 40
77
- },
78
- second_cell: {
79
- text: 'your text when size is fixed!',
80
- justify: :left,
81
- color_pair: CursesMenu::COLORS_GREEN
82
- }
83
- )
84
- menu.item CursesMenu::CursesRow.new(
85
- first_cell: {
86
- text: 'You can even',
87
- justify: :right,
88
- fixed_size: 40,
89
- pad: '_-'
90
- },
91
- second_cell: {
92
- text: 'pad it!',
93
- justify: :left,
94
- color_pair: CursesMenu::COLORS_GREEN,
95
- fixed_size: 40,
96
- pad: '*'
97
- }
98
- )
99
- menu.item CursesMenu::CursesRow.new(
100
- {
101
- first_cell: { text: 'Use a' },
102
- second_cell: {
103
- text: 'different separator',
104
- color_pair: CursesMenu::COLORS_GREEN
105
- },
106
- third_cell: { text: 'between cells' }
107
- },
108
- separator: '|'
109
- )
110
- menu.item dynamic_row_1 do
111
- dynamic_row_1.cells_order([:first_cell, :second_cell, :third_cell].sort_by { rand })
112
- :menu_refresh
113
- end
114
- menu.item dynamic_row_2 do
115
- dynamic_row_2.change_cells(
116
- first_cell: {
117
- color_pair: [CursesMenu::COLORS_GREEN, CursesMenu::COLORS_RED, CursesMenu::COLORS_BLUE].sample
118
- },
119
- second_cell: {
120
- color_pair: [CursesMenu::COLORS_GREEN, CursesMenu::COLORS_RED, CursesMenu::COLORS_BLUE].sample,
121
- pad: ['*', ' ', '|', '='].sample
122
- }
123
- )
124
- :menu_refresh
125
- end
126
- menu.item 'Quit' do
127
- puts 'Quitting...'
128
- :menu_exit
129
- end
130
- end
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