tty-prompt 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -1
  3. data/CHANGELOG.md +15 -0
  4. data/Gemfile +2 -2
  5. data/README.md +185 -25
  6. data/examples/enum.rb +8 -0
  7. data/examples/enum_select.rb +7 -0
  8. data/examples/in.rb +3 -1
  9. data/examples/slider.rb +6 -0
  10. data/lib/tty-prompt.rb +8 -2
  11. data/lib/tty/prompt.rb +63 -13
  12. data/lib/tty/prompt/converters.rb +12 -6
  13. data/lib/tty/prompt/enum_list.rb +222 -0
  14. data/lib/tty/prompt/list.rb +48 -15
  15. data/lib/tty/prompt/multi_list.rb +11 -11
  16. data/lib/tty/prompt/question.rb +38 -14
  17. data/lib/tty/prompt/question/checks.rb +5 -3
  18. data/lib/tty/prompt/reader.rb +12 -18
  19. data/lib/tty/prompt/reader/codes.rb +15 -9
  20. data/lib/tty/prompt/reader/key_event.rb +51 -24
  21. data/lib/tty/prompt/slider.rb +170 -0
  22. data/lib/tty/prompt/symbols.rb +7 -1
  23. data/lib/tty/prompt/utils.rb +31 -3
  24. data/lib/tty/prompt/version.rb +1 -1
  25. data/spec/spec_helper.rb +1 -0
  26. data/spec/unit/converters/convert_bool_spec.rb +1 -1
  27. data/spec/unit/converters/convert_date_spec.rb +11 -2
  28. data/spec/unit/converters/convert_file_spec.rb +1 -1
  29. data/spec/unit/converters/convert_number_spec.rb +19 -2
  30. data/spec/unit/converters/convert_path_spec.rb +1 -1
  31. data/spec/unit/converters/convert_range_spec.rb +4 -3
  32. data/spec/unit/enum_select_spec.rb +93 -0
  33. data/spec/unit/multi_select_spec.rb +14 -12
  34. data/spec/unit/question/checks_spec.rb +97 -0
  35. data/spec/unit/reader/key_event_spec.rb +67 -0
  36. data/spec/unit/select_spec.rb +15 -16
  37. data/spec/unit/slider_spec.rb +54 -0
  38. data/tty-prompt.gemspec +2 -1
  39. metadata +31 -5
  40. data/.ruby-version +0 -1
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  RSpec.describe TTY::Prompt, '#select' do
6
4
 
7
5
  subject(:prompt) { TTY::TestPrompt.new }
@@ -97,6 +95,7 @@ RSpec.describe TTY::Prompt, '#select' do
97
95
  prompt.input.rewind
98
96
  value = prompt.select('What size?') do |menu|
99
97
  menu.default 2
98
+ menu.enum '.'
100
99
 
101
100
  menu.choice :large, 1
102
101
  menu.choice :medium, 2
@@ -104,10 +103,10 @@ RSpec.describe TTY::Prompt, '#select' do
104
103
  end
105
104
  expect(value).to eq(2)
106
105
  expect(prompt.output.string).to eq([
107
- "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
108
- " large\n",
109
- "\e[32m‣ medium\e[0m\n",
110
- " small",
106
+ "\e[?25lWhat size? \e[90m(Use arrow or number (0-9) keys, press Enter to select)\e[0m\n",
107
+ " 1. large\n",
108
+ "\e[32m‣ 2. medium\e[0m\n",
109
+ " 3. small",
111
110
  "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
112
111
  "What size? \e[32mmedium\e[0m\n\e[?25h"
113
112
  ].join)
@@ -116,17 +115,17 @@ RSpec.describe TTY::Prompt, '#select' do
116
115
  it "sets choice value to proc and executes it" do
117
116
  prompt.input << " "
118
117
  prompt.input.rewind
119
- value = prompt.select('What size?', default: 2) do |menu|
118
+ value = prompt.select('What size?', default: 2, enum: ')') do |menu|
120
119
  menu.choice :large, 1
121
120
  menu.choice :medium do 'Good choice!' end
122
121
  menu.choice :small, 3
123
122
  end
124
123
  expect(value).to eq('Good choice!')
125
124
  expect(prompt.output.string).to eq([
126
- "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
127
- " large\n",
128
- "\e[32m‣ medium\e[0m\n",
129
- " small",
125
+ "\e[?25lWhat size? \e[90m(Use arrow or number (0-9) keys, press Enter to select)\e[0m\n",
126
+ " 1) large\n",
127
+ "\e[32m‣ 2) medium\e[0m\n",
128
+ " 3) small",
130
129
  "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
131
130
  "What size? \e[32mmedium\e[0m\n\e[?25h"
132
131
  ].join)
