tty-prompt 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +66 -7
  4. data/examples/key_events.rb +11 -0
  5. data/examples/keypress.rb +3 -5
  6. data/examples/multiline.rb +9 -0
  7. data/examples/pause.rb +7 -0
  8. data/lib/tty/prompt.rb +82 -44
  9. data/lib/tty/prompt/confirm_question.rb +20 -36
  10. data/lib/tty/prompt/enum_list.rb +32 -23
  11. data/lib/tty/prompt/expander.rb +35 -31
  12. data/lib/tty/prompt/keypress.rb +91 -0
  13. data/lib/tty/prompt/list.rb +38 -23
  14. data/lib/tty/prompt/mask_question.rb +4 -7
  15. data/lib/tty/prompt/multi_list.rb +3 -1
  16. data/lib/tty/prompt/multiline.rb +71 -0
  17. data/lib/tty/prompt/question.rb +33 -35
  18. data/lib/tty/prompt/reader.rb +154 -38
  19. data/lib/tty/prompt/reader/codes.rb +4 -4
  20. data/lib/tty/prompt/reader/console.rb +1 -1
  21. data/lib/tty/prompt/reader/history.rb +145 -0
  22. data/lib/tty/prompt/reader/key_event.rb +4 -0
  23. data/lib/tty/prompt/reader/line.rb +162 -0
  24. data/lib/tty/prompt/reader/mode.rb +2 -2
  25. data/lib/tty/prompt/reader/win_console.rb +5 -1
  26. data/lib/tty/prompt/slider.rb +18 -12
  27. data/lib/tty/prompt/timeout.rb +48 -0
  28. data/lib/tty/prompt/version.rb +1 -1
  29. data/spec/unit/ask_spec.rb +15 -0
  30. data/spec/unit/converters/convert_bool_spec.rb +1 -0
  31. data/spec/unit/keypress_spec.rb +35 -6
  32. data/spec/unit/multi_select_spec.rb +18 -0
  33. data/spec/unit/multiline_spec.rb +67 -9
  34. data/spec/unit/question/default_spec.rb +1 -0
  35. data/spec/unit/question/echo_spec.rb +8 -0
  36. data/spec/unit/question/in_spec.rb +13 -0
  37. data/spec/unit/question/required_spec.rb +31 -2
  38. data/spec/unit/question/validate_spec.rb +39 -9
  39. data/spec/unit/reader/history_spec.rb +172 -0
  40. data/spec/unit/reader/key_event_spec.rb +12 -8
  41. data/spec/unit/reader/line_spec.rb +110 -0
  42. data/spec/unit/reader/publish_keypress_event_spec.rb +11 -0
  43. data/spec/unit/reader/read_line_spec.rb +32 -2
  44. data/spec/unit/reader/read_multiline_spec.rb +21 -7
  45. data/spec/unit/select_spec.rb +40 -1
  46. data/spec/unit/yes_no_spec.rb +48 -4
  47. metadata +14 -3
  48. data/lib/tty/prompt/history.rb +0 -16
@@ -11,6 +11,9 @@ 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[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m y",
15
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m ye",
16
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m yes",
14
17
  "\e[1A\e[2K\e[1G",
15
18
  "Are you a human? \e[32mYes\e[0m\n"
16
19
  ].join)
@@ -22,6 +25,8 @@ RSpec.describe TTY::Prompt, 'confirmation' do
22
25
  expect(prompt.yes?("Are you a human?")).to eq(false)
23
26
  expect(prompt.output.string).to eq([
24
27
  "Are you a human? \e[90m(Y/n)\e[0m ",
28
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m n",
29
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m no",
25
30
  "\e[1A\e[2K\e[1G",
26
31
  "Are you a human? \e[32mno\e[0m\n"
27
32
  ].join)
@@ -33,6 +38,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
33
38
  expect(prompt.yes?("Are you a human?")).to eq(true)
34
39
  expect(prompt.output.string).to eq([
35
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 \n",
36
42
  "\e[1A\e[2K\e[1G",
37
43
  "Are you a human? \e[32mYes\e[0m\n"
38
44
  ].join)
@@ -43,9 +49,10 @@ RSpec.describe TTY::Prompt, 'confirmation' do
43
49
  prompt.input.rewind
44
50
  expect(prompt.yes?("Are you a human?", default: false)).to eq(false)
45
51
  expect(prompt.output.string).to eq([
46
- "Are you a human? \e[90m(Y/n)\e[0m ",
52
+ "Are you a human? \e[90m(y/N)\e[0m ",
53
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m \n",
47
54
  "\e[1A\e[2K\e[1G",
48
- "Are you a human? \e[32mno\e[0m\n"
55
+ "Are you a human? \e[32mNo\e[0m\n"
49
56
  ].join)
50
57
  end
51
58
 
