tty-prompt 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/CHANGELOG.md +12 -0
- data/README.md +3 -3
- data/appveyor.yml +2 -0
- data/lib/tty/prompt/keypress.rb +7 -4
- data/lib/tty/prompt/reader.rb +1 -1
- data/lib/tty/prompt/reader/win_api.rb +14 -0
- data/lib/tty/prompt/reader/win_console.rb +9 -2
- data/lib/tty/prompt/timeout.rb +44 -23
- data/lib/tty/prompt/version.rb +1 -1
- data/tty-prompt.gemspec +6 -3
- metadata +21 -131
- data/spec/spec_helper.rb +0 -45
- data/spec/unit/ask_spec.rb +0 -132
- data/spec/unit/choice/eql_spec.rb +0 -22
- data/spec/unit/choice/from_spec.rb +0 -29
- data/spec/unit/choices/add_spec.rb +0 -12
- data/spec/unit/choices/each_spec.rb +0 -13
- data/spec/unit/choices/find_by_spec.rb +0 -10
- data/spec/unit/choices/new_spec.rb +0 -10
- data/spec/unit/choices/pluck_spec.rb +0 -9
- data/spec/unit/collect_spec.rb +0 -33
- data/spec/unit/converters/convert_bool_spec.rb +0 -58
- data/spec/unit/converters/convert_char_spec.rb +0 -11
- data/spec/unit/converters/convert_custom_spec.rb +0 -14
- data/spec/unit/converters/convert_date_spec.rb +0 -34
- data/spec/unit/converters/convert_file_spec.rb +0 -17
- data/spec/unit/converters/convert_number_spec.rb +0 -39
- data/spec/unit/converters/convert_path_spec.rb +0 -18
- data/spec/unit/converters/convert_range_spec.rb +0 -22
- data/spec/unit/converters/convert_regex_spec.rb +0 -12
- data/spec/unit/converters/convert_string_spec.rb +0 -21
- data/spec/unit/converters/on_error_spec.rb +0 -9
- data/spec/unit/distance/distance_spec.rb +0 -73
- data/spec/unit/enum_paginator_spec.rb +0 -65
- data/spec/unit/enum_select_spec.rb +0 -310
- data/spec/unit/error_spec.rb +0 -20
- data/spec/unit/evaluator_spec.rb +0 -67
- data/spec/unit/expand_spec.rb +0 -198
- data/spec/unit/keypress_spec.rb +0 -58
- data/spec/unit/mask_spec.rb +0 -132
- data/spec/unit/multi_select_spec.rb +0 -319
- data/spec/unit/multiline_spec.rb +0 -77
- data/spec/unit/new_spec.rb +0 -20
- data/spec/unit/ok_spec.rb +0 -10
- data/spec/unit/paginator_spec.rb +0 -63
- data/spec/unit/question/checks_spec.rb +0 -97
- data/spec/unit/question/default_spec.rb +0 -31
- data/spec/unit/question/echo_spec.rb +0 -38
- data/spec/unit/question/in_spec.rb +0 -115
- data/spec/unit/question/initialize_spec.rb +0 -12
- data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
- data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
- data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
- data/spec/unit/question/modify_spec.rb +0 -41
- data/spec/unit/question/required_spec.rb +0 -92
- data/spec/unit/question/validate_spec.rb +0 -115
- data/spec/unit/question/validation/call_spec.rb +0 -31
- data/spec/unit/question/validation/coerce_spec.rb +0 -30
- data/spec/unit/reader/history_spec.rb +0 -172
- data/spec/unit/reader/key_event_spec.rb +0 -86
- data/spec/unit/reader/line_spec.rb +0 -110
- data/spec/unit/reader/publish_keypress_event_spec.rb +0 -94
- data/spec/unit/reader/read_keypress_spec.rb +0 -80
- data/spec/unit/reader/read_line_spec.rb +0 -68
- data/spec/unit/reader/read_multiline_spec.rb +0 -60
- data/spec/unit/result_spec.rb +0 -40
- data/spec/unit/say_spec.rb +0 -67
- data/spec/unit/select_spec.rb +0 -359
- data/spec/unit/slider_spec.rb +0 -96
- data/spec/unit/statement/initialize_spec.rb +0 -15
- data/spec/unit/suggest_spec.rb +0 -28
- data/spec/unit/warn_spec.rb +0 -21
- data/spec/unit/yes_no_spec.rb +0 -235
@@ -1,319 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt do
|
4
|
-
let(:symbols) { TTY::Prompt::Symbols.symbols }
|
5
|
-
|
6
|
-
it "selects nothing when return pressed immediately" do
|
7
|
-
prompt = TTY::TestPrompt.new
|
8
|
-
choices = %w(vodka beer wine whisky bourbon)
|
9
|
-
prompt.input << "\r"
|
10
|
-
prompt.input.rewind
|
11
|
-
expect(prompt.multi_select("Select drinks?", choices)). to eq([])
|
12
|
-
expect(prompt.output.string).to eq([
|
13
|
-
"\e[?25lSelect drinks? \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
|
14
|
-
"#{symbols[:pointer]} #{symbols[:radio_off]} vodka\n",
|
15
|
-
" #{symbols[:radio_off]} beer\n",
|
16
|
-
" #{symbols[:radio_off]} wine\n",
|
17
|
-
" #{symbols[:radio_off]} whisky\n",
|
18
|
-
" #{symbols[:radio_off]} bourbon",
|
19
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
20
|
-
"Select drinks? \n\e[?25h"
|
21
|
-
].join)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "selects item when space pressed" do
|
25
|
-
prompt = TTY::TestPrompt.new
|
26
|
-
choices = %w(vodka beer wine whisky bourbon)
|
27
|
-
prompt.input << " \r"
|
28
|
-
prompt.input.rewind
|
29
|
-
expect(prompt.multi_select("Select drinks?", choices)). to eq(['vodka'])
|
30
|
-
expect(prompt.output.string).to eq([
|
31
|
-
"\e[?25lSelect drinks? \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
|
32
|
-
"#{symbols[:pointer]} #{symbols[:radio_off]} vodka\n",
|
33
|
-
" #{symbols[:radio_off]} beer\n",
|
34
|
-
" #{symbols[:radio_off]} wine\n",
|
35
|
-
" #{symbols[:radio_off]} whisky\n",
|
36
|
-
" #{symbols[:radio_off]} bourbon",
|
37
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
38
|
-
"Select drinks? vodka\n",
|
39
|
-
"#{symbols[:pointer]} \e[32m#{symbols[:radio_on]}\e[0m vodka\n",
|
40
|
-
" #{symbols[:radio_off]} beer\n",
|
41
|
-
" #{symbols[:radio_off]} wine\n",
|
42
|
-
" #{symbols[:radio_off]} whisky\n",
|
43
|
-
" #{symbols[:radio_off]} bourbon",
|
44
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
45
|
-
"Select drinks? \e[32mvodka\e[0m\n\e[?25h"
|
46
|
-
].join)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "selects item when space pressed but doesn't echo item if echo: false" do
|
50
|
-
prompt = TTY::TestPrompt.new
|
51
|
-
choices = %w(vodka beer wine whisky bourbon)
|
52
|
-
prompt.input << " \r"
|
53
|
-
prompt.input.rewind
|
54
|
-
expect(prompt.multi_select("Select drinks?", choices, echo: false)). to eq(['vodka'])
|
55
|
-
expect(prompt.output.string).to eq([
|
56
|
-
"\e[?25lSelect drinks? \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
|
57
|
-
"#{symbols[:pointer]} #{symbols[:radio_off]} vodka\n",
|
58
|
-
" #{symbols[:radio_off]} beer\n",
|
59
|
-
" #{symbols[:radio_off]} wine\n",
|
60
|
-
" #{symbols[:radio_off]} whisky\n",
|
61
|
-
" #{symbols[:radio_off]} bourbon",
|
62
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
63
|
-
"Select drinks? \n",
|
64
|
-
"#{symbols[:pointer]} \e[32m#{symbols[:radio_on]}\e[0m vodka\n",
|
65
|
-
" #{symbols[:radio_off]} beer\n",
|
66
|
-
" #{symbols[:radio_off]} wine\n",
|
67
|
-
" #{symbols[:radio_off]} whisky\n",
|
68
|
-
" #{symbols[:radio_off]} bourbon",
|
69
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
70
|
-
"Select drinks? \n\e[?25h"
|
71
|
-
].join)
|
72
|
-
end
|
73
|
-
|
74
|
-
it "sets choice custom values" do
|
75
|
-
prompt = TTY::TestPrompt.new
|
76
|
-
choices = {vodka: 1, beer: 2, wine: 3, whisky: 4, bourbon: 5}
|
77
|
-
prompt.input << " \r"
|
78
|
-
prompt.input.rewind
|
79
|
-
expect(prompt.multi_select("Select drinks?", choices)).to eq([1])
|
80
|
-
expect(prompt.output.string).to eq([
|
81
|
-
"\e[?25lSelect drinks? \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
|
82
|
-
"#{symbols[:pointer]} #{symbols[:radio_off]} vodka\n",
|
83
|
-
" #{symbols[:radio_off]} beer\n",
|
84
|
-
" #{symbols[:radio_off]} wine\n",
|
85
|
-
" #{symbols[:radio_off]} whisky\n",
|
86
|
-
" #{symbols[:radio_off]} bourbon",
|
87
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
88
|
-
"Select drinks? vodka\n",
|
89
|
-
"#{symbols[:pointer]} \e[32m#{symbols[:radio_on]}\e[0m vodka\n",
|
90
|
-
" #{symbols[:radio_off]} beer\n",
|
91
|
-
" #{symbols[:radio_off]} wine\n",
|
92
|
-
" #{symbols[:radio_off]} whisky\n",
|
93
|
-
" #{symbols[:radio_off]} bourbon",
|
94
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
95
|
-
"Select drinks? \e[32mvodka\e[0m\n\e[?25h"
|
96
|
-
].join)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "sets choice name and value through DSL" do
|
100
|
-
prompt = TTY::TestPrompt.new
|
101
|
-
prompt.input << " \r"
|
102
|
-
prompt.input.rewind
|
103
|
-
value = prompt.multi_select("Select drinks?") do |menu|
|
104
|
-
menu.enum ')'
|
105
|
-
|
106
|
-
menu.choice :vodka, {score: 1}
|
107
|
-
menu.choice :beer, 2
|
108
|
-
menu.choice :wine, 3
|
109
|
-
menu.choices whisky: 4, bourbon: 5
|
110
|
-
end
|
111
|
-
expect(value).to eq([{score: 1}])
|
112
|
-
expect(prompt.output.string).to eq([
|
113
|
-
"\e[?25lSelect drinks? \e[90m(Use arrow or number (1-5) keys, press Space to select and Enter to finish)\e[0m\n",
|
114
|
-
"#{symbols[:pointer]} #{symbols[:radio_off]} 1) vodka\n",
|
115
|
-
" #{symbols[:radio_off]} 2) beer\n",
|
116
|
-
" #{symbols[:radio_off]} 3) wine\n",
|
117
|
-
" #{symbols[:radio_off]} 4) whisky\n",
|
118
|
-
" #{symbols[:radio_off]} 5) bourbon",
|
119
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
120
|
-
"Select drinks? vodka\n",
|
121
|
-
"#{symbols[:pointer]} \e[32m#{symbols[:radio_on]}\e[0m 1) vodka\n",
|
122
|
-
" #{symbols[:radio_off]} 2) beer\n",
|
123
|
-
" #{symbols[:radio_off]} 3) wine\n",
|
124
|
-
" #{symbols[:radio_off]} 4) whisky\n",
|
125
|
-
" #{symbols[:radio_off]} 5) bourbon",
|
126
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
127
|
-
"Select drinks? \e[32mvodka\e[0m\n\e[?25h"
|
128
|
-
].join)
|
129
|
-
end
|
130
|
-
|
131
|
-
it "sets default options through DSL syntax" do
|
132
|
-
prompt = TTY::TestPrompt.new
|
133
|
-
prompt.input << "\r"
|
134
|
-
prompt.input.rewind
|
135
|
-
value = prompt.multi_select("Select drinks?") do |menu|
|
136
|
-
menu.default 2, 5
|
137
|
-
|
138
|
-
menu.choice :vodka, {score: 10}
|
139
|
-
menu.choice :beer, {score: 20}
|
140
|
-
menu.choice :wine, {score: 30}
|
141
|
-
menu.choice :whisky, {score: 40}
|
142
|
-
menu.choice :bourbon, {score: 50}
|
143
|
-
end
|
144
|
-
expect(value).to match_array([{score: 20}, {score: 50}])
|
145
|
-
expect(prompt.output.string).to eq([
|
146
|
-
"\e[?25lSelect drinks? beer, bourbon \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
|
147
|
-
" #{symbols[:radio_off]} vodka\n",
|
148
|
-
" \e[32m#{symbols[:radio_on]}\e[0m beer\n",
|
149
|
-
" #{symbols[:radio_off]} wine\n",
|
150
|
-
" #{symbols[:radio_off]} whisky\n",
|
151
|
-
"#{symbols[:pointer]} \e[32m#{symbols[:radio_on]}\e[0m bourbon",
|
152
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
153
|
-
"Select drinks? \e[32mbeer, bourbon\e[0m\n\e[?25h",
|
154
|
-
].join)
|
155
|
-
end
|
156
|
-
|
157
|
-
it "sets default options through hash syntax" do
|
158
|
-
prompt = TTY::TestPrompt.new
|
159
|
-
prompt.input << "\r"
|
160
|
-
prompt.input.rewind
|
161
|
-
value = prompt.multi_select("Select drinks?", default: [2, 5]) do |menu|
|
162
|
-
menu.choice :vodka, {score: 10}
|
163
|
-
menu.choice :beer, {score: 20}
|
164
|
-
menu.choice :wine, {score: 30}
|
165
|
-
menu.choice :whisky, {score: 40}
|
166
|
-
menu.choice :bourbon, {score: 50}
|
167
|
-
end
|
168
|
-
expect(value).to match_array([{score: 20}, {score: 50}])
|
169
|
-
end
|
170
|
-
|
171
|
-
it "raises error for defaults out of range" do
|
172
|
-
prompt = TTY::TestPrompt.new
|
173
|
-
prompt.input << "\r"
|
174
|
-
prompt.input.rewind
|
175
|
-
expect {
|
176
|
-
prompt.multi_select("Select drinks?", default: [2, 6]) do |menu|
|
177
|
-
menu.choice :vodka, {score: 10}
|
178
|
-
menu.choice :beer, {score: 20}
|
179
|
-
menu.choice :wine, {score: 30}
|
180
|
-
menu.choice :whisky, {score: 40}
|
181
|
-
menu.choice :bourbon, {score: 50}
|
182
|
-
end
|
183
|
-
}.to raise_error(TTY::Prompt::ConfigurationError,
|
184
|
-
/default index `6` out of range \(1 - 5\)/)
|
185
|
-
end
|
186
|
-
|
187
|
-
it "sets prompt prefix" do
|
188
|
-
prompt = TTY::TestPrompt.new(prefix: '[?] ')
|
189
|
-
choices = %w(vodka beer wine whisky bourbon)
|
190
|
-
prompt.input << "\r"
|
191
|
-
prompt.input.rewind
|
192
|
-
expect(prompt.multi_select("Select drinks?", choices)). to eq([])
|
193
|
-
expect(prompt.output.string).to eq([
|
194
|
-
"\e[?25l[?] Select drinks? \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
|
195
|
-
"#{symbols[:pointer]} #{symbols[:radio_off]} vodka\n",
|
196
|
-
" #{symbols[:radio_off]} beer\n",
|
197
|
-
" #{symbols[:radio_off]} wine\n",
|
198
|
-
" #{symbols[:radio_off]} whisky\n",
|
199
|
-
" #{symbols[:radio_off]} bourbon",
|
200
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
201
|
-
"[?] Select drinks? \n\e[?25h"
|
202
|
-
].join)
|
203
|
-
end
|
204
|
-
|
205
|
-
it "changes selected item color & marker" do
|
206
|
-
prompt = TTY::TestPrompt.new
|
207
|
-
choices = %w(vodka beer wine whisky bourbon)
|
208
|
-
prompt.input << "\r"
|
209
|
-
prompt.input.rewind
|
210
|
-
options = {default: [1], active_color: :blue, marker: '>'}
|
211
|
-
expect(prompt.multi_select("Select drinks?", choices, options)). to eq(['vodka'])
|
212
|
-
expect(prompt.output.string).to eq([
|
213
|
-
"\e[?25lSelect drinks? vodka \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
|
214
|
-
"> \e[34m#{symbols[:radio_on]}\e[0m vodka\n",
|
215
|
-
" #{symbols[:radio_off]} beer\n",
|
216
|
-
" #{symbols[:radio_off]} wine\n",
|
217
|
-
" #{symbols[:radio_off]} whisky\n",
|
218
|
-
" #{symbols[:radio_off]} bourbon",
|
219
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
220
|
-
"Select drinks? \e[34mvodka\e[0m\n\e[?25h"
|
221
|
-
].join)
|
222
|
-
end
|
223
|
-
|
224
|
-
it "changes help text" do
|
225
|
-
prompt = TTY::TestPrompt.new
|
226
|
-
choices = %w(vodka beer wine whisky bourbon)
|
227
|
-
prompt.input << "\r"
|
228
|
-
prompt.input.rewind
|
229
|
-
expect(prompt.multi_select("Select drinks?", choices, help: '(Bash keyboard)')). to eq([])
|
230
|
-
expect(prompt.output.string).to eq([
|
231
|
-
"\e[?25lSelect drinks? \e[90m(Bash keyboard)\e[0m\n",
|
232
|
-
"#{symbols[:pointer]} #{symbols[:radio_off]} vodka\n",
|
233
|
-
" #{symbols[:radio_off]} beer\n",
|
234
|
-
" #{symbols[:radio_off]} wine\n",
|
235
|
-
" #{symbols[:radio_off]} whisky\n",
|
236
|
-
" #{symbols[:radio_off]} bourbon",
|
237
|
-
"\e[2K\e[1G\e[1A" * 5, "\e[2K\e[1G",
|
238
|
-
"Select drinks? \n\e[?25h"
|
239
|
-
].join)
|
240
|
-
end
|
241
|
-
|
242
|
-
it "paginates long selections" do
|
243
|
-
prompt = TTY::TestPrompt.new
|
244
|
-
choices = %w(A B C D E F G H)
|
245
|
-
prompt.input << "\r"
|
246
|
-
prompt.input.rewind
|
247
|
-
value = prompt.multi_select("What letter?", choices, per_page: 3, default: 4)
|
248
|
-
expect(value).to eq(['D'])
|
249
|
-
expect(prompt.output.string).to eq([
|
250
|
-
"\e[?25lWhat letter? D \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
|
251
|
-
"#{symbols[:pointer]} \e[32m#{symbols[:radio_on]}\e[0m D\n",
|
252
|
-
" #{symbols[:radio_off]} E\n",
|
253
|
-
" #{symbols[:radio_off]} F\n",
|
254
|
-
"\e[90m(Move up or down to reveal more choices)\e[0m",
|
255
|
-
"\e[2K\e[1G\e[1A" * 4, "\e[2K\e[1G",
|
256
|
-
"What letter? \e[32mD\e[0m\n\e[?25h",
|
257
|
-
].join)
|
258
|
-
end
|
259
|
-
|
260
|
-
it "paginates choices as hash object" do
|
261
|
-
prompt = TTY::TestPrompt.new
|
262
|
-
choices = {A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8}
|
263
|
-
prompt.input << "\r"
|
264
|
-
prompt.input.rewind
|
265
|
-
value = prompt.multi_select("What letter?", choices, default: 4, per_page: 3)
|
266
|
-
expect(value).to eq([4])
|
267
|
-
expect(prompt.output.string).to eq([
|
268
|
-
"\e[?25lWhat letter? D \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
|
269
|
-
"#{symbols[:pointer]} \e[32m#{symbols[:radio_on]}\e[0m D\n",
|
270
|
-
" #{symbols[:radio_off]} E\n",
|
271
|
-
" #{symbols[:radio_off]} F\n",
|
272
|
-
"\e[90m(Move up or down to reveal more choices)\e[0m",
|
273
|
-
"\e[2K\e[1G\e[1A" * 4, "\e[2K\e[1G",
|
274
|
-
"What letter? \e[32mD\e[0m\n\e[?25h",
|
275
|
-
].join)
|
276
|
-
end
|
277
|
-
|
278
|
-
it "paginates long selections through DSL" do
|
279
|
-
prompt = TTY::TestPrompt.new
|
280
|
-
choices = %w(A B C D E F G H)
|
281
|
-
prompt.input << "\r"
|
282
|
-
prompt.input.rewind
|
283
|
-
value = prompt.multi_select("What letter?") do |menu|
|
284
|
-
menu.per_page 3
|
285
|
-
menu.page_help '(Wiggle thy finger up or down to see more)'
|
286
|
-
menu.default 4
|
287
|
-
menu.choices choices
|
288
|
-
end
|
289
|
-
expect(value).to eq(['D'])
|
290
|
-
expect(prompt.output.string).to eq([
|
291
|
-
"\e[?25lWhat letter? D \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
|
292
|
-
"#{symbols[:pointer]} \e[32m#{symbols[:radio_on]}\e[0m D\n",
|
293
|
-
" #{symbols[:radio_off]} E\n",
|
294
|
-
" #{symbols[:radio_off]} F\n",
|
295
|
-
"\e[90m(Wiggle thy finger up or down to see more)\e[0m",
|
296
|
-
"\e[2K\e[1G\e[1A" * 4, "\e[2K\e[1G",
|
297
|
-
"What letter? \e[32mD\e[0m\n\e[?25h",
|
298
|
-
].join)
|
299
|
-
end
|
300
|
-
|
301
|
-
it "doesn't paginate short selections" do
|
302
|
-
prompt = TTY::TestPrompt.new
|
303
|
-
choices = %w(A B C D)
|
304
|
-
prompt.input << "\r"
|
305
|
-
prompt.input.rewind
|
306
|
-
value = prompt.multi_select("What letter?", choices, per_page: 4, default: 1)
|
307
|
-
expect(value).to eq(['A'])
|
308
|
-
|
309
|
-
expect(prompt.output.string).to eq([
|
310
|
-
"\e[?25lWhat letter? A \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
|
311
|
-
"#{symbols[:pointer]} \e[32m#{symbols[:radio_on]}\e[0m A\n",
|
312
|
-
" #{symbols[:radio_off]} B\n",
|
313
|
-
" #{symbols[:radio_off]} C\n",
|
314
|
-
" #{symbols[:radio_off]} D",
|
315
|
-
"\e[2K\e[1G\e[1A" * 4, "\e[2K\e[1G",
|
316
|
-
"What letter? \e[32mA\e[0m\n\e[?25h",
|
317
|
-
].join)
|
318
|
-
end
|
319
|
-
end
|
data/spec/unit/multiline_spec.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt::Question, '#multiline' do
|
4
|
-
it 'reads no lines' do
|
5
|
-
prompt = TTY::TestPrompt.new
|
6
|
-
prompt.input << "\C-d"
|
7
|
-
prompt.input.rewind
|
8
|
-
|
9
|
-
answer = prompt.multiline("Description?")
|
10
|
-
|
11
|
-
expect(answer).to eq([])
|
12
|
-
expect(prompt.output.string).to eq([
|
13
|
-
"Description? \e[90m(Press CTRL-D or CTRL-Z to finish)\e[0m\n",
|
14
|
-
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
15
|
-
"Description? \n"
|
16
|
-
].join)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "uses defualt when no input" do
|
20
|
-
prompt = TTY::TestPrompt.new
|
21
|
-
prompt.input << "\C-d"
|
22
|
-
prompt.input.rewind
|
23
|
-
|
24
|
-
answer = prompt.multiline("Description?", default: 'A super sweet prompt')
|
25
|
-
|
26
|
-
expect(answer).to eq([])
|
27
|
-
expect(prompt.output.string).to eq([
|
28
|
-
"Description? \e[90m(Press CTRL-D or CTRL-Z to finish)\e[0m\n",
|
29
|
-
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
30
|
-
"Description? \e[32mA super sweet prompt\e[0m\n"
|
31
|
-
].join)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "changes help text" do
|
35
|
-
prompt = TTY::TestPrompt.new
|
36
|
-
prompt.input << "\C-d"
|
37
|
-
prompt.input.rewind
|
38
|
-
|
39
|
-
answer = prompt.multiline("Description?") do |q|
|
40
|
-
q.default 'A super sweet prompt'
|
41
|
-
q.help '(Press thy ctrl-d to end)'
|
42
|
-
end
|
43
|
-
|
44
|
-
expect(answer).to eq([])
|
45
|
-
expect(prompt.output.string).to eq([
|
46
|
-
"Description? \e[90m(Press thy ctrl-d to end)\e[0m\n",
|
47
|
-
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
48
|
-
"Description? \e[32mA super sweet prompt\e[0m\n"
|
49
|
-
].join)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'reads multiple lines with empty lines' do
|
53
|
-
prompt = TTY::TestPrompt.new
|
54
|
-
prompt.input << "aa\n\nbb\n\n\ncc\C-d"
|
55
|
-
prompt.input.rewind
|
56
|
-
|
57
|
-
answer = prompt.multiline("Description?")
|
58
|
-
expect(answer).to eq(["aa\n", "bb\n", "cc"])
|
59
|
-
expect(prompt.output.string).to eq([
|
60
|
-
"Description? \e[90m(Press CTRL-D or CTRL-Z to finish)\e[0m\n",
|
61
|
-
"\e[2K\e[1Ga",
|
62
|
-
"\e[2K\e[1Gaa",
|
63
|
-
"\e[2K\e[1Gaa\n",
|
64
|
-
"\e[2K\e[1G\n",
|
65
|
-
"\e[2K\e[1Gb",
|
66
|
-
"\e[2K\e[1Gbb",
|
67
|
-
"\e[2K\e[1Gbb\n",
|
68
|
-
"\e[2K\e[1G\n",
|
69
|
-
"\e[2K\e[1G\n",
|
70
|
-
"\e[2K\e[1Gc",
|
71
|
-
"\e[2K\e[1Gcc",
|
72
|
-
"\e[2K\e[1G\e[1A" * 6,
|
73
|
-
"\e[2K\e[1G",
|
74
|
-
"Description? \e[32maa ...\e[0m\n"
|
75
|
-
].join)
|
76
|
-
end
|
77
|
-
end
|
data/spec/unit/new_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt, '#new' do
|
4
|
-
let(:env) { { "TTY_TEST" => true } }
|
5
|
-
|
6
|
-
it "sets prefix" do
|
7
|
-
prompt = described_class.new(prefix: "[?]", env: env)
|
8
|
-
expect(prompt.prefix).to eq("[?]")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "sets input stream" do
|
12
|
-
prompt = described_class.new(input: :stream1, env: env)
|
13
|
-
expect(prompt.input).to eq(:stream1)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "sets output stream" do
|
17
|
-
prompt = described_class.new(output: :stream2, env: env)
|
18
|
-
expect(prompt.output).to eq(:stream2)
|
19
|
-
end
|
20
|
-
end
|
data/spec/unit/ok_spec.rb
DELETED
data/spec/unit/paginator_spec.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt::Paginator, '#paginate' do
|
4
|
-
it "ignores per_page when equal items " do
|
5
|
-
list = %w(a b c d)
|
6
|
-
paginator = described_class.new({per_page: 4})
|
7
|
-
|
8
|
-
expect(paginator.paginate(list, 1).to_a).to eq([
|
9
|
-
['a',0],['b',1],['c',2],['d',3]])
|
10
|
-
end
|
11
|
-
|
12
|
-
it "ignores per_page when less items " do
|
13
|
-
list = %w(a b c d)
|
14
|
-
paginator = described_class.new({per_page: 5})
|
15
|
-
|
16
|
-
expect(paginator.paginate(list, 1).to_a).to eq([
|
17
|
-
['a',0],['b',1],['c',2],['d',3]])
|
18
|
-
end
|
19
|
-
|
20
|
-
it "paginates items matching per_page count" do
|
21
|
-
list = %w(a b c d e f)
|
22
|
-
paginator = described_class.new({per_page: 3})
|
23
|
-
|
24
|
-
expect(paginator.paginate(list, 1).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
25
|
-
expect(paginator.paginate(list, 2).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
26
|
-
expect(paginator.paginate(list, 3).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
27
|
-
expect(paginator.paginate(list, 4).to_a).to eq([['b',1], ['c',2], ['d',3]])
|
28
|
-
expect(paginator.paginate(list, 5).to_a).to eq([['c',2], ['d',3], ['e',4]])
|
29
|
-
expect(paginator.paginate(list, 6).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
30
|
-
expect(paginator.paginate(list, 7).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
31
|
-
end
|
32
|
-
|
33
|
-
it "paginates items not matching per_page count" do
|
34
|
-
list = %w(a b c d e f g)
|
35
|
-
paginator = described_class.new({per_page: 3})
|
36
|
-
|
37
|
-
expect(paginator.paginate(list, 1).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
38
|
-
expect(paginator.paginate(list, 2).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
39
|
-
expect(paginator.paginate(list, 3).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
40
|
-
expect(paginator.paginate(list, 4).to_a).to eq([['b',1], ['c',2], ['d',3]])
|
41
|
-
expect(paginator.paginate(list, 5).to_a).to eq([['c',2], ['d',3], ['e',4]])
|
42
|
-
expect(paginator.paginate(list, 6).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
43
|
-
expect(paginator.paginate(list, 7).to_a).to eq([['e',4], ['f',5], ['g',6]])
|
44
|
-
expect(paginator.paginate(list, 8).to_a).to eq([['e',4], ['f',5], ['g',6]])
|
45
|
-
end
|
46
|
-
|
47
|
-
it "finds maximum index for current selection" do
|
48
|
-
list = %w(a b c d e f g)
|
49
|
-
paginator = described_class.new({per_page: 3, default: 0})
|
50
|
-
|
51
|
-
paginator.paginate(list, 4)
|
52
|
-
expect(paginator.max_index).to eq(3)
|
53
|
-
paginator.paginate(list, 5)
|
54
|
-
expect(paginator.max_index).to eq(4)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "starts with default selection" do
|
58
|
-
list = %w(a b c d e f g)
|
59
|
-
paginator = described_class.new({per_page: 3, default: 3})
|
60
|
-
|
61
|
-
expect(paginator.paginate(list, 4).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
62
|
-
end
|
63
|
-
end
|