inquirer.rb 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/README.md +10 -4
- data/examples/checkbox.rb +8 -0
- data/examples/list.rb +8 -0
- data/lib/inquirer.rb +2 -0
- data/lib/inquirer/prompts/checkbox.rb +13 -0
- data/lib/inquirer/prompts/list.rb +15 -0
- data/lib/inquirer/utils/iohelper.rb +11 -0
- data/lib/inquirer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d0c59415e69c915f7f8e20f566a096e2218d5b9
|
4
|
+
data.tar.gz: c702cf48d146f65dd677b39b10eba81b176bc1f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27fef9a176a7c1d0f7359c0a4381831f70f8b552db4a8a7bba90d7af4f7f44435b9eb81560fdb415f69e5c9b20cee0c43cd9b9fd011c440e8306dba33772b16f
|
7
|
+
data.tar.gz: 82c9bdffd2f961f23a7b924cffc2e8311799a13db1dc1d64fde751ddea4d1d96de359bc91d42cf2bd94fc7e2117ce8944538b986c8d5f03ea74d08426eed7168
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# inquirer.rb
|
2
2
|
|
3
|
-
A collection of common interactive command line user interfaces. A (not yet
|
3
|
+
A collection of common interactive command line user interfaces. A (not yet completed) clone of the great [Inquirer.js](https://github.com/SBoudrias/Inquirer.js) and strongly inspired by the similar [inquirer.rb](https://github.com/arlimus/inquirer.rb).
|
4
4
|
|
5
5
|
Started as a fork of [inquirer.rb](https://github.com/arlimus/inquirer.rb) the changes become to fundamental to keep it that way.
|
6
6
|
|
@@ -16,7 +16,7 @@ Started as a fork of [inquirer.rb](https://github.com/arlimus/inquirer.rb) the c
|
|
16
16
|
Add this line to your application's Gemfile:
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
gem 'inquirer'
|
19
|
+
gem 'inquirer.rb'
|
20
20
|
```
|
21
21
|
|
22
22
|
And then execute:
|
@@ -25,7 +25,7 @@ And then execute:
|
|
25
25
|
|
26
26
|
Or install it yourself as:
|
27
27
|
|
28
|
-
$ gem install inquirer
|
28
|
+
$ gem install inquirer.rb
|
29
29
|
|
30
30
|
## Usage
|
31
31
|
|
@@ -85,6 +85,7 @@ There parameters are valid for all prompt types:
|
|
85
85
|
- `:name` (String) The display value
|
86
86
|
- `:short` (String) (optional) To display after selection
|
87
87
|
- `:value` (String|Symbol) To save in the answers Hash
|
88
|
+
- `:when` (Proc|Boolean) (optional) Should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.
|
88
89
|
- `:default` (Integer|String|Symbol) (optional) Must be the choice index (Integer) in the Array or a choice `:value` parameters value (String|Symbol).
|
89
90
|
|
90
91
|
#### Checkbox (`type: :checkbox`)
|
@@ -96,6 +97,7 @@ There parameters are valid for all prompt types:
|
|
96
97
|
- `:short` (String) (optional) To display after selection
|
97
98
|
- `:value` (String|Symbol) To save in the answers Hash
|
98
99
|
- `:checked` (Boolean) (optional) True choices will be checked by default
|
100
|
+
- `:when` (Proc|Boolean) (optional) Should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.
|
99
101
|
- `:default` (Array) (optional) An Array of choices `:value` parameters values (String|Symbol).
|
100
102
|
- `:validate` (Proc) (optional) Receive the user input and should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
|
101
103
|
|
@@ -143,6 +145,8 @@ There parameters are valid for all prompt types:
|
|
143
145
|
- [x] `:choices` `:name` parameter (InquirerJS conform)
|
144
146
|
- [x] `:choices` `:value` parameter (InquirerJS conform)
|
145
147
|
- [x] `:choices` `:short` parameter (InquirerJS conform)
|
148
|
+
- [x] `:choices` `:when` (Proc) parameter
|
149
|
+
- [x] `:choices` `:when` (Boolean) parameter
|
146
150
|
- [x] `:validate` (Proc) parameter (optional) (InquirerJS conform)
|
147
151
|
- [ ] Tests
|
148
152
|
|
@@ -154,6 +158,8 @@ There parameters are valid for all prompt types:
|
|
154
158
|
- [x] `:choices` `:name` parameter (InquirerJS conform)
|
155
159
|
- [x] `:choices` `:value` parameter (InquirerJS conform)
|
156
160
|
- [x] `:choices` `:checked` parameter (InquirerJS conform)
|
161
|
+
- [x] `:choices` `:when` (Proc) parameter
|
162
|
+
- [x] `:choices` `:when` (Boolean) parameter
|
157
163
|
- [ ] `:choices` `:disabled` (String) parameter (InquirerJS conform)
|
158
164
|
- [ ] `:choices` `:disabled` (Boolean) parameter (InquirerJS conform)
|
159
165
|
- [ ] `:choices` `:disabled` (Proc) parameter (InquirerJS conform)
|
data/examples/checkbox.rb
CHANGED
data/examples/list.rb
CHANGED
data/lib/inquirer.rb
CHANGED
@@ -18,6 +18,19 @@ module Checkbox
|
|
18
18
|
@choices = []
|
19
19
|
opts[:choices].each { |choice|
|
20
20
|
|
21
|
+
if choice[:when].is_a?(Proc)
|
22
|
+
|
23
|
+
when_parameter = opts.merge(
|
24
|
+
choice: choice,
|
25
|
+
)
|
26
|
+
|
27
|
+
ask_choice = choice[:when].call( when_parameter )
|
28
|
+
|
29
|
+
next if !ask_choice
|
30
|
+
elsif [true, false].include? choice[:when]
|
31
|
+
next if !choice[:when]
|
32
|
+
end
|
33
|
+
|
21
34
|
choice[:value] ||= choice[:name]
|
22
35
|
|
23
36
|
if !choice[:checked] && opts[:default].is_a?(Array)
|
@@ -17,6 +17,19 @@ module List
|
|
17
17
|
@choices = []
|
18
18
|
opts[:choices].each { |choice|
|
19
19
|
|
20
|
+
if choice[:when].is_a?(Proc)
|
21
|
+
|
22
|
+
when_parameter = opts.merge(
|
23
|
+
choice: choice,
|
24
|
+
)
|
25
|
+
|
26
|
+
ask_choice = choice[:when].call( when_parameter )
|
27
|
+
|
28
|
+
next if !ask_choice
|
29
|
+
elsif [true, false].include? choice[:when]
|
30
|
+
next if !choice[:when]
|
31
|
+
end
|
32
|
+
|
20
33
|
choice[:value] ||= choice[:name]
|
21
34
|
|
22
35
|
@choices.push(choice)
|
@@ -24,6 +37,8 @@ module List
|
|
24
37
|
|
25
38
|
return nil if Array(@choices).empty?
|
26
39
|
|
40
|
+
return @choices[0][:value] if @choices.size == 1
|
41
|
+
|
27
42
|
if default.is_a?(String) || default.is_a?(Symbol)
|
28
43
|
@position = @choices.find_index { |choice| choice[:value] == default }
|
29
44
|
@position ||= 0
|
@@ -65,10 +65,17 @@ module IOHelper
|
|
65
65
|
print IOChar.newline * lines + @bottomline + IOChar.cursor_left * @bottomline.size + IOChar.cursor_up * lines
|
66
66
|
end
|
67
67
|
print @rendered
|
68
|
+
|
69
|
+
plain_last_line = plain_chars(@rendered.lines.last)
|
70
|
+
print IOChar.newline + IOChar.cursor_up + IOChar.cursor_right * plain_last_line.length
|
68
71
|
end
|
69
72
|
|
70
73
|
# clear the console based on the last text rendered
|
71
74
|
def clear
|
75
|
+
|
76
|
+
# remove the trailing newline, otherwise an upper line will get eaten
|
77
|
+
@rendered.sub!(/\n\z/, '')
|
78
|
+
|
72
79
|
# determine how many lines to move up
|
73
80
|
lines = @rendered.scan(/\n/).length
|
74
81
|
|
@@ -120,4 +127,8 @@ module IOHelper
|
|
120
127
|
|
121
128
|
result + IOChar.clear_line
|
122
129
|
end
|
130
|
+
|
131
|
+
def plain_chars(string)
|
132
|
+
string.gsub(/\e\[([;\dA-Z]+)?m?/, '')
|
133
|
+
end
|
123
134
|
end
|
data/lib/inquirer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inquirer.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thorsten Eckel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|