tty-prompt 0.10.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -1
  3. data/CHANGELOG.md +30 -0
  4. data/README.md +39 -9
  5. data/examples/echo.rb +5 -1
  6. data/examples/inputs.rb +10 -0
  7. data/examples/mask.rb +6 -2
  8. data/examples/multi_select.rb +1 -1
  9. data/examples/multi_select_paged.rb +9 -0
  10. data/examples/select.rb +5 -5
  11. data/examples/slider.rb +1 -1
  12. data/lib/tty-prompt.rb +2 -36
  13. data/lib/tty/prompt.rb +49 -8
  14. data/lib/tty/prompt/choices.rb +2 -0
  15. data/lib/tty/prompt/confirm_question.rb +6 -1
  16. data/lib/tty/prompt/converter_dsl.rb +9 -6
  17. data/lib/tty/prompt/converter_registry.rb +27 -19
  18. data/lib/tty/prompt/converters.rb +16 -22
  19. data/lib/tty/prompt/enum_list.rb +8 -4
  20. data/lib/tty/prompt/enum_paginator.rb +2 -0
  21. data/lib/tty/prompt/evaluator.rb +1 -1
  22. data/lib/tty/prompt/expander.rb +1 -1
  23. data/lib/tty/prompt/list.rb +21 -11
  24. data/lib/tty/prompt/mask_question.rb +15 -6
  25. data/lib/tty/prompt/multi_list.rb +12 -10
  26. data/lib/tty/prompt/question.rb +38 -36
  27. data/lib/tty/prompt/question/modifier.rb +2 -0
  28. data/lib/tty/prompt/question/validation.rb +5 -4
  29. data/lib/tty/prompt/reader.rb +104 -58
  30. data/lib/tty/prompt/reader/codes.rb +103 -63
  31. data/lib/tty/prompt/reader/console.rb +57 -0
  32. data/lib/tty/prompt/reader/key_event.rb +51 -88
  33. data/lib/tty/prompt/reader/mode.rb +5 -5
  34. data/lib/tty/prompt/reader/win_api.rb +29 -0
  35. data/lib/tty/prompt/reader/win_console.rb +49 -0
  36. data/lib/tty/prompt/slider.rb +10 -6
  37. data/lib/tty/prompt/suggestion.rb +1 -1
  38. data/lib/tty/prompt/symbols.rb +52 -10
  39. data/lib/tty/prompt/version.rb +1 -1
  40. data/lib/tty/{prompt/test.rb → test_prompt.rb} +2 -1
  41. data/spec/unit/ask_spec.rb +8 -16
  42. data/spec/unit/converters/convert_bool_spec.rb +1 -2
  43. data/spec/unit/converters/on_error_spec.rb +9 -0
  44. data/spec/unit/enum_paginator_spec.rb +16 -0
  45. data/spec/unit/enum_select_spec.rb +69 -25
  46. data/spec/unit/expand_spec.rb +14 -14
  47. data/spec/unit/mask_spec.rb +66 -29
  48. data/spec/unit/multi_select_spec.rb +120 -74
  49. data/spec/unit/new_spec.rb +5 -3
  50. data/spec/unit/paginator_spec.rb +16 -0
  51. data/spec/unit/question/default_spec.rb +2 -4
  52. data/spec/unit/question/echo_spec.rb +2 -3
  53. data/spec/unit/question/in_spec.rb +9 -14
  54. data/spec/unit/question/modifier/letter_case_spec.rb +32 -11
  55. data/spec/unit/question/modifier/whitespace_spec.rb +41 -15
  56. data/spec/unit/question/required_spec.rb +9 -13
  57. data/spec/unit/question/validate_spec.rb +7 -10
  58. data/spec/unit/reader/key_event_spec.rb +36 -50
  59. data/spec/unit/reader/publish_keypress_event_spec.rb +5 -3
  60. data/spec/unit/reader/read_keypress_spec.rb +8 -7
  61. data/spec/unit/reader/read_line_spec.rb +9 -9
  62. data/spec/unit/reader/read_multiline_spec.rb +8 -7
  63. data/spec/unit/select_spec.rb +85 -25
  64. data/spec/unit/slider_spec.rb +43 -16
  65. data/spec/unit/yes_no_spec.rb +14 -28
  66. data/tasks/console.rake +1 -0
  67. data/tty-prompt.gemspec +2 -2
  68. metadata +14 -7
@@ -11,8 +11,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
11
11
  expect(prompt.yes?("Are you a human?")).to eq(true)
12
12
  expect(prompt.output.string).to eq([
13
13
  "Are you a human? \e[90m(Y/n)\e[0m ",
14
- "\e[1000D\e[K\e[1A",
15
- "\e[1000D\e[K",
14
+ "\e[1A\e[2K\e[1G",
16
15
  "Are you a human? \e[32mYes\e[0m\n"
17
16
  ].join)
18
17
  end