@@ -59,6 +66,11 @@ RSpec.describe TTY::Prompt, 'confirmation' do
59
66
  expect(result).to eq(false)
60
67
  expect(prompt.output.string).to eq([
61
68
  "Are you a human? \e[90m(Yup/nope)\e[0m ",
69
+ "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m N",
70
+ "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m No",
71
+ "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nop",
72
+ "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nope",
73
+ "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nope\n",
62
74
  "\e[1A\e[2K\e[1G",
63
75
  "Are you a human? \e[32mnope\e[0m\n"
64
76
  ].join)
@@ -73,6 +85,11 @@ RSpec.describe TTY::Prompt, 'confirmation' do
73
85
  expect(result).to eq(false)
74
86
  expect(prompt.output.string).to eq([
75
87
  "Are you a human? \e[90m(Yup/nope)\e[0m ",
88
+ "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m N",
89
+ "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m No",
90
+ "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nop",
91
+ "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nope",
92
+ "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nope\n",
76
93
  "\e[1A\e[2K\e[1G",
77
94
  "Are you a human? \e[32mnope\e[0m\n"
78
95
  ].join)
@@ -86,6 +103,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
86
103
  expect(result).to eq(true)
87
104
  expect(prompt.output.string).to eq([
88
105
  "Are you a human? \e[90m(Agree/Disagree)\e[0m ",
106
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m \n",
89
107
  "\e[1A\e[2K\e[1G",
90
108
  "Are you a human? \e[32mAgree\e[0m\n"
91
109
  ].join)
@@ -104,6 +122,15 @@ RSpec.describe TTY::Prompt, 'confirmation' do
104
122
  expect(result).to eq(false)
105
123
  expect(prompt.output.string).to eq([
106
124
  "Are you a human? \e[90m(Agree/Disagree)\e[0m ",
125
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m d",
126
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m di",
127
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m dis",
128
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disa",
129
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disag",
130
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagr",
131
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagre",
132
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagree",
133
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagree\n",
107
134
  "\e[1A\e[2K\e[1G",
108
135
  "Are you a human? \e[32mDisagree\e[0m\n"
109
136
  ].join)
@@ -117,6 +144,8 @@ RSpec.describe TTY::Prompt, 'confirmation' do
117
144
  expect(prompt.no?("Are you a human?")).to eq(true)
118
145
  expect(prompt.output.string).to eq([
119
146
  "Are you a human? \e[90m(y/N)\e[0m ",
147
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m n",
148
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m no",
120
149
  "\e[1A\e[2K\e[1G",
121
150
  "Are you a human? \e[32mNo\e[0m\n"
122
151
  ].join)
@@ -128,8 +157,11 @@ RSpec.describe TTY::Prompt, 'confirmation' do
128
157
  expect(prompt.no?("Are you a human?")).to eq(false)
129
158
  expect(prompt.output.string).to eq([
130
159
  "Are you a human? \e[90m(y/N)\e[0m ",
160
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m y",
161
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m ye",
162
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m yes",
131
163
  "\e[1A\e[2K\e[1G",
132
- "Are you a human? \e[32mYes\e[0m\n"
164
+ "Are you a human? \e[32myes\e[0m\n"
133
165
  ].join)
134
166
  end
135
167
 
@@ -139,6 +171,7 @@ RSpec.describe TTY::Prompt, 'confirmation' do
139
171
  expect(prompt.no?("Are you a human?")).to eq(true)
140
172
  expect(prompt.output.string).to eq([
141
173
  "Are you a human? \e[90m(y/N)\e[0m ",
174
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m \n",
142
175
  "\e[1A\e[2K\e[1G",
143
176
  "Are you a human? \e[32mNo\e[0m\n"
144
177
  ].join)
@@ -149,7 +182,8 @@ RSpec.describe TTY::Prompt, 'confirmation' do
149
182
  prompt.input.rewind
150
183
  expect(prompt.no?("Are you a human?", default: true)).to eq(false)
151
184
  expect(prompt.output.string).to eq([
152
- "Are you a human? \e[90m(y/N)\e[0m ",
185
+ "Are you a human? \e[90m(Y/n)\e[0m ",
186
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m \n",
153
187
  "\e[1A\e[2K\e[1G",
154
188
  "Are you a human? \e[32mYes\e[0m\n"
155
189
  ].join)
@@ -165,6 +199,10 @@ RSpec.describe TTY::Prompt, 'confirmation' do
165
199
  expect(result).to eq(false)
166
200
  expect(prompt.output.string).to eq([
167
201
  "Are you a human? \e[90m(yup/Nope)\e[0m ",
202
+ "\e[2K\e[1GAre you a human? \e[90m(yup/Nope)\e[0m Y",
203
+ "\e[2K\e[1GAre you a human? \e[90m(yup/Nope)\e[0m Yu",
204
+ "\e[2K\e[1GAre you a human? \e[90m(yup/Nope)\e[0m Yup",
205
+ "\e[2K\e[1GAre you a human? \e[90m(yup/Nope)\e[0m Yup\n",
168
206
  "\e[1A\e[2K\e[1G",
169
207
  "Are you a human? \e[32myup\e[0m\n"
170
208
  ].join)