@@ -136,12 +135,12 @@ RSpec.describe TTY::Prompt, '#select' do
136
135
  choices = %w(Large Medium Small)
137
136
  prompt.input << " "
138
137
  prompt.input.rewind
139
- expect(prompt.select('What size?', choices, default: 2)).to eq('Medium')
138
+ expect(prompt.select('What size?', choices, default: 2, enum: '.')).to eq('Medium')
140
139
  expect(prompt.output.string).to eq([
141
- "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
142
- " Large\n",
143
- "\e[32m‣ Medium\e[0m\n",
144
- " Small",
140
+ "\e[?25lWhat size? \e[90m(Use arrow or number (0-9) keys, press Enter to select)\e[0m\n",
141
+ " 1. Large\n",
142
+ "\e[32m‣ 2. Medium\e[0m\n",
143
+ " 3. Small",
145
144
  "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
146
145
  "What size? \e[32mMedium\e[0m\n\e[?25h"
147
146
  ].join)
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ RSpec.describe TTY::Prompt, '#slider' do
4
+
5
+ subject(:prompt) { TTY::TestPrompt.new }
6
+
7
+ it "specifies ranges & step" do
8
+ prompt.input << "\r"
9
+ prompt.input.rewind
10
+ expect(prompt.slider('What size?', min: 32, max: 54, step: 2)).to eq(44)
11
+ expect(prompt.output.string).to eq([
12
+ "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
13
+ "|------",
14
+ "\e[32mO\e[0m",
15
+ "-----| 44",
16
+ "\e[1000D\e[K\e[1A\e[1000D\e[K",
17
+ "What size? \e[32m44\e[0m\n\e[?25h"
18
+ ].join)
19
+ end
20
+
21
+ it "specifies default value" do
22
+ prompt.input << "\r"
23
+ prompt.input.rewind
24
+ expect(prompt.slider('What size?', min: 32, max: 54, step: 2, default: 38)).to eq(38)
25
+ expect(prompt.output.string).to eq([
26
+ "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
27
+ "|---",
28
+ "\e[32mO\e[0m",
29
+ "--------| 38",
30
+ "\e[1000D\e[K\e[1A\e[1000D\e[K",
31
+ "What size? \e[32m38\e[0m\n\e[?25h"
32
+ ].join)
33
+ end
34
+
35
+ it "specifies range through DSL" do
36
+ prompt.input << "\r"
37
+ prompt.input.rewind
38
+ value = prompt.slider('What size?') do |range|
39
+ range.default 6
40
+ range.min 0
41
+ range.max 20
42
+ range.step 2
43
+ end
44
+ expect(value).to eq(6)
45
+ expect(prompt.output.string).to eq([
46
+ "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
47
+ "|---",
48
+ "\e[32mO\e[0m",
49
+ "-------| 6",
50
+ "\e[1000D\e[K\e[1A\e[1000D\e[K",
51
+ "What size? \e[32m6\e[0m\n\e[?25h"
52
+ ].join)
53
+ end
54
+ end
data/tty-prompt.gemspec CHANGED
@@ -19,11 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'necromancer', '~> 0.3.0'
22
- spec.add_dependency 'pastel', '~> 0.5.2'
22
+ spec.add_dependency 'pastel', '~> 0.6.0'
23
23
  spec.add_dependency 'tty-cursor', '~> 0.2.0'
24
24
  spec.add_dependency 'tty-platform', '~> 0.1.0'
25
25
  spec.add_dependency 'wisper', '~> 1.6.1'
26
26
 
27
27
  spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.4.0'
28
29
  spec.add_development_dependency 'rake'
29
30
  end
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.3.0
4
+ version: 0.4.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: 2015-12-28 00:00:00.000000000 Z
11
+ date: 2016-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: necromancer
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.2
33
+ version: 0.6.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.2
40
+ version: 0.6.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: tty-cursor
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - <
101
101
  - !ruby/object:Gem::Version
102
102
  version: '2.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 3.4.0
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ~>
115
+ - !ruby/object:Gem::Version
116
+ version: 3.4.0
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: rake
105
119
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +138,6 @@ extra_rdoc_files: []
124
138
  files:
125
139
  - .gitignore
126
140
  - .rspec
127
- - .ruby-version
128
141
  - .travis.yml
129
142
  - CHANGELOG.md
130
143
  - Gemfile
@@ -133,10 +146,13 @@ files:
133
146
  - Rakefile
134
147
  - examples/ask.rb
135
148
  - examples/echo.rb
149
+ - examples/enum.rb
150
+ - examples/enum_select.rb
136
151
  - examples/in.rb
137
152
  - examples/mask.rb
138
153
  - examples/multi_select.rb
139
154
  - examples/select.rb
