menu_commander 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/menu_commander/exceptions.rb +17 -1
- data/lib/menu_commander/menu.rb +38 -5
- data/lib/menu_commander/version.rb +1 -1
- data/lib/menu_commander.rb +4 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac6321af9d45e46d217819d6659c88786ad23f6946d8c7f63076ed98ad8c3ba5
|
4
|
+
data.tar.gz: 650c78d949042c8a3651edad05bc82491fcd7b7095fc4b638b4e52dcfe9b0b74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d53c7fc17bd0ee211262624b0973d49eff0c433d5b819847989b211d452514e531d3183a662a9d1b878c916086a92b57ed3359d6b624a414cef470ee8f8410c2
|
7
|
+
data.tar.gz: 446c8c2a2f6d99af790e1f011251a6005a83173aec102b2b6bf792bcce57bd9dd343a9d5488ce969da5a1f956203f22cf475a056234092b737786f6b32a3ef40
|
data/README.md
CHANGED
@@ -13,6 +13,7 @@ Easily create menus for any command line tool using simple YAML configuration.
|
|
13
13
|
|
14
14
|
* [Installation](#installation)
|
15
15
|
* [Usage](#usage)
|
16
|
+
* [Menu Navigation](#menu-navigation)
|
16
17
|
* [Menu Configuration Features](#menu-configuration-features)
|
17
18
|
* [Minimal menu requirements](#minimal-menu-requirements)
|
18
19
|
* [Argument sub-menus](#argument-sub-menus)
|
@@ -67,9 +68,18 @@ $ menu
|
|
67
68
|
$ menu some-other-file
|
68
69
|
```
|
69
70
|
|
70
|
-
|
71
71
|
![Demo](/demo/demo.gif)
|
72
72
|
|
73
|
+
### Menu Navigation
|
74
|
+
|
75
|
+
- When a menu or sub menu has more than 10 items, it will become paginated
|
76
|
+
and a search filter will be added.
|
77
|
+
- Pressing <kbd>Home</kbd> from any nested menu will go back to the first
|
78
|
+
menu.
|
79
|
+
- Pressing <kbd>Page Up</kbd> from any nested menu will go back to the
|
80
|
+
previous menu.
|
81
|
+
|
82
|
+
|
73
83
|
|
74
84
|
Menu Configuration Features
|
75
85
|
--------------------------------------------------
|
@@ -7,11 +7,27 @@ module MenuCommander
|
|
7
7
|
# :nocov: - covered by external process
|
8
8
|
attr_reader :paths, :config
|
9
9
|
|
10
|
-
def initialize(message
|
10
|
+
def initialize(message=nil, paths: nil, config: nil)
|
11
11
|
message ||= "Could not find menu configuration file"
|
12
12
|
@paths, @config = paths, config
|
13
13
|
super message
|
14
14
|
end
|
15
15
|
# :nocov:
|
16
16
|
end
|
17
|
+
|
18
|
+
class ExitMenu < Interrupt
|
19
|
+
# :nocov:
|
20
|
+
def initialize(message=nil)
|
21
|
+
super (message || "> Exit")
|
22
|
+
end
|
23
|
+
# :nocov:
|
24
|
+
end
|
25
|
+
|
26
|
+
class MenuNavigation < StandardError
|
27
|
+
attr_reader :menu
|
28
|
+
|
29
|
+
def initialize(menu)
|
30
|
+
@menu = menu
|
31
|
+
end
|
32
|
+
end
|
17
33
|
end
|
data/lib/menu_commander/menu.rb
CHANGED
@@ -15,8 +15,13 @@ module MenuCommander
|
|
15
15
|
menu ||= config['menu']
|
16
16
|
response = select menu
|
17
17
|
response = combine_commands response if response.is_a? Array
|
18
|
-
|
18
|
+
|
19
|
+
history << menu
|
20
|
+
|
19
21
|
response.is_a?(String) ? evaluate(response) : call(response)
|
22
|
+
rescue MenuNavigation => e
|
23
|
+
call e.menu
|
24
|
+
|
20
25
|
end
|
21
26
|
|
22
27
|
def header
|
@@ -25,6 +30,10 @@ module MenuCommander
|
|
25
30
|
|
26
31
|
private
|
27
32
|
|
33
|
+
def history
|
34
|
+
@history ||= []
|
35
|
+
end
|
36
|
+
|
28
37
|
def combine_commands(command_array)
|
29
38
|
command_array.map { |cmd| "(#{cmd})" }.join ' && '
|
30
39
|
end
|
@@ -72,26 +81,50 @@ module MenuCommander
|
|
72
81
|
end
|
73
82
|
|
74
83
|
def prompt
|
75
|
-
@prompt ||=
|
84
|
+
@prompt ||= prompt!
|
85
|
+
end
|
86
|
+
|
87
|
+
def prompt!
|
88
|
+
result = TTY::Prompt.new
|
89
|
+
result.on(:keypress) { |event| handle_keypress event }
|
90
|
+
result
|
76
91
|
end
|
77
92
|
|
93
|
+
def handle_keypress(event)
|
94
|
+
case event.key.name
|
95
|
+
when :page_up
|
96
|
+
parent_menu = history.pop
|
97
|
+
raise MenuNavigation.new(parent_menu) if parent_menu
|
98
|
+
|
99
|
+
when :home
|
100
|
+
home_menu = history.first
|
101
|
+
if home_menu
|
102
|
+
@history = []
|
103
|
+
raise MenuNavigation.new(home_menu)
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
78
110
|
def ask(title)
|
79
111
|
prompt.ask "> #{title}:"
|
80
112
|
|
81
113
|
rescue TTY::Reader::InputInterrupt
|
82
114
|
# :nocov:
|
83
|
-
raise
|
115
|
+
raise ExitMenu
|
84
116
|
# :nocov:
|
85
117
|
|
86
118
|
end
|
87
119
|
|
88
120
|
def select(options, title=nil)
|
89
121
|
title = title ? "> #{title}:" : ">"
|
90
|
-
|
122
|
+
enable_filter = options.size > 10
|
123
|
+
prompt.select title, options, symbols: { marker: '>' }, per_page: 10, filter: enable_filter
|
91
124
|
|
92
125
|
rescue TTY::Reader::InputInterrupt
|
93
126
|
# :nocov:
|
94
|
-
raise
|
127
|
+
raise ExitMenu
|
95
128
|
# :nocov:
|
96
129
|
|
97
130
|
end
|
data/lib/menu_commander.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: menu_commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mister_bin
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
|
-
rubygems_version: 3.0.
|
103
|
+
rubygems_version: 3.0.3
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: Create menus for any CLI tool
|