tty-prompt 0.19.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +13 -5
- data/examples/ask_multiline.rb +7 -0
- data/lib/tty/prompt.rb +15 -10
- data/lib/tty/prompt/answers_collector.rb +3 -3
- data/lib/tty/prompt/choice.rb +3 -3
- data/lib/tty/prompt/confirm_question.rb +15 -4
- data/lib/tty/prompt/multiline.rb +1 -1
- data/lib/tty/prompt/question.rb +1 -1
- data/lib/tty/prompt/question/validation.rb +3 -3
- data/lib/tty/prompt/suggestion.rb +1 -1
- data/lib/tty/prompt/version.rb +1 -1
- data/spec/unit/ask_spec.rb +2 -2
- data/spec/unit/block_paginator_spec.rb +7 -7
- data/spec/unit/choice/from_spec.rb +18 -0
- data/spec/unit/paginator_spec.rb +7 -7
- data/spec/unit/select_spec.rb +1 -1
- data/spec/unit/yes_no_spec.rb +34 -0
- data/tty-prompt.gemspec +11 -2
- metadata +13 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c931430d3e829a2006e67517b24605d5761d401ab04824e6c1c26f33dee2253a
|
4
|
+
data.tar.gz: b5a4b0bbe4ffe080719074bca1d9ef59f6c55490a3b1832aa8bfa3c7f045ab0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2daf65290416154a3734d22a08b3e3d93b518c963f5b735282835dd362ff6380c81cf0d1c5822d207eb3ff3b2717f3633fb82ab9941f0854849b893b775bc24
|
7
|
+
data.tar.gz: 1aaeb2c66b87133c54d353a305d3798629f5b953ac4dd09971a3789f0647d97dec2dd4ae811d4dc7f4e07775eef9e1803aeb80e6829a8a8b40d3d9f32fabf1ab
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.20.0] - 2019-11-24
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change to update tty-reader dependency
|
7
|
+
* Change gemspec to include metadata
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
* Fix Choice#from to differentiate between nil and false by Katelyn Schiesser(@slowbro)
|
11
|
+
* Fix yes? and no? prompts to stop raising on invalid/blank input by Katelyn Schiesser(@slowbro)
|
12
|
+
* Fix Ruby 2.7 keyword arguments warnings
|
13
|
+
* Fix question validation to work with nil input
|
14
|
+
|
3
15
|
## [v0.19.0] - 2019-05-27
|
4
16
|
|
5
17
|
### Added
|
@@ -326,6 +338,7 @@
|
|
326
338
|
|
327
339
|
* Initial implementation and release
|
328
340
|
|
341
|
+
[v0.20.0]: https://github.com/piotrmurach/tty-prompt/compare/v0.19.0...v0.20.0
|
329
342
|
[v0.19.0]: https://github.com/piotrmurach/tty-prompt/compare/v0.18.1...v0.19.0
|
330
343
|
[v0.18.1]: https://github.com/piotrmurach/tty-prompt/compare/v0.18.0...v0.18.1
|
331
344
|
[v0.18.0]: https://github.com/piotrmurach/tty-prompt/compare/v0.17.2...v0.18.0
|
data/README.md
CHANGED
@@ -116,6 +116,8 @@ Or install it yourself as:
|
|
116
116
|
In order to start asking questions on the command line, create prompt:
|
117
117
|
|
118
118
|
```ruby
|
119
|
+
require "tty-prompt"
|
120
|
+
|
119
121
|
prompt = TTY::Prompt.new
|
120
122
|
```
|
121
123
|
|
@@ -374,7 +376,7 @@ prompt.ask("What's your phone number?", required: true)
|
|
374
376
|
|
375
377
|
#### 2.1.9 validate
|
376
378
|
|
377
|
-
In order to validate that input matches a given
|
379
|
+
In order to validate that input matches a given pattern you can pass the `validate` option. Validate setting accepts `Regex`, `Proc` or `Symbol`.
|
378
380
|
|
379
381
|
```ruby
|
380
382
|
prompt.ask('What is your username?') do |q|
|
@@ -384,7 +386,7 @@ end
|
|
384
386
|
|
385
387
|
The **TTY::Prompt** comes with built-in validations for `:email` and you can use them directly like so:
|
386
388
|
|
387
|
-
```
|
389
|
+
```ruby
|
388
390
|
prompt.ask('What is your email?') { |q| q.validate :email }
|
389
391
|
```
|
390
392
|
|
@@ -716,14 +718,20 @@ prompt.select("Choose your letter?", letters, per_page: 4)
|
|
716
718
|
# D
|
717
719
|
```
|
718
720
|
|
719
|
-
You can also customise page navigation text using `:
|
721
|
+
You can also customise page navigation text using `:help` option:
|
720
722
|
```ruby
|
721
723
|
letters = ('A'..'Z').to_a
|
722
724
|
prompt.select("Choose your letter?") do |menu|
|
723
725
|
menu.per_page 4
|
724
|
-
menu.
|
726
|
+
menu.help '(Wiggle thy finger up/down and left/right to see more)'
|
725
727
|
menu.choices letters
|
726
728
|
end
|
729
|
+
# =>
|
730
|
+
# Which letter? (Wiggle thy finger up/down and left/right to see more)
|
731
|
+
# ‣ A
|
732
|
+
# B
|
733
|
+
# C
|
734
|
+
# D
|
727
735
|
```
|
728
736
|
|
729
737
|
#### 2.6.2.2 `:disabled`
|
@@ -1210,7 +1218,7 @@ end
|
|
1210
1218
|
|
1211
1219
|
In order to collect _mutliple values_ for a given key in a loop, chain `values` onto the `key` desired:
|
1212
1220
|
|
1213
|
-
```
|
1221
|
+
```ruby
|
1214
1222
|
result = prompt.collect do
|
1215
1223
|
key(:name).ask('Name?')
|
1216
1224
|
|
data/lib/tty/prompt.rb
CHANGED
@@ -86,7 +86,7 @@ module TTY
|
|
86
86
|
def_delegators :@cursor, :clear_lines, :clear_line,
|
87
87
|
:show, :hide
|
88
88
|
|
89
|
-
def_delegators :@reader, :read_char, :
|
89
|
+
def_delegators :@reader, :read_char, :read_keypress, # :read_line,
|
90
90
|
:read_multiline, :on, :subscribe, :unsubscribe, :trigger,
|
91
91
|
:count_screen_lines
|
92
92
|
|
@@ -100,6 +100,11 @@ module TTY
|
|
100
100
|
}
|
101
101
|
end
|
102
102
|
|
103
|
+
# This fixes Forwardable module keyword arguments warning
|
104
|
+
def read_line(message, **options)
|
105
|
+
@reader.read_line(message, **options)
|
106
|
+
end
|
107
|
+
|
103
108
|
# Initialize a Prompt
|
104
109
|
#
|
105
110
|
# @param [Hash] options
|
@@ -163,7 +168,7 @@ module TTY
|
|
163
168
|
# @api public
|
164
169
|
def invoke_question(object, message, **options, &block)
|
165
170
|
options[:messages] = self.class.messages
|
166
|
-
question = object.new(self, options)
|
171
|
+
question = object.new(self, **options)
|
167
172
|
question.(message, &block)
|
168
173
|
end
|
169
174
|
|
@@ -233,7 +238,7 @@ module TTY
|
|
233
238
|
args.flatten
|
234
239
|
end
|
235
240
|
|
236
|
-
list = object.new(self, options)
|
241
|
+
list = object.new(self, **options)
|
237
242
|
list.(question, choices, &block)
|
238
243
|
end
|
239
244
|
|
@@ -330,7 +335,7 @@ module TTY
|
|
330
335
|
options = Utils.extract_options!(args)
|
331
336
|
options.merge!(defaults.reject { |k, _| options.key?(k) })
|
332
337
|
|
333
|
-
question = ConfirmQuestion.new(self, options)
|
338
|
+
question = ConfirmQuestion.new(self, **options)
|
334
339
|
question.call(message, &block)
|
335
340
|
end
|
336
341
|
|
@@ -350,7 +355,7 @@ module TTY
|
|
350
355
|
options = Utils.extract_options!(args)
|
351
356
|
options.merge!(defaults.reject { |k, _| options.key?(k) })
|
352
357
|
|
353
|
-
question = ConfirmQuestion.new(self, options)
|
358
|
+
question = ConfirmQuestion.new(self, **options)
|
354
359
|
!question.call(message, &block)
|
355
360
|
end
|
356
361
|
|
@@ -391,7 +396,7 @@ module TTY
|
|
391
396
|
# @api public
|
392
397
|
def slider(question, *args, &block)
|
393
398
|
options = Utils.extract_options!(args)
|
394
|
-
slider = Slider.new(self, options)
|
399
|
+
slider = Slider.new(self, **options)
|
395
400
|
slider.call(question, &block)
|
396
401
|
end
|
397
402
|
|
@@ -506,8 +511,8 @@ module TTY
|
|
506
511
|
# @return [String]
|
507
512
|
#
|
508
513
|
# @api public
|
509
|
-
def suggest(message, possibilities, options
|
510
|
-
suggestion = Suggestion.new(options)
|
514
|
+
def suggest(message, possibilities, **options)
|
515
|
+
suggestion = Suggestion.new(**options)
|
511
516
|
say(suggestion.suggest(message, possibilities))
|
512
517
|
end
|
513
518
|
|
@@ -522,8 +527,8 @@ module TTY
|
|
522
527
|
# the collection of answers
|
523
528
|
#
|
524
529
|
# @api public
|
525
|
-
def collect(options
|
526
|
-
collector = AnswersCollector.new(self, options)
|
530
|
+
def collect(**options, &block)
|
531
|
+
collector = AnswersCollector.new(self, **options)
|
527
532
|
collector.call(&block)
|
528
533
|
end
|
529
534
|
|
@@ -6,7 +6,7 @@ module TTY
|
|
6
6
|
# Initialize answer collector
|
7
7
|
#
|
8
8
|
# @api public
|
9
|
-
def initialize(prompt, options
|
9
|
+
def initialize(prompt, **options)
|
10
10
|
@prompt = prompt
|
11
11
|
@answers = options.fetch(:answers) { {} }
|
12
12
|
end
|
@@ -69,8 +69,8 @@ module TTY
|
|
69
69
|
private
|
70
70
|
|
71
71
|
# @api private
|
72
|
-
def method_missing(method, *args, &block)
|
73
|
-
answer = @prompt.public_send(method, *args, &block)
|
72
|
+
def method_missing(method, *args, **options, &block)
|
73
|
+
answer = @prompt.public_send(method, *args, **options, &block)
|
74
74
|
add_answer(answer)
|
75
75
|
end
|
76
76
|
end # AnswersCollector
|
data/lib/tty/prompt/choice.rb
CHANGED
@@ -35,7 +35,7 @@ module TTY
|
|
35
35
|
if name.is_a?(Hash)
|
36
36
|
convert_hash(name)
|
37
37
|
else
|
38
|
-
new(name.to_s, value
|
38
|
+
new(name.to_s, (value.nil? ? name.to_s : value), **(options || {}))
|
39
39
|
end
|
40
40
|
when Hash
|
41
41
|
convert_hash(val)
|
@@ -49,9 +49,9 @@ module TTY
|
|
49
49
|
# @api public
|
50
50
|
def self.convert_hash(val)
|
51
51
|
if val.key?(:name) && val.key?(:value)
|
52
|
-
new(val[:name].to_s, val[:value], val)
|
52
|
+
new(val[:name].to_s, val[:value], **val)
|
53
53
|
elsif val.key?(:name)
|
54
|
-
new(val[:name].to_s, val[:name].to_s, val)
|
54
|
+
new(val[:name].to_s, val[:name].to_s, **val)
|
55
55
|
else
|
56
56
|
new(val.keys.first.to_s, val.values.first)
|
57
57
|
end
|
@@ -14,7 +14,7 @@ module TTY
|
|
14
14
|
# @option options [String] :negative
|
15
15
|
#
|
16
16
|
# @api public
|
17
|
-
def initialize(prompt, options
|
17
|
+
def initialize(prompt, **options)
|
18
18
|
super
|
19
19
|
@suffix = options.fetch(:suffix) { UndefinedSetting }
|
20
20
|
@positive = options.fetch(:positive) { UndefinedSetting }
|
@@ -85,21 +85,30 @@ module TTY
|
|
85
85
|
|
86
86
|
protected
|
87
87
|
|
88
|
+
# Decide how to handle input from user
|
89
|
+
#
|
90
|
+
# @api private
|
91
|
+
def process_input(question)
|
92
|
+
@input = read_input(question)
|
93
|
+
if Utils.blank?(@input)
|
94
|
+
@input = default ? positive : negative
|
95
|
+
end
|
96
|
+
@evaluator.call(@input)
|
97
|
+
end
|
98
|
+
|
88
99
|
# @api private
|
89
100
|
def setup_defaults
|
101
|
+
@convert = conversion
|
90
102
|
return if suffix? && positive?
|
91
103
|
|
92
104
|
if suffix? && (!positive? || !negative?)
|
93
105
|
parts = @suffix.split('/')
|
94
106
|
@positive = parts[0]
|
95
107
|
@negative = parts[1]
|
96
|
-
@convert = conversion
|
97
108
|
elsif !suffix? && positive?
|
98
109
|
@suffix = create_suffix
|
99
|
-
@convert = conversion
|
100
110
|
else
|
101
111
|
create_default_labels
|
102
|
-
@convert = :bool
|
103
112
|
end
|
104
113
|
end
|
105
114
|
|
@@ -108,6 +117,8 @@ module TTY
|
|
108
117
|
@suffix = default ? 'Y/n' : 'y/N'
|
109
118
|
@positive = default ? 'Yes' : 'yes'
|
110
119
|
@negative = default ? 'no' : 'No'
|
120
|
+
@validation = /^(y(es)?|no?)$/i
|
121
|
+
@messages[:valid?] = "Invalid input."
|
111
122
|
end
|
112
123
|
|
113
124
|
# @api private
|
data/lib/tty/prompt/multiline.rb
CHANGED
data/lib/tty/prompt/question.rb
CHANGED
@@ -57,11 +57,11 @@ module TTY
|
|
57
57
|
def call(input)
|
58
58
|
if pattern.is_a?(String) || pattern.is_a?(Symbol)
|
59
59
|
VALIDATORS.key?(pattern.to_sym)
|
60
|
-
!VALIDATORS[pattern.to_sym].match(input).nil?
|
60
|
+
!VALIDATORS[pattern.to_sym].match(input.to_s).nil?
|
61
61
|
elsif pattern.is_a?(Regexp)
|
62
|
-
!pattern.match(input).nil?
|
62
|
+
!pattern.match(input.to_s).nil?
|
63
63
|
elsif pattern.is_a?(Proc)
|
64
|
-
result = pattern.call(input)
|
64
|
+
result = pattern.call(input.to_s)
|
65
65
|
result.nil? ? false : result
|
66
66
|
else false
|
67
67
|
end
|
@@ -33,7 +33,7 @@ module TTY
|
|
33
33
|
# Initialize a Suggestion
|
34
34
|
#
|
35
35
|
# @api public
|
36
|
-
def initialize(options
|
36
|
+
def initialize(**options)
|
37
37
|
@indent = options.fetch(:indent) { DEFAULT_INDENT }
|
38
38
|
@single_text = options.fetch(:single_text) { SINGLE_TEXT }
|
39
39
|
@plural_text = options.fetch(:plural_text) { PLURAL_TEXT }
|
data/lib/tty/prompt/version.rb
CHANGED
data/spec/unit/ask_spec.rb
CHANGED
@@ -99,7 +99,7 @@ RSpec.describe TTY::Prompt, '#ask' do
|
|
99
99
|
prompt.input << ''
|
100
100
|
prompt.input.rewind
|
101
101
|
options = {default: 'Piotr', help_color: :red, active_color: :cyan}
|
102
|
-
answer = prompt.ask("What is your name?", options)
|
102
|
+
answer = prompt.ask("What is your name?", **options)
|
103
103
|
expect(answer).to eq('Piotr')
|
104
104
|
expect(prompt.output.string).to eq([
|
105
105
|
"What is your name? \e[31m(Piotr)\e[0m ",
|
@@ -147,7 +147,7 @@ RSpec.describe TTY::Prompt, '#ask' do
|
|
147
147
|
prompt.input << "Piotr\r"
|
148
148
|
prompt.input.rewind
|
149
149
|
local_settings = {prefix: ':-) ', active_color: :blue, help_color: :magenta}
|
150
|
-
prompt.ask('What is your name?', local_settings)
|
150
|
+
prompt.ask('What is your name?', **local_settings)
|
151
151
|
|
152
152
|
expect(prompt.output.string).to eq([
|
153
153
|
"[?] What is your name? ",
|
@@ -3,7 +3,7 @@
|
|
3
3
|
RSpec.describe TTY::Prompt::BlockPaginator, '#paginate' do
|
4
4
|
it "ignores per_page when equal items " do
|
5
5
|
list = %w(a b c d)
|
6
|
-
paginator = described_class.new(
|
6
|
+
paginator = described_class.new(per_page: 4)
|
7
7
|
|
8
8
|
expect(paginator.paginate(list, 1).to_a).to eq([
|
9
9
|
['a',0],['b',1],['c',2],['d',3]])
|
@@ -11,7 +11,7 @@ RSpec.describe TTY::Prompt::BlockPaginator, '#paginate' do
|
|
11
11
|
|
12
12
|
it "ignores per_page when less items " do
|
13
13
|
list = %w(a b c d)
|
14
|
-
paginator = described_class.new(
|
14
|
+
paginator = described_class.new(per_page: 5)
|
15
15
|
|
16
16
|
expect(paginator.paginate(list, 1).to_a).to eq([
|
17
17
|
['a',0],['b',1],['c',2],['d',3]])
|
@@ -19,7 +19,7 @@ RSpec.describe TTY::Prompt::BlockPaginator, '#paginate' do
|
|
19
19
|
|
20
20
|
it "paginates items matching per_page count" do
|
21
21
|
list = %w(a b c d e f)
|
22
|
-
paginator = described_class.new(
|
22
|
+
paginator = described_class.new(per_page: 3)
|
23
23
|
|
24
24
|
expect(paginator.paginate(list, 1).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
25
25
|
expect(paginator.paginate(list, 2).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
@@ -32,7 +32,7 @@ RSpec.describe TTY::Prompt::BlockPaginator, '#paginate' do
|
|
32
32
|
|
33
33
|
it "paginates items not matching per_page count" do
|
34
34
|
list = %w(a b c d e f g)
|
35
|
-
paginator = described_class.new(
|
35
|
+
paginator = described_class.new(per_page: 3)
|
36
36
|
|
37
37
|
expect(paginator.paginate(list, 1).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
38
38
|
expect(paginator.paginate(list, 2).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
@@ -46,7 +46,7 @@ RSpec.describe TTY::Prompt::BlockPaginator, '#paginate' do
|
|
46
46
|
|
47
47
|
it "finds both start and end index for current selection" do
|
48
48
|
list = %w(a b c d e f g)
|
49
|
-
paginator = described_class.new(
|
49
|
+
paginator = described_class.new(per_page: 3, default: 0)
|
50
50
|
|
51
51
|
paginator.paginate(list, 3)
|
52
52
|
expect(paginator.start_index).to eq(0)
|
@@ -67,7 +67,7 @@ RSpec.describe TTY::Prompt::BlockPaginator, '#paginate' do
|
|
67
67
|
|
68
68
|
it "starts with default selection" do
|
69
69
|
list = %w(a b c d e f g)
|
70
|
-
paginator = described_class.new(
|
70
|
+
paginator = described_class.new(per_page: 3, default: 3)
|
71
71
|
|
72
72
|
expect(paginator.paginate(list, 4).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
73
73
|
end
|
@@ -75,7 +75,7 @@ RSpec.describe TTY::Prompt::BlockPaginator, '#paginate' do
|
|
75
75
|
it "doesn't accept invalid pagination" do
|
76
76
|
list = %w(a b c d e f g)
|
77
77
|
|
78
|
-
paginator = described_class.new(
|
78
|
+
paginator = described_class.new(per_page: 0)
|
79
79
|
|
80
80
|
expect {
|
81
81
|
paginator.paginate(list, 4)
|
@@ -34,6 +34,24 @@ RSpec.describe TTY::Prompt::Choice, '#from' do
|
|
34
34
|
expect(choice.value).to eq(1)
|
35
35
|
end
|
36
36
|
|
37
|
+
it "creates choice from array with false" do
|
38
|
+
expected_choice = described_class.new('large', false)
|
39
|
+
choice = described_class.from([:large, false])
|
40
|
+
|
41
|
+
expect(choice).to eq(expected_choice)
|
42
|
+
expect(choice.name).to eq('large')
|
43
|
+
expect(choice.value).to eq(false)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "defaults value to name if value is nil" do
|
47
|
+
expected_choice = described_class.new('large', 'large')
|
48
|
+
choice = described_class.from([:large, nil])
|
49
|
+
|
50
|
+
expect(choice).to eq(expected_choice)
|
51
|
+
expect(choice.name).to eq('large')
|
52
|
+
expect(choice.value).to eq('large')
|
53
|
+
end
|
54
|
+
|
37
55
|
it "creates choice from hash value" do
|
38
56
|
expected_choice = described_class.new('large', 1)
|
39
57
|
choice = described_class.from({large: 1})
|
data/spec/unit/paginator_spec.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
RSpec.describe TTY::Prompt::Paginator, '#paginate' do
|
4
4
|
it "ignores per_page when equal items " do
|
5
5
|
list = %w(a b c d)
|
6
|
-
paginator = described_class.new(
|
6
|
+
paginator = described_class.new(per_page: 4)
|
7
7
|
|
8
8
|
expect(paginator.paginate(list, 1).to_a).to eq([
|
9
9
|
['a',0],['b',1],['c',2],['d',3]])
|
@@ -11,7 +11,7 @@ RSpec.describe TTY::Prompt::Paginator, '#paginate' do
|
|
11
11
|
|
12
12
|
it "ignores per_page when less items " do
|
13
13
|
list = %w(a b c d)
|
14
|
-
paginator = described_class.new(
|
14
|
+
paginator = described_class.new(per_page: 5)
|
15
15
|
|
16
16
|
expect(paginator.paginate(list, 1).to_a).to eq([
|
17
17
|
['a',0],['b',1],['c',2],['d',3]])
|
@@ -19,7 +19,7 @@ RSpec.describe TTY::Prompt::Paginator, '#paginate' do
|
|
19
19
|
|
20
20
|
it "paginates items matching per_page count" do
|
21
21
|
list = %w(a b c d e f)
|
22
|
-
paginator = described_class.new(
|
22
|
+
paginator = described_class.new(per_page: 3)
|
23
23
|
|
24
24
|
expect(paginator.paginate(list, 1).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
25
25
|
expect(paginator.paginate(list, 2).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
@@ -32,7 +32,7 @@ RSpec.describe TTY::Prompt::Paginator, '#paginate' do
|
|
32
32
|
|
33
33
|
it "paginates items not matching per_page count" do
|
34
34
|
list = %w(a b c d e f g)
|
35
|
-
paginator = described_class.new(
|
35
|
+
paginator = described_class.new(per_page: 3)
|
36
36
|
|
37
37
|
expect(paginator.paginate(list, 1).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
38
38
|
expect(paginator.paginate(list, 2).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
@@ -46,7 +46,7 @@ RSpec.describe TTY::Prompt::Paginator, '#paginate' do
|
|
46
46
|
|
47
47
|
it "finds both start and end index for current selection" do
|
48
48
|
list = %w(a b c d e f g)
|
49
|
-
paginator = described_class.new(
|
49
|
+
paginator = described_class.new(per_page: 3, default: 0)
|
50
50
|
|
51
51
|
paginator.paginate(list, 2)
|
52
52
|
expect(paginator.start_index).to eq(0)
|
@@ -75,7 +75,7 @@ RSpec.describe TTY::Prompt::Paginator, '#paginate' do
|
|
75
75
|
|
76
76
|
it "starts with default selection" do
|
77
77
|
list = %w(a b c d e f g)
|
78
|
-
paginator = described_class.new(
|
78
|
+
paginator = described_class.new(per_page: 3, default: 3)
|
79
79
|
|
80
80
|
expect(paginator.paginate(list, 4).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
81
81
|
end
|
@@ -83,7 +83,7 @@ RSpec.describe TTY::Prompt::Paginator, '#paginate' do
|
|
83
83
|
it "doesn't accept invalid pagination" do
|
84
84
|
list = %w(a b c d e f g)
|
85
85
|
|
86
|
-
paginator = described_class.new(
|
86
|
+
paginator = described_class.new(per_page: 0)
|
87
87
|
|
88
88
|
expect {
|
89
89
|
paginator.paginate(list, 4)
|
data/spec/unit/select_spec.rb
CHANGED
@@ -233,7 +233,7 @@ RSpec.describe TTY::Prompt, '#select' do
|
|
233
233
|
prompt.input.rewind
|
234
234
|
options = {active_color: :blue, help_color: :red, symbols: {marker: '>' }}
|
235
235
|
|
236
|
-
value = prompt.select('What size?', choices, options)
|
236
|
+
value = prompt.select('What size?', choices, **options)
|
237
237
|
|
238
238
|
expect(value).to eq('Large')
|
239
239
|
expect(prompt.output.string).to eq([
|
data/spec/unit/yes_no_spec.rb
CHANGED
@@ -32,6 +32,23 @@ RSpec.describe TTY::Prompt, 'confirmation' do
|
|
32
32
|
].join)
|
33
33
|
end
|
34
34
|
|
35
|
+
it 'warns about invalid entry when using defaults' do
|
36
|
+
prompt.input << "test"
|
37
|
+
prompt.input.rewind
|
38
|
+
prompt.yes?("Are you a human?")
|
39
|
+
expect(prompt.output.string).to eq([
|
40
|
+
"Are you a human? \e[90m(Y/n)\e[0m ",
|
41
|
+
"\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m t",
|
42
|
+
"\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m te",
|
43
|
+
"\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m tes",
|
44
|
+
"\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m test",
|
45
|
+
"\e[31m>>\e[0m Invalid input.\e[1A",
|
46
|
+
"\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m ",
|
47
|
+
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
48
|
+
"Are you a human? \e[32mYes\e[0m\n"
|
49
|
+
].join)
|
50
|
+
end
|
51
|
+
|
35
52
|
it 'assumes default true' do
|
36
53
|
prompt.input << "\r"
|
37
54
|
prompt.input.rewind
|
@@ -181,6 +198,23 @@ RSpec.describe TTY::Prompt, 'confirmation' do
|
|
181
198
|
].join)
|
182
199
|
end
|
183
200
|
|
201
|
+
it 'warns about invalid entry when using defaults' do
|
202
|
+
prompt.input << "test"
|
203
|
+
prompt.input.rewind
|
204
|
+
prompt.no?("Are you a human?")
|
205
|
+
expect(prompt.output.string).to eq([
|
206
|
+
"Are you a human? \e[90m(y/N)\e[0m ",
|
207
|
+
"\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m t",
|
208
|
+
"\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m te",
|
209
|
+
"\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m tes",
|
210
|
+
"\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m test",
|
211
|
+
"\e[31m>>\e[0m Invalid input.\e[1A",
|
212
|
+
"\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m ",
|
213
|
+
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
214
|
+
"Are you a human? \e[32mNo\e[0m\n"
|
215
|
+
].join)
|
216
|
+
end
|
217
|
+
|
184
218
|
it 'assumes default false' do
|
185
219
|
prompt.input << "\r"
|
186
220
|
prompt.input.rewind
|
data/tty-prompt.gemspec
CHANGED
@@ -11,7 +11,16 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.description = %q{A beautiful and powerful interactive command line prompt with a robust API for getting and validating complex inputs.}
|
12
12
|
spec.homepage = "https://piotrmurach.github.io/tty"
|
13
13
|
spec.license = "MIT"
|
14
|
-
|
14
|
+
if spec.respond_to?(:metadata=)
|
15
|
+
spec.metadata = {
|
16
|
+
"allowed_push_host" => "https://rubygems.org",
|
17
|
+
"bug_tracker_uri" => "https://github.com/piotrmurach/tty-prompt/issues",
|
18
|
+
"changelog_uri" => "https://github.com/piotrmurach/tty-prompt/blob/master/CHANGELOG.md",
|
19
|
+
"documentation_uri" => "https://www.rubydoc.info/gems/tty-prompt",
|
20
|
+
"homepage_uri" => spec.homepage,
|
21
|
+
"source_code_uri" => "https://github.com/piotrmurach/tty-prompt"
|
22
|
+
}
|
23
|
+
end
|
15
24
|
spec.files = Dir['{lib,spec,examples}/**/*.rb']
|
16
25
|
spec.files += Dir['tasks/*', 'tty-prompt.gemspec']
|
17
26
|
spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt', 'Rakefile']
|
@@ -23,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
23
32
|
|
24
33
|
spec.add_dependency 'necromancer', '~> 0.5.0'
|
25
34
|
spec.add_dependency 'pastel', '~> 0.7.0'
|
26
|
-
spec.add_dependency 'tty-reader', '~> 0.
|
35
|
+
spec.add_dependency 'tty-reader', '~> 0.7.0'
|
27
36
|
|
28
37
|
spec.add_development_dependency 'bundler', '>= 1.5.0'
|
29
38
|
spec.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-prompt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: necromancer
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.7.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.7.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- Rakefile
|
109
109
|
- examples/ask.rb
|
110
110
|
- examples/ask_blank.rb
|
111
|
+
- examples/ask_multiline.rb
|
111
112
|
- examples/ask_valid.rb
|
112
113
|
- examples/collect.rb
|
113
114
|
- examples/echo.rb
|
@@ -237,7 +238,13 @@ files:
|
|
237
238
|
homepage: https://piotrmurach.github.io/tty
|
238
239
|
licenses:
|
239
240
|
- MIT
|
240
|
-
metadata:
|
241
|
+
metadata:
|
242
|
+
allowed_push_host: https://rubygems.org
|
243
|
+
bug_tracker_uri: https://github.com/piotrmurach/tty-prompt/issues
|
244
|
+
changelog_uri: https://github.com/piotrmurach/tty-prompt/blob/master/CHANGELOG.md
|
245
|
+
documentation_uri: https://www.rubydoc.info/gems/tty-prompt
|
246
|
+
homepage_uri: https://piotrmurach.github.io/tty
|
247
|
+
source_code_uri: https://github.com/piotrmurach/tty-prompt
|
241
248
|
post_install_message:
|
242
249
|
rdoc_options: []
|
243
250
|
require_paths:
|
@@ -253,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
253
260
|
- !ruby/object:Gem::Version
|
254
261
|
version: '0'
|
255
262
|
requirements: []
|
256
|
-
rubygems_version: 3.0.
|
263
|
+
rubygems_version: 3.0.6
|
257
264
|
signing_key:
|
258
265
|
specification_version: 4
|
259
266
|
summary: A beautiful and powerful interactive command line prompt.
|