155
+ - examples/slider.rb
140
156
  - examples/validation.rb
141
157
  - examples/yes_no.rb
142
158
  - lib/tty-prompt.rb
@@ -147,6 +163,7 @@ files:
147
163
  - lib/tty/prompt/converter_registry.rb
148
164
  - lib/tty/prompt/converters.rb
149
165
  - lib/tty/prompt/distance.rb
166
+ - lib/tty/prompt/enum_list.rb
150
167
  - lib/tty/prompt/evaluator.rb
151
168
  - lib/tty/prompt/history.rb
152
169
  - lib/tty/prompt/list.rb
@@ -163,6 +180,7 @@ files:
163
180
  - lib/tty/prompt/reader/mode/echo.rb
164
181
  - lib/tty/prompt/reader/mode/raw.rb
165
182
  - lib/tty/prompt/result.rb
183
+ - lib/tty/prompt/slider.rb
166
184
  - lib/tty/prompt/statement.rb
167
185
  - lib/tty/prompt/suggestion.rb
168
186
  - lib/tty/prompt/symbols.rb
@@ -188,6 +206,7 @@ files:
188
206
  - spec/unit/converters/convert_regex_spec.rb
189
207
  - spec/unit/converters/convert_string_spec.rb
190
208
  - spec/unit/distance/distance_spec.rb
209
+ - spec/unit/enum_select_spec.rb
191
210
  - spec/unit/error_spec.rb
192
211
  - spec/unit/evaluator_spec.rb
193
212
  - spec/unit/keypress_spec.rb
@@ -196,6 +215,7 @@ files:
196
215
  - spec/unit/multiline_spec.rb
197
216
  - spec/unit/new_spec.rb
198
217
  - spec/unit/ok_spec.rb
218
+ - spec/unit/question/checks_spec.rb
199
219
  - spec/unit/question/default_spec.rb
200
220
  - spec/unit/question/echo_spec.rb
201
221
  - spec/unit/question/in_spec.rb
@@ -208,6 +228,7 @@ files:
208
228
  - spec/unit/question/validate_spec.rb
209
229
  - spec/unit/question/validation/call_spec.rb
210
230
  - spec/unit/question/validation/coerce_spec.rb
231
+ - spec/unit/reader/key_event_spec.rb
211
232
  - spec/unit/reader/publish_keypress_event_spec.rb
212
233
  - spec/unit/reader/read_keypress_spec.rb
213
234
  - spec/unit/reader/read_line_spec.rb
@@ -215,6 +236,7 @@ files:
215
236
  - spec/unit/result_spec.rb
216
237
  - spec/unit/say_spec.rb
217
238
  - spec/unit/select_spec.rb
239
+ - spec/unit/slider_spec.rb
218
240
  - spec/unit/statement/initialize_spec.rb
219
241
  - spec/unit/suggest_spec.rb
220
242
  - spec/unit/warn_spec.rb
@@ -267,6 +289,7 @@ test_files:
267
289
  - spec/unit/converters/convert_regex_spec.rb
268
290
  - spec/unit/converters/convert_string_spec.rb
269
291
  - spec/unit/distance/distance_spec.rb
292
+ - spec/unit/enum_select_spec.rb
270
293
  - spec/unit/error_spec.rb
271
294
  - spec/unit/evaluator_spec.rb
272
295
  - spec/unit/keypress_spec.rb
@@ -275,6 +298,7 @@ test_files:
275
298
  - spec/unit/multiline_spec.rb
276
299
  - spec/unit/new_spec.rb
277
300
  - spec/unit/ok_spec.rb
301
+ - spec/unit/question/checks_spec.rb
278
302
  - spec/unit/question/default_spec.rb
279
303
  - spec/unit/question/echo_spec.rb
280
304
  - spec/unit/question/in_spec.rb
@@ -287,6 +311,7 @@ test_files:
287
311
  - spec/unit/question/validate_spec.rb
288
312
  - spec/unit/question/validation/call_spec.rb
289
313
  - spec/unit/question/validation/coerce_spec.rb
314
+ - spec/unit/reader/key_event_spec.rb
290
315
  - spec/unit/reader/publish_keypress_event_spec.rb
291
316
  - spec/unit/reader/read_keypress_spec.rb
292
317
  - spec/unit/reader/read_line_spec.rb
@@ -294,6 +319,7 @@ test_files:
294
319
  - spec/unit/result_spec.rb
295
320
  - spec/unit/say_spec.rb
296
321
  - spec/unit/select_spec.rb
322
+ - spec/unit/slider_spec.rb
297
323
  - spec/unit/statement/initialize_spec.rb
298
324
  - spec/unit/suggest_spec.rb
299
325
  - spec/unit/warn_spec.rb
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.0.0