@@ -23,8 +22,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
23
22
  expect(prompt.yes?("Are you a human?")).to eq(false)
24
23
  expect(prompt.output.string).to eq([
25
24
  "Are you a human? \e[90m(Y/n)\e[0m ",
26
- "\e[1000D\e[K\e[1A",
27
- "\e[1000D\e[K",
25
+ "\e[1A\e[2K\e[1G",
28
26
  "Are you a human? \e[32mno\e[0m\n"
29
27
  ].join)
30
28
  end
@@ -35,8 +33,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
35
33
  expect(prompt.yes?("Are you a human?")).to eq(true)
36
34
  expect(prompt.output.string).to eq([
37
35
  "Are you a human? \e[90m(Y/n)\e[0m ",
38
- "\e[1000D\e[K\e[1A",
39
- "\e[1000D\e[K",
36
+ "\e[1A\e[2K\e[1G",
40
37
  "Are you a human? \e[32mYes\e[0m\n"
41
38
  ].join)
42
39
  end
@@ -47,8 +44,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
47
44
  expect(prompt.yes?("Are you a human?", default: false)).to eq(false)
48
45
  expect(prompt.output.string).to eq([
49
46
  "Are you a human? \e[90m(Y/n)\e[0m ",
50
- "\e[1000D\e[K\e[1A",
51
- "\e[1000D\e[K",
47
+ "\e[1A\e[2K\e[1G",
52
48
  "Are you a human? \e[32mno\e[0m\n"
53
49
  ].join)
54
50
  end
@@ -63,8 +59,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
63
59
  expect(result).to eq(false)
64
60
  expect(prompt.output.string).to eq([
65
61
  "Are you a human? \e[90m(Yup/nope)\e[0m ",
66
- "\e[1000D\e[K\e[1A",
67
- "\e[1000D\e[K",
62
+ "\e[1A\e[2K\e[1G",
68
63
  "Are you a human? \e[32mnope\e[0m\n"
69
64
  ].join)
70
65
  end
@@ -78,8 +73,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
78
73
  expect(result).to eq(false)
79
74
  expect(prompt.output.string).to eq([
80
75
  "Are you a human? \e[90m(Yup/nope)\e[0m ",
81
- "\e[1000D\e[K\e[1A",
82
- "\e[1000D\e[K",
76
+ "\e[1A\e[2K\e[1G",
83
77
  "Are you a human? \e[32mnope\e[0m\n"
84
78
  ].join)
85
79
  end
@@ -92,8 +86,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
92
86
  expect(result).to eq(true)
93
87
  expect(prompt.output.string).to eq([
94
88
  "Are you a human? \e[90m(Agree/Disagree)\e[0m ",
95
- "\e[1000D\e[K\e[1A",
96
- "\e[1000D\e[K",
89
+ "\e[1A\e[2K\e[1G",
97
90
  "Are you a human? \e[32mAgree\e[0m\n"
98
91
  ].join)
99
92
  end
@@ -111,8 +104,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
111
104
  expect(result).to eq(false)
112
105
  expect(prompt.output.string).to eq([
113
106
  "Are you a human? \e[90m(Agree/Disagree)\e[0m ",
114
- "\e[1000D\e[K\e[1A",
115
- "\e[1000D\e[K",
107
+ "\e[1A\e[2K\e[1G",
116
108
  "Are you a human? \e[32mDisagree\e[0m\n"
117
109
  ].join)
118
110
  end
@@ -125,8 +117,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
125
117
  expect(prompt.no?("Are you a human?")).to eq(true)
126
118
  expect(prompt.output.string).to eq([
127
119
  "Are you a human? \e[90m(y/N)\e[0m ",
128
- "\e[1000D\e[K\e[1A",
129
- "\e[1000D\e[K",
120
+ "\e[1A\e[2K\e[1G",
130
121
  "Are you a human? \e[32mNo\e[0m\n"
131
122
  ].join)
132
123
  end
@@ -137,8 +128,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
137
128
  expect(prompt.no?("Are you a human?")).to eq(false)
138
129
  expect(prompt.output.string).to eq([
139
130
  "Are you a human? \e[90m(y/N)\e[0m ",
140
- "\e[1000D\e[K\e[1A",
141
- "\e[1000D\e[K",
131
+ "\e[1A\e[2K\e[1G",
142
132
  "Are you a human? \e[32mYes\e[0m\n"
143
133
  ].join)
144
134
  end
@@ -149,8 +139,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
149
139
  expect(prompt.no?("Are you a human?")).to eq(true)
150
140
  expect(prompt.output.string).to eq([
151
141
  "Are you a human? \e[90m(y/N)\e[0m ",
152
- "\e[1000D\e[K\e[1A",
153
- "\e[1000D\e[K",
142
+ "\e[1A\e[2K\e[1G",
154
143
  "Are you a human? \e[32mNo\e[0m\n"
155
144
  ].join)
156
145
  end
@@ -161,8 +150,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
161
150
  expect(prompt.no?("Are you a human?", default: true)).to eq(false)
