tty-prompt 0.20.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +29 -4
  4. data/lib/tty/prompt.rb +3 -3
  5. data/lib/tty/prompt/multi_list.rb +33 -10
  6. data/lib/tty/prompt/version.rb +1 -1
  7. metadata +11 -175
  8. data/Rakefile +0 -8
  9. data/examples/ask.rb +0 -7
  10. data/examples/ask_blank.rb +0 -9
  11. data/examples/ask_multiline.rb +0 -7
  12. data/examples/ask_valid.rb +0 -12
  13. data/examples/collect.rb +0 -21
  14. data/examples/echo.rb +0 -11
  15. data/examples/enum_select.rb +0 -7
  16. data/examples/enum_select_disabled.rb +0 -16
  17. data/examples/enum_select_paged.rb +0 -9
  18. data/examples/enum_select_wrapped.rb +0 -15
  19. data/examples/expand.rb +0 -29
  20. data/examples/expand_auto.rb +0 -29
  21. data/examples/in.rb +0 -9
  22. data/examples/inputs.rb +0 -10
  23. data/examples/key_events.rb +0 -15
  24. data/examples/keypress.rb +0 -9
  25. data/examples/mask.rb +0 -13
  26. data/examples/multi_select.rb +0 -8
  27. data/examples/multi_select_disabled.rb +0 -17
  28. data/examples/multi_select_disabled_paged.rb +0 -22
  29. data/examples/multi_select_paged.rb +0 -9
  30. data/examples/multi_select_wrapped.rb +0 -15
  31. data/examples/multiline.rb +0 -9
  32. data/examples/pause.rb +0 -9
  33. data/examples/select.rb +0 -24
  34. data/examples/select_disabled.rb +0 -18
  35. data/examples/select_disabled_paged.rb +0 -22
  36. data/examples/select_enum.rb +0 -8
  37. data/examples/select_filtered.rb +0 -11
  38. data/examples/select_paginated.rb +0 -11
  39. data/examples/select_wrapped.rb +0 -15
  40. data/examples/slider.rb +0 -6
  41. data/examples/validation.rb +0 -9
  42. data/examples/yes_no.rb +0 -7
  43. data/spec/spec_helper.rb +0 -61
  44. data/spec/unit/ask_spec.rb +0 -173
  45. data/spec/unit/block_paginator_spec.rb +0 -84
  46. data/spec/unit/choice/eql_spec.rb +0 -22
  47. data/spec/unit/choice/from_spec.rb +0 -130
  48. data/spec/unit/choices/add_spec.rb +0 -12
  49. data/spec/unit/choices/each_spec.rb +0 -13
  50. data/spec/unit/choices/find_by_spec.rb +0 -10
  51. data/spec/unit/choices/new_spec.rb +0 -10
  52. data/spec/unit/choices/pluck_spec.rb +0 -9
  53. data/spec/unit/collect_spec.rb +0 -96
  54. data/spec/unit/converters/convert_bool_spec.rb +0 -58
  55. data/spec/unit/converters/convert_char_spec.rb +0 -11
  56. data/spec/unit/converters/convert_custom_spec.rb +0 -14
  57. data/spec/unit/converters/convert_date_spec.rb +0 -34
  58. data/spec/unit/converters/convert_file_spec.rb +0 -18
  59. data/spec/unit/converters/convert_number_spec.rb +0 -39
  60. data/spec/unit/converters/convert_path_spec.rb +0 -15
  61. data/spec/unit/converters/convert_range_spec.rb +0 -22
  62. data/spec/unit/converters/convert_regex_spec.rb +0 -12
  63. data/spec/unit/converters/convert_string_spec.rb +0 -21
  64. data/spec/unit/converters/on_error_spec.rb +0 -9
  65. data/spec/unit/distance/distance_spec.rb +0 -73
  66. data/spec/unit/enum_select_spec.rb +0 -518
  67. data/spec/unit/error_spec.rb +0 -20
  68. data/spec/unit/evaluator_spec.rb +0 -67
  69. data/spec/unit/expand_spec.rb +0 -290
  70. data/spec/unit/keypress_spec.rb +0 -66
  71. data/spec/unit/mask_spec.rb +0 -140
  72. data/spec/unit/multi_select_spec.rb +0 -741
  73. data/spec/unit/multiline_spec.rb +0 -77
  74. data/spec/unit/new_spec.rb +0 -20
  75. data/spec/unit/ok_spec.rb +0 -10
  76. data/spec/unit/paginator_spec.rb +0 -92
  77. data/spec/unit/question/checks_spec.rb +0 -97
  78. data/spec/unit/question/default_spec.rb +0 -31
  79. data/spec/unit/question/echo_spec.rb +0 -38
  80. data/spec/unit/question/in_spec.rb +0 -115
  81. data/spec/unit/question/initialize_spec.rb +0 -12
  82. data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
  83. data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
  84. data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
  85. data/spec/unit/question/modify_spec.rb +0 -41
  86. data/spec/unit/question/required_spec.rb +0 -92
  87. data/spec/unit/question/validate_spec.rb +0 -115
  88. data/spec/unit/question/validation/call_spec.rb +0 -31
  89. data/spec/unit/question/validation/coerce_spec.rb +0 -30
  90. data/spec/unit/result_spec.rb +0 -40
  91. data/spec/unit/say_spec.rb +0 -67
  92. data/spec/unit/select_spec.rb +0 -942
  93. data/spec/unit/slider_spec.rb +0 -142
  94. data/spec/unit/statement/initialize_spec.rb +0 -15
  95. data/spec/unit/subscribe_spec.rb +0 -22
  96. data/spec/unit/suggest_spec.rb +0 -28
  97. data/spec/unit/timer_spec.rb +0 -29
  98. data/spec/unit/warn_spec.rb +0 -21
  99. data/spec/unit/yes_no_spec.rb +0 -285
  100. data/tasks/console.rake +0 -11
  101. data/tasks/coverage.rake +0 -11
  102. data/tasks/spec.rake +0 -29
  103. data/tty-prompt.gemspec +0 -40
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt, '.error' do
4
- subject(:prompt) { TTY::TestPrompt.new }
5
-
6
- it 'displays one message' do
7
- prompt.error "Nothing is fine!"
8
- expect(prompt.output.string).to eql "\e[31mNothing is fine!\e[0m\n"
9
- end
10
-
11
- it 'displays many messages' do
12
- prompt.error "Nothing is fine!", "All is broken!"
13
- expect(prompt.output.string).to eql "\e[31mNothing is fine!\e[0m\n\e[31mAll is broken!\e[0m\n"
14
- end
15
-
16
- it 'displays message with option' do
17
- prompt.error "Nothing is fine!", newline: false
18
- expect(prompt.output.string).to eql "\e[31mNothing is fine!\e[0m"
19
- end
20
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Evaluator do
4
- it "checks chained validation procs" do
5
- question = double(:question)
6
- evaluator = TTY::Prompt::Evaluator.new(question)
7
-
8
- evaluator.check { |quest, value|
9
- if value < 21
10
- [value, ["#{value} is not bigger than 21"]]
11
- else
12
- value
13
- end
14
- }
15
-
16
- evaluator.check { |quest, value|
17
- if value < 42
18
- [value, ["#{value} is not bigger than 42"]]
19
- else
20
- value
21
- end
22
- }
23
-
24
- answer = evaluator.call(2)
25
- expect(answer.errors.count).to eq(2)
26
- expect(answer.value).to eq(2)
27
- expect(answer.success?).to eq(false)
28
- expect(answer.failure?).to eq(true)
29
- end
30
-
31
- it "checks chained validation objects" do
32
- question = double(:question)
33
- evaluator = TTY::Prompt::Evaluator.new(question)
34
-
35
- LessThan21 = Class.new do
36
- def self.call(quest, value)
37
- if value < 21
38
- [value, ["#{value} is not bigger than 21"]]
39
- else
40
- value
41
- end
42
- end
43
- end
44
-
45
- LessThan42 = Class.new do
46
- def self.call(quest, value)
47
- if value < 42
48
- [value, ["#{value} is not bigger than 42"]]
49
- else
50
- value
51
- end
52
- end
53
- end
54
-
55
- evaluator.check(LessThan21)
56
- evaluator.check(LessThan42)
57
-
58
- answer = evaluator.call(2)
59
- expect(answer.errors).to match_array([
60
- "2 is not bigger than 21",
61
- "2 is not bigger than 42"
62
- ])
63
- expect(answer.value).to eq(2)
64
- expect(answer.success?).to eq(false)
65
- expect(answer.failure?).to eq(true)
66
- end
67
- end
@@ -1,290 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt, '#expand' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- let(:choices) {
8
- [{
9
- key: 'y',
10
- name: 'Overwrite',
11
- value: :yes
12
- }, {
13
- key: 'n',
14
- name: 'Skip',
15
- value: :no
16
- }, {
17
- key: 'a',
18
- name: 'Overwrite all',
19
- value: :all
20
- }, {
21
- key: 'd',
22
- name: 'Show diff',
23
- value: :diff
24
- }, {
25
- key: 'q',
26
- name: 'Quit',
27
- value: :quit
28
- }]
29
- }
30
-
31
- it "expands default option" do
32
- prompt.input << "\n"
33
- prompt.input.rewind
34
-
35
- result = prompt.expand('Overwrite Gemfile?', choices)
36
- expect(result).to eq(:yes)
37
-
38
- expected_output = [
39
- "Overwrite Gemfile? (enter \"h\" for help) [\e[32my\e[0m,n,a,d,q,h] ",
40
- "\e[2K\e[1G",
41
- "Overwrite Gemfile? \e[32mOverwrite\e[0m\n"
42
- ].join
43
-
44
- expect(prompt.output.string).to eq(expected_output)
45
- end
46
-
47
- it "changes default option" do
48
- prompt.input << "\n"
49
- prompt.input.rewind
50
-
51
- result = prompt.expand('Overwrite Gemfile?', choices, default: 3)
52
- expect(result).to eq(:all)
53
-
54
- expected_output = [
55
- "Overwrite Gemfile? (enter \"h\" for help) [y,n,\e[32ma\e[0m,d,q,h] ",
56
- "\e[2K\e[1G",
57
- "Overwrite Gemfile? \e[32mOverwrite all\e[0m\n"
58
- ].join
59
-
60
- expect(prompt.output.string).to eq(expected_output)
61
- end
62
-
63
- it "expands chosen option with extra information" do
64
- prompt.input << "a\n"
65
- prompt.input.rewind
66
-
67
- result = prompt.expand('Overwrite Gemfile?', choices)
68
- expect(result).to eq(:all)
69
-
70
- expected_output = [
71
- "Overwrite Gemfile? (enter \"h\" for help) [\e[32my\e[0m,n,a,d,q,h] ",
72
- "\e[2K\e[1G",
73
- "Overwrite Gemfile? (enter \"h\" for help) [y,n,\e[32ma\e[0m,d,q,h] ",
74
- "a\n",
75
- "\e[32m>> \e[0mOverwrite all",
76
- "\e[A\e[1G\e[55C",
77
- "\e[2K\e[1G",
78
- "\e[1B",
79
- "\e[2K\e[1G",
80
- "\e[A\e[1G",
81
- "Overwrite Gemfile? \e[32mOverwrite all\e[0m\n"
82
- ].join
83
-
84
- expect(prompt.output.string).to eq(expected_output)
85
- end
86
-
87
- it "expands help option and then defaults" do
88
- prompt.input << "h\nd\n"
89
- prompt.input.rewind
90
-
91
- result = prompt.expand('Overwrite Gemfile?', choices)
92
- expect(result).to eq(:diff)
93
-
94
- expected_output = [
95
- "Overwrite Gemfile? (enter \"h\" for help) [\e[32my\e[0m,n,a,d,q,h] ",
96
- "\e[2K\e[1G",
97
- "Overwrite Gemfile? (enter \"h\" for help) [y,n,a,d,q,\e[32mh\e[0m] h\n",
98
- "\e[32m>> \e[0mprint help",
99
- "\e[A\e[1G\e[55C",
100
- "\e[2K\e[1G",
101
- "\e[1B",
102
- "\e[2K\e[1G",
103
- "\e[A\e[1G",
104
- "Overwrite Gemfile? \n",
105
- " y - Overwrite\n",
106
- " n - Skip\n",
107
- " a - Overwrite all\n",
108
- " d - Show diff\n",
109
- " q - Quit\n",
110
- " h - print help\n",
111
- " Choice [y]: ",
112
- "\e[2K\e[1G\e[1A" * 7,
113
- "\e[2K\e[1G",
114
- "Overwrite Gemfile? \n",
115
- " y - Overwrite\n",
116
- " n - Skip\n",
117
- " a - Overwrite all\n",
118
- " \e[32md - Show diff\e[0m\n",
119
- " q - Quit\n",
120
- " h - print help\n",
121
- " Choice [y]: d",
122
- "\e[2K\e[1G\e[1A" * 7,
123
- "\e[2K\e[1G",
124
- "Overwrite Gemfile? \e[32mShow diff\e[0m\n",
125
- ].join
126
-
127
- expect(prompt.output.string).to eq(expected_output)
128
- end
129
-
130
- it "automatically expands hint" do
131
- prompt.input << "d\n"
132
- prompt.input.rewind
133
-
134
- result = prompt.expand('Overwrite Gemfile?', choices, auto_hint: true)
135
- expect(result).to eq(:diff)
136
-
137
- expected_output = [
138
- "Overwrite Gemfile? (enter \"h\" for help) [\e[32my\e[0m,n,a,d,q,h] ",
139
- "\n\e[32m>> \e[0mOverwrite",
140
- "\e[A\e[1G\e[54C",
141
- "\e[2K\e[1G",
142
- "\e[1B",
143
- "\e[2K\e[1G",
144
- "\e[A\e[1G",
145
- "Overwrite Gemfile? (enter \"h\" for help) [y,n,a,\e[32md\e[0m,q,h] ",
146
- "d\n",
147
- "\e[32m>> \e[0mShow diff",
148
- "\e[A\e[1G\e[55C",
149
- "\e[2K\e[1G",
150
- "\e[1B",
151
- "\e[2K\e[1G",
152
- "\e[A\e[1G",
153
- "Overwrite Gemfile? \e[32mShow diff\e[0m\n",
154
- "\e[32m>> \e[0mShow diff",
155
- "\e[A\e[1G\e[28C\n"
156
- ].join
157
-
158
- expect(prompt.output.string).to eq(expected_output)
159
- end
160
-
161
- it "informs about invalid input when automatically expanding hint" do
162
- prompt = TTY::TestPrompt.new
163
- prompt.on(:keypress) { |e| prompt.trigger(:keybackspace) if e.value == "w" }
164
- prompt.input << "y" << "y" << "\u007F" << "\r"
165
- prompt.input.rewind
166
-
167
- result = prompt.expand('Overwrite Gemfile?', choices, defualt: 1, auto_hint: true)
168
- expect(result).to eq(:yes)
169
-
170
- expected_output = [
171
- "Overwrite Gemfile? (enter \"h\" for help) [\e[32my\e[0m,n,a,d,q,h] ",
172
- "\n\e[32m>> \e[0mOverwrite",
173
- "\e[A\e[1G\e[54C",
174
- "\e[2K\e[1G",
175
- "\e[1B",
176
- "\e[2K\e[1G",
177
- "\e[A\e[1G",
178
- "Overwrite Gemfile? (enter \"h\" for help) [\e[32my\e[0m,n,a,d,q,h] ",
179
- "y\n",
180
- "\e[32m>> \e[0mOverwrite",
181
- "\e[A\e[1G\e[55C",
182
- "\e[2K\e[1G",
183
- "\e[1B",
184
- "\e[2K\e[1G",
185
- "\e[A\e[1G",
186
- "Overwrite Gemfile? (enter \"h\" for help) [y,n,a,d,q,h] ",
187
- "yy\n",
188
- "\e[32m>> \e[0minvalid option",
189
- "\e[A\e[1G\e[56C",
190
- "\e[2K\e[1G",
191
- "\e[1B",
192
- "\e[2K\e[1G",
193
- "\e[A\e[1G",
194
- "Overwrite Gemfile? (enter \"h\" for help) [\e[32my\e[0m,n,a,d,q,h] ",
195
- "y\n",
196
- "\e[32m>> \e[0mOverwrite",
197
- "\e[A\e[1G\e[55C",
198
- "\e[2K\e[1G",
199
- "\e[1B",
200
- "\e[2K\e[1G",
201
- "\e[A\e[1G",
202
- "Overwrite Gemfile? \e[32mOverwrite\e[0m\n",
203
- "\e[32m>> \e[0mOverwrite",
204
- "\e[A\e[1G\e[28C\n"
205
- ].join
206
-
207
- expect(prompt.output.string).to eq(expected_output)
208
- end
209
-
210
- it "specifies options through DSL" do
211
- prompt.input << "\n"
212
- prompt.input.rewind
213
-
214
- result = prompt.expand('Overwrite Gemfile?') do |q|
215
- q.default 4
216
-
217
- q.choice key: 'y', name: 'Overwrite', value: :yes
218
- q.choice key: 'n', name: 'Skip', value: :no
219
- q.choice key: 'a', name: 'Overwrite all', value: :all
220
- q.choice key: 'd', name: 'Show diff', value: :diff
221
- q.choice key: 'q', name: 'Quit', value: :quit
222
- end
223
-
224
- expect(result).to eq(:diff)
225
-
226
- expected_output = [
227
- "Overwrite Gemfile? (enter \"h\" for help) [y,n,a,\e[32md\e[0m,q,h] ",
228
- "\e[2K\e[1G",
229
- "Overwrite Gemfile? \e[32mShow diff\e[0m\n"
230
- ].join
231
-
232
- expect(prompt.output.string).to eq(expected_output)
233
- end
234
-
235
- it "specifies options through DSL and executes value" do
236
- prompt.input << "\n"
237
- prompt.input.rewind
238
-
239
- result = prompt.expand('Overwrite Gemfile?') do |q|
240
- q.choice key: 'y', name: 'Overwrite' do :ok end
241
- q.choice key: 'n', name: 'Skip', value: :no
242
- q.choice key: 'a', name: 'Overwrite all', value: :all
243
- q.choice key: 'd', name: 'Show diff', value: :diff
244
- q.choice key: 'q', name: 'Quit', value: :quit
245
- end
246
-
247
- expect(result).to eq(:ok)
248
-
249
- expected_output = [
250
- "Overwrite Gemfile? (enter \"h\" for help) [\e[32my\e[0m,n,a,d,q,h] ",
251
- "\e[2K\e[1G",
252
- "Overwrite Gemfile? \e[32mOverwrite\e[0m\n"
253
- ].join
254
-
255
- expect(prompt.output.string).to eq(expected_output)
256
- end
257
-
258
- it "fails to expand due to lack of key attribute" do
259
- choices = [{ name: 'Overwrite', value: :yes }]
260
-
261
- expect {
262
- prompt.expand('Overwrite Gemfile?', choices)
263
- }.to raise_error(TTY::Prompt::ConfigurationError, /Choice Overwrite is missing a :key attribute/)
264
- end
265
-
266
- it "fails to expand due to wrong key length" do
267
- choices = [{ key: 'long', name: 'Overwrite', value: :yes }]
268
-
269
- expect {
270
- prompt.expand('Overwrite Gemfile?', choices)
271
- }.to raise_error(TTY::Prompt::ConfigurationError, /Choice key `long` is more than one character long/)
272
- end
273
-
274
- it "fails to expand due to reserve key" do
275
- choices = [{ key: 'h', name: 'Overwrite', value: :yes }]
276
-
277
- expect {
278
- prompt.expand('Overwrite Gemfile?', choices)
279
- }.to raise_error(TTY::Prompt::ConfigurationError, /Choice key `h` is reserved for help menu/)
280
- end
281
-
282
- it "fails to expand due to duplicate key" do
283
- choices = [{ key: 'y', name: 'Overwrite', value: :yes },
284
- { key: 'y', name: 'Change', value: :yes }]
285
-
286
- expect {
287
- prompt.expand('Overwrite Gemfile?', choices)
288
- }.to raise_error(TTY::Prompt::ConfigurationError, /Choice key `y` is a duplicate/)
289
- end
290
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question, '#keypress' do
4
- it 'receives line feed with echo on' do
5
- prompt = TTY::TestPrompt.new
6
- prompt.input << "\n"
7
- prompt.input.rewind
8
-
9
- answer = prompt.keypress("Press key:", echo: true)
10
-
11
- expect(answer).to eq("\n")
12
- expect(prompt.output.string).to eq([
13
- "Press key: ",
14
- "\e[2K\e[1G\e[1A\e[2K\e[1G",
15
- "Press key: \e[32m\n\e[0m\n",
16
- ].join)
17
- end
18
-
19
- it 'asks for a keypress with echo on' do
20
- prompt = TTY::TestPrompt.new
21
- prompt.input << "abcd"
22
- prompt.input.rewind
23
-
24
- answer = prompt.keypress("Press key:", echo: true)
25
-
26
- expect(answer).to eq("a")
27
- expect(prompt.output.string).to eq([
28
- "Press key: ",
29
- "\e[2K\e[1G",
30
- "Press key: \e[32ma\e[0m\n",
31
- ].join)
32
- end
33
-
34
- it 'asks for a keypress with echo off' do
35
- prompt = TTY::TestPrompt.new
36
- prompt.input << "abcd"
37
- prompt.input.rewind
38
-
39
- answer = prompt.keypress("Press key:")
40
-
41
- expect(answer).to eq("a")
42
- expect(prompt.output.string).to eq([
43
- "Press key: ",
44
- "\e[2K\e[1G",
45
- "Press key: \n",
46
- ].join)
47
- end
48
-
49
- it "interrupts input" do
50
- prompt = TTY::TestPrompt.new(interrupt: :exit)
51
- prompt.input << "\x03"
52
- prompt.input.rewind
53
-
54
- expect {
55
- prompt.keypress("Press key:")
56
- }.to raise_error(SystemExit)
57
- end
58
-
59
- it "timeouts when no key provided" do
60
- prompt = TTY::TestPrompt.new(interrupt: :exit)
61
-
62
- prompt.keypress("Press any key or continue in :countdown", timeout: 0.01)
63
-
64
- expect(prompt.output.string).to include("Press any key or continue in 0.00")
65
- end
66
- end
@@ -1,140 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt, '#mask' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- let(:symbols) { TTY::Prompt::Symbols.symbols }
8
-
9
- it "masks output by default" do
10
- prompt.input << "pass\r"
11
- prompt.input.rewind
12
-
13
- answer = prompt.mask("What is your password?")
14
-
15
- expect(answer).to eql("pass")
16
- expect(prompt.output.string).to eq([
17
- "What is your password? ",
18
- "\e[2K\e[1G",
19
- "What is your password? #{symbols[:dot]}",
20
- "\e[2K\e[1G",
21
- "What is your password? #{symbols[:dot] * 2}",
22
- "\e[2K\e[1G",
23
- "What is your password? #{symbols[:dot] * 3}",
24
- "\e[2K\e[1G",
25
- "What is your password? #{symbols[:dot] * 4}",
26
- "\e[2K\e[1G",
27
- "What is your password? \e[32m#{symbols[:dot] * 4}\e[0m\n",
28
- "\e[1A\e[2K\e[1G",
29
- "What is your password? \e[32m#{symbols[:dot] * 4}\e[0m\n"
30
- ].join)
31
- end
32
-
33
- it 'masks output with custom character' do
34
- prompt.input << "pass\r"
35
- prompt.input.rewind
36
-
37
- answer = prompt.mask("What is your password?") { |q| q.mask('*') }
38
-
39
- expect(answer).to eql("pass")
40
- expect(prompt.output.string).to eq([
41
- "What is your password? ",
42
- "\e[2K\e[1G",
43
- "What is your password? *",
44
- "\e[2K\e[1G",
45
- "What is your password? **",
46
- "\e[2K\e[1G",
47
- "What is your password? ***",
48
- "\e[2K\e[1G",
49
- "What is your password? ****",
50
- "\e[2K\e[1G",
51
- "What is your password? \e[32m****\e[0m\n",
52
- "\e[1A\e[2K\e[1G",
53
- "What is your password? \e[32m****\e[0m\n",
54
- ].join)
55
- end
56
-
57
- it "masks with unicode character" do
58
- prompt.input << "lov\n"
59
- prompt.input.rewind
60
-
61
- answer = prompt.mask("What is your password?", mask: "\u2665")
62
-
63
- expect(answer).to eql("lov")
64
- expect(prompt.output.string).to eq([
65
- "What is your password? ",
66
- "\e[2K\e[1G",
67
- "What is your password? ♥",
68
- "\e[2K\e[1G",
69
- "What is your password? ♥♥",
70
- "\e[2K\e[1G",
71
- "What is your password? ♥♥♥",
72
- "\e[2K\e[1G",
73
- "What is your password? \e[32m♥♥♥\e[0m\n",
74
- "\e[1A\e[2K\e[1G",
75
- "What is your password? \e[32m♥♥♥\e[0m\n",
76
- ].join)
77
- end
78
-
79
- it 'ignores mask if echo is off' do
80
- prompt.input << "pass\n"
81
- prompt.input.rewind
82
-
83
- answer = prompt.mask('What is your password?') do |q|
84
- q.echo false
85
- q.mask '*'
86
- end
87
-
88
- expect(answer).to eql("pass")
89
- expect(prompt.output.string).to eq([
90
- "What is your password? ",
91
- "\e[2K\e[1G",
92
- "What is your password? ",
93
- "\e[2K\e[1G",
94
- "What is your password? ",
95
- "\e[2K\e[1G",
96
- "What is your password? ",
97
- "\e[2K\e[1G",
98
- "What is your password? ",
99
- "\e[2K\e[1G",
100
- "What is your password? \n",
101
- "\e[1A\e[2K\e[1G",
102
- "What is your password? \n",
103
- ].join)
104
- end
105
-
106
- it "validates input" do
107
- prompt = TTY::TestPrompt.new(symbols: {dot: '*'})
108
- prompt.input << "no\nyes\n"
109
- prompt.input.rewind
110
- answer = prompt.mask('What is your password?') do |q|
111
- q.echo true
112
- q.validate(/[a-z]{3,4}/)
113
- q.messages[:valid?] = 'Not valid'
114
- end
115
- expect(answer).to eq('yes')
116
- expect(prompt.output.string).to eq([
117
- "What is your password? ",
118
- "\e[2K\e[1G",
119
- "What is your password? *",
120
- "\e[2K\e[1G",
121
- "What is your password? **",
122
- "\e[2K\e[1G",
123
- "What is your password? \e[32m**\e[0m\n",
124
- "\e[31m>>\e[0m Not valid",
125
- "\e[1A\e[2K\e[1G",
126
- "What is your password? \e[31m**\e[0m",
127
- "\e[2K\e[1G",
128
- "What is your password? *",
129
- "\e[2K\e[1G",
130
- "What is your password? **",
131
- "\e[2K\e[1G",
132
- "What is your password? ***",
133
- "\e[2K\e[1G",
134
- "What is your password? \e[32m***\e[0m\n",
135
- "\e[2K\e[1G",
136
- "\e[1A\e[2K\e[1G",
137
- "What is your password? \e[32m***\e[0m\n"
138
- ].join)
139
- end
140
- end