@@ -183,6 +221,12 @@ RSpec.describe TTY::Prompt, 'confirmation' do
183
221
  expect(result).to eq(false)
184
222
  expect(prompt.output.string).to eq([
185
223
  "Are you a human? \e[90m(Agree/Disagree)\e[0m ",
224
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m a",
225
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m ag",
226
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agr",
227
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agre",
228
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agree",
229
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agree\n",
186
230
  "\e[1A\e[2K\e[1G",
187
231
  "Are you a human? \e[32mAgree\e[0m\n"
188
232
  ].join)
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.11.0
4
+ version: 0.12.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-26 00:00:00.000000000 Z
11
+ date: 2017-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: necromancer
@@ -142,10 +142,13 @@ files:
142
142
  - examples/expand.rb
143
143
  - examples/in.rb
144
144
  - examples/inputs.rb
145
+ - examples/key_events.rb
145
146
  - examples/keypress.rb
146
147
  - examples/mask.rb
147
148
  - examples/multi_select.rb
148
149
  - examples/multi_select_paged.rb
150
+ - examples/multiline.rb
151
+ - examples/pause.rb
149
152
  - examples/select.rb
150
153
  - examples/select_paginated.rb
151
154
  - examples/slider.rb
@@ -165,10 +168,11 @@ files:
165
168
  - lib/tty/prompt/enum_paginator.rb
166
169
  - lib/tty/prompt/evaluator.rb
167
170
  - lib/tty/prompt/expander.rb
168
- - lib/tty/prompt/history.rb
171
+ - lib/tty/prompt/keypress.rb
169
172
  - lib/tty/prompt/list.rb
170
173
  - lib/tty/prompt/mask_question.rb
171
174
  - lib/tty/prompt/multi_list.rb
175
+ - lib/tty/prompt/multiline.rb
172
176
  - lib/tty/prompt/paginator.rb
173
177
  - lib/tty/prompt/question.rb
174
178
  - lib/tty/prompt/question/checks.rb
@@ -177,7 +181,9 @@ files:
177
181
  - lib/tty/prompt/reader.rb
178
182
  - lib/tty/prompt/reader/codes.rb
179
183
  - lib/tty/prompt/reader/console.rb
184
+ - lib/tty/prompt/reader/history.rb
180
185
  - lib/tty/prompt/reader/key_event.rb
186
+ - lib/tty/prompt/reader/line.rb
181
187
  - lib/tty/prompt/reader/mode.rb
182
188
  - lib/tty/prompt/reader/win_api.rb
183
189
  - lib/tty/prompt/reader/win_console.rb
@@ -186,6 +192,7 @@ files:
186
192
  - lib/tty/prompt/statement.rb
187
193
  - lib/tty/prompt/suggestion.rb
188
194
  - lib/tty/prompt/symbols.rb
195
+ - lib/tty/prompt/timeout.rb
189
196
  - lib/tty/prompt/utils.rb
190
197
  - lib/tty/prompt/version.rb
191
198
  - lib/tty/test_prompt.rb
@@ -236,7 +243,9 @@ files:
236
243
  - spec/unit/question/validate_spec.rb
237
244
  - spec/unit/question/validation/call_spec.rb
238
245
  - spec/unit/question/validation/coerce_spec.rb
246
+ - spec/unit/reader/history_spec.rb
239
247
  - spec/unit/reader/key_event_spec.rb
248
+ - spec/unit/reader/line_spec.rb
240
249
  - spec/unit/reader/publish_keypress_event_spec.rb
241
250
  - spec/unit/reader/read_keypress_spec.rb
242
251
  - spec/unit/reader/read_line_spec.rb
@@ -325,7 +334,9 @@ test_files:
325
334
  - spec/unit/question/validate_spec.rb
326
335
  - spec/unit/question/validation/call_spec.rb
327
336
  - spec/unit/question/validation/coerce_spec.rb
337
+ - spec/unit/reader/history_spec.rb
328
338
  - spec/unit/reader/key_event_spec.rb
339
+ - spec/unit/reader/line_spec.rb
329
340
  - spec/unit/reader/publish_keypress_event_spec.rb
330
341
  - spec/unit/reader/read_keypress_spec.rb
331
342
  - spec/unit/reader/read_line_spec.rb
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module TTY
4
- class Prompt
5
- # A class responsible for storing shell interactions
6
- class History
7
-
8
- attr_reader :max_size
9
-
10
- def initialize(max_size=nil)
11
- @max_size = max_size
12
- end
13
-
14
- end # History
15
- end # Prompt
16
- end # TTY