162
151
  expect(prompt.output.string).to eq([
163
152
  "Are you a human? \e[90m(y/N)\e[0m ",
164
- "\e[1000D\e[K\e[1A",
165
- "\e[1000D\e[K",
153
+ "\e[1A\e[2K\e[1G",
166
154
  "Are you a human? \e[32mYes\e[0m\n"
167
155
  ].join)
168
156
  end
@@ -177,8 +165,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
177
165
  expect(result).to eq(false)
178
166
  expect(prompt.output.string).to eq([
179
167
  "Are you a human? \e[90m(yup/Nope)\e[0m ",
180
- "\e[1000D\e[K\e[1A",
181
- "\e[1000D\e[K",
168
+ "\e[1A\e[2K\e[1G",
182
169
  "Are you a human? \e[32myup\e[0m\n"
183
170
  ].join)
184
171
  end
@@ -196,8 +183,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
196
183
  expect(result).to eq(false)
197
184
  expect(prompt.output.string).to eq([
198
185
  "Are you a human? \e[90m(Agree/Disagree)\e[0m ",
199
- "\e[1000D\e[K\e[1A",
200
- "\e[1000D\e[K",
186
+ "\e[1A\e[2K\e[1G",
201
187
  "Are you a human? \e[32mAgree\e[0m\n"
202
188
  ].join)
203
189
  end
@@ -8,3 +8,4 @@ task :console do
8
8
  ARGV.clear
9
9
  IRB.start
10
10
  end
11
+ task c: %w[ console ]
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'necromancer', '~> 0.3.0'
21
+ spec.add_dependency 'necromancer', '~> 0.4.0'
22
22
  spec.add_dependency 'pastel', '~> 0.7.0'
23
- spec.add_dependency 'tty-cursor', '~> 0.3.0'
23
+ spec.add_dependency 'tty-cursor', '~> 0.4.0'
24
24
  spec.add_dependency 'wisper', '~> 1.6.1'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
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.10.1
4
+ version: 0.11.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: 2017-02-06 00:00:00.000000000 Z
11
+ date: 2017-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: necromancer
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.0
19
+ version: 0.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.0
26
+ version: 0.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pastel
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.0
47
+ version: 0.4.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.3.0
54
+ version: 0.4.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: wisper
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -141,9 +141,11 @@ files:
141
141
  - examples/enum_select.rb
142
142
  - examples/expand.rb
143
143
  - examples/in.rb
144
+ - examples/inputs.rb
144
145
  - examples/keypress.rb
145
146
  - examples/mask.rb
146
147
  - examples/multi_select.rb
148
+ - examples/multi_select_paged.rb
147
149
  - examples/select.rb
148
150
  - examples/select_paginated.rb
149
151
  - examples/slider.rb
@@ -174,16 +176,19 @@ files:
174
176
  - lib/tty/prompt/question/validation.rb
175
177
  - lib/tty/prompt/reader.rb
176
178
  - lib/tty/prompt/reader/codes.rb
179
+ - lib/tty/prompt/reader/console.rb
177
180
  - lib/tty/prompt/reader/key_event.rb
178
181
  - lib/tty/prompt/reader/mode.rb
182
+ - lib/tty/prompt/reader/win_api.rb
183
+ - lib/tty/prompt/reader/win_console.rb
179
184
  - lib/tty/prompt/result.rb
180
185
  - lib/tty/prompt/slider.rb
181
186
  - lib/tty/prompt/statement.rb
182
187
  - lib/tty/prompt/suggestion.rb
183
188
  - lib/tty/prompt/symbols.rb
184
- - lib/tty/prompt/test.rb
185
189
  - lib/tty/prompt/utils.rb
186
190
  - lib/tty/prompt/version.rb
191
+ - lib/tty/test_prompt.rb
187
192
  - spec/spec_helper.rb
188
193
  - spec/unit/ask_spec.rb
189
194
  - spec/unit/choice/eql_spec.rb
@@ -204,6 +209,7 @@ files:
204
209
  - spec/unit/converters/convert_range_spec.rb
205
210
  - spec/unit/converters/convert_regex_spec.rb
206
211
  - spec/unit/converters/convert_string_spec.rb
212
+ - spec/unit/converters/on_error_spec.rb
207
213
  - spec/unit/distance/distance_spec.rb
208
214
  - spec/unit/enum_paginator_spec.rb
209
215
  - spec/unit/enum_select_spec.rb
@@ -292,6 +298,7 @@ test_files:
292
298
  - spec/unit/converters/convert_range_spec.rb
293
299
  - spec/unit/converters/convert_regex_spec.rb
294
300
  - spec/unit/converters/convert_string_spec.rb
301
+ - spec/unit/converters/on_error_spec.rb
295
302
  - spec/unit/distance/distance_spec.rb
296
303
  - spec/unit/enum_paginator_spec.rb
297
304
  - spec/unit/enum_select_spec.rb