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
data/spec/unit/say_spec.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt, '#say' do
|
4
|
-
|
5
|
-
subject(:prompt) { TTY::TestPrompt.new }
|
6
|
-
|
7
|
-
it 'prints an empty message' do
|
8
|
-
prompt.say('')
|
9
|
-
expect(prompt.output.string).to eq('')
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'with new line' do
|
13
|
-
it 'prints a message with newline' do
|
14
|
-
prompt.say("Hell yeah!\n")
|
15
|
-
expect(prompt.output.string).to eq("Hell yeah!\n")
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'prints a message with implicit newline' do
|
19
|
-
prompt.say("Hell yeah!\n")
|
20
|
-
expect(prompt.output.string).to eq("Hell yeah!\n")
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'prints a message with newline within text' do
|
24
|
-
prompt.say("Hell\n yeah!")
|
25
|
-
expect(prompt.output.string).to eq("Hell\n yeah!\n")
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'prints a message with newline within text and blank space' do
|
29
|
-
prompt.say("Hell\n yeah! ")
|
30
|
-
expect(prompt.output.string).to eq("Hell\n yeah! ")
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'prints a message without newline' do
|
34
|
-
prompt.say("Hell yeah!", newline: false)
|
35
|
-
expect(prompt.output.string).to eq("Hell yeah!")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'with tab or space' do
|
40
|
-
it 'prints ' do
|
41
|
-
prompt.say("Hell yeah!\t")
|
42
|
-
expect(prompt.output.string).to eq("Hell yeah!\t")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'with color' do
|
47
|
-
it 'prints message with ansi color' do
|
48
|
-
prompt.say('Hell yeah!', color: :green)
|
49
|
-
expect(prompt.output.string).to eq("\e[32mHell yeah!\e[0m\n")
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'prints message with ansi color without newline' do
|
53
|
-
prompt.say('Hell yeah! ', color: :green)
|
54
|
-
expect(prompt.output.string).to eq("\e[32mHell yeah! \e[0m")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'without color' do
|
59
|
-
it 'prints message without ansi' do
|
60
|
-
prompt = TTY::TestPrompt.new(enable_color: false)
|
61
|
-
|
62
|
-
prompt.say('Hell yeah!', color: :green)
|
63
|
-
|
64
|
-
expect(prompt.output.string).to eq("Hell yeah!\n")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/spec/unit/select_spec.rb
DELETED
@@ -1,359 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt, '#select' do
|
4
|
-
|
5
|
-
subject(:prompt) { TTY::TestPrompt.new }
|
6
|
-
|
7
|
-
let(:symbols) { TTY::Prompt::Symbols.symbols }
|
8
|
-
|
9
|
-
it "selects by default first option" do
|
10
|
-
choices = %w(Large Medium Small)
|
11
|
-
prompt.input << "\r"
|
12
|
-
prompt.input.rewind
|
13
|
-
expect(prompt.select('What size?', choices)).to eq('Large')
|
14
|
-
expect(prompt.output.string).to eq([
|
15
|
-
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
16
|
-
"\e[32m#{symbols[:pointer]} Large\e[0m\n",
|
17
|
-
" Medium\n",
|
18
|
-
" Small",
|
19
|
-
"\e[2K\e[1G\e[1A" * 3,
|
20
|
-
"\e[2K\e[1G",
|
21
|
-
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
22
|
-
].join)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "allows navigation using events without errors" do
|
26
|
-
choices = %w(Large Medium Small)
|
27
|
-
prompt.input << "j" << "\r"
|
28
|
-
prompt.input.rewind
|
29
|
-
prompt.on(:keypress) do |event|
|
30
|
-
prompt.trigger(:keydown) if event.value == "j"
|
31
|
-
end
|
32
|
-
expect { prompt.select('What size?', choices) }.not_to output.to_stderr
|
33
|
-
expect(prompt.output.string).to eq([
|
34
|
-
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
35
|
-
"\e[32m#{symbols[:pointer]} Large\e[0m\n",
|
36
|
-
" Medium\n",
|
37
|
-
" Small",
|
38
|
-
"\e[2K\e[1G\e[1A" * 3,
|
39
|
-
"\e[2K\e[1G",
|
40
|
-
"What size? \n",
|
41
|
-
" Large\n",
|
42
|
-
"\e[32m#{symbols[:pointer]} Medium\e[0m\n",
|
43
|
-
" Small",
|
44
|
-
"\e[2K\e[1G\e[1A" * 3,
|
45
|
-
"\e[2K\e[1G",
|
46
|
-
"What size? \e[32mMedium\e[0m\n\e[?25h"
|
47
|
-
].join)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "sets choice name and value" do
|
51
|
-
choices = {large: 1, medium: 2, small: 3}
|
52
|
-
prompt.input << " "
|
53
|
-
prompt.input.rewind
|
54
|
-
expect(prompt.select('What size?', choices, default: 1)).to eq(1)
|
55
|
-
expect(prompt.output.string).to eq([
|
56
|
-
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
57
|
-
"\e[32m#{symbols[:pointer]} large\e[0m\n",
|
58
|
-
" medium\n",
|
59
|
-
" small",
|
60
|
-
"\e[2K\e[1G\e[1A" * 3,
|
61
|
-
"\e[2K\e[1G",
|
62
|
-
"What size? \e[32mlarge\e[0m\n\e[?25h"
|
63
|
-
].join)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "sets choice name through DSL" do
|
67
|
-
prompt.input << " "
|
68
|
-
prompt.input.rewind
|
69
|
-
value = prompt.select('What size?') do |menu|
|
70
|
-
menu.choice "Large"
|
71
|
-
menu.choice "Medium"
|
72
|
-
menu.choice "Small"
|
73
|
-
end
|
74
|
-
expect(value).to eq('Large')
|
75
|
-
expect(prompt.output.string).to eq([
|
76
|
-
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
77
|
-
"\e[32m#{symbols[:pointer]} Large\e[0m\n",
|
78
|
-
" Medium\n",
|
79
|
-
" Small",
|
80
|
-
"\e[2K\e[1G\e[1A" * 3,
|
81
|
-
"\e[2K\e[1G",
|
82
|
-
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
83
|
-
].join)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "sets choice name & value through DSL" do
|
87
|
-
prompt.input << " "
|
88
|
-
prompt.input.rewind
|
89
|
-
value = prompt.select('What size?') do |menu|
|
90
|
-
menu.choice :large, 1
|
91
|
-
menu.choice :medium, 2
|
92
|
-
menu.choice :small, 3
|
93
|
-
end
|
94
|
-
expect(value).to eq(1)
|
95
|
-
expect(prompt.output.string).to eq([
|
96
|
-
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
97
|
-
"\e[32m#{symbols[:pointer]} large\e[0m\n",
|
98
|
-
" medium\n",
|
99
|
-
" small",
|
100
|
-
"\e[2K\e[1G\e[1A" * 3,
|
101
|
-
"\e[2K\e[1G",
|
102
|
-
"What size? \e[32mlarge\e[0m\n\e[?25h"
|
103
|
-
].join)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "sets choices and single choice through DSL" do
|
107
|
-
prompt.input << " "
|
108
|
-
prompt.input.rewind
|
109
|
-
value = prompt.select('What size?') do |menu|
|
110
|
-
menu.choice 'Large'
|
111
|
-
menu.choices %w(Medium Small)
|
112
|
-
end
|
113
|
-
expect(value).to eq('Large')
|
114
|
-
expect(prompt.output.string).to eq([
|
115
|
-
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
116
|
-
"\e[32m#{symbols[:pointer]} Large\e[0m\n",
|
117
|
-
" Medium\n",
|
118
|
-
" Small",
|
119
|
-
"\e[2K\e[1G\e[1A" * 3,
|
120
|
-
"\e[2K\e[1G",
|
121
|
-
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
122
|
-
].join)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "sets choice name & value through DSL" do
|
126
|
-
prompt.input << " "
|
127
|
-
prompt.input.rewind
|
128
|
-
value = prompt.select('What size?') do |menu|
|
129
|
-
menu.default 2
|
130
|
-
menu.enum '.'
|
131
|
-
|
132
|
-
menu.choice :large, 1
|
133
|
-
menu.choice :medium, 2
|
134
|
-
menu.choice :small, 3
|
135
|
-
end
|
136
|
-
expect(value).to eq(2)
|
137
|
-
expect(prompt.output.string).to eq([
|
138
|
-
"\e[?25lWhat size? \e[90m(Use arrow or number (1-3) keys, press Enter to select)\e[0m\n",
|
139
|
-
" 1. large\n",
|
140
|
-
"\e[32m#{symbols[:pointer]} 2. medium\e[0m\n",
|
141
|
-
" 3. small",
|
142
|
-
"\e[2K\e[1G\e[1A" * 3,
|
143
|
-
"\e[2K\e[1G",
|
144
|
-
"What size? \e[32mmedium\e[0m\n\e[?25h"
|
145
|
-
].join)
|
146
|
-
end
|
147
|
-
|
148
|
-
it "sets choice value to proc and executes it" do
|
149
|
-
prompt.input << " "
|
150
|
-
prompt.input.rewind
|
151
|
-
value = prompt.select('What size?', default: 2, enum: ')') do |menu|
|
152
|
-
menu.choice :large, 1
|
153
|
-
menu.choice :medium do 'Good choice!' end
|
154
|
-
menu.choice :small, 3
|
155
|
-
end
|
156
|
-
expect(value).to eq('Good choice!')
|
157
|
-
expect(prompt.output.string).to eq([
|
158
|
-
"\e[?25lWhat size? \e[90m(Use arrow or number (1-3) keys, press Enter to select)\e[0m\n",
|
159
|
-
" 1) large\n",
|
160
|
-
"\e[32m#{symbols[:pointer]} 2) medium\e[0m\n",
|
161
|
-
" 3) small",
|
162
|
-
"\e[2K\e[1G\e[1A" * 3,
|
163
|
-
"\e[2K\e[1G",
|
164
|
-
"What size? \e[32mmedium\e[0m\n\e[?25h"
|
165
|
-
].join)
|
166
|
-
end
|
167
|
-
|
168
|
-
it "sets default option through hash syntax" do
|
169
|
-
choices = %w(Large Medium Small)
|
170
|
-
prompt.input << " "
|
171
|
-
prompt.input.rewind
|
172
|
-
expect(prompt.select('What size?', choices, default: 2, enum: '.')).to eq('Medium')
|
173
|
-
expect(prompt.output.string).to eq([
|
174
|
-
"\e[?25lWhat size? \e[90m(Use arrow or number (1-3) keys, press Enter to select)\e[0m\n",
|
175
|
-
" 1. Large\n",
|
176
|
-
"\e[32m#{symbols[:pointer]} 2. Medium\e[0m\n",
|
177
|
-
" 3. Small",
|
178
|
-
"\e[2K\e[1G\e[1A" * 3,
|
179
|
-
"\e[2K\e[1G",
|
180
|
-
"What size? \e[32mMedium\e[0m\n\e[?25h"
|
181
|
-
].join)
|
182
|
-
end
|
183
|
-
|
184
|
-
it "changes selected item color & marker" do
|
185
|
-
choices = %w(Large Medium Small)
|
186
|
-
prompt.input << " "
|
187
|
-
prompt.input.rewind
|
188
|
-
options = {active_color: :blue, help_color: :red, marker: '>'}
|
189
|
-
value = prompt.select('What size?', choices, options)
|
190
|
-
expect(value).to eq('Large')
|
191
|
-
expect(prompt.output.string).to eq([
|
192
|
-
"\e[?25lWhat size? \e[31m(Use arrow keys, press Enter to select)\e[0m\n",
|
193
|
-
"\e[34m> Large\e[0m\n",
|
194
|
-
" Medium\n",
|
195
|
-
" Small",
|
196
|
-
"\e[2K\e[1G\e[1A" * 3,
|
197
|
-
"\e[2K\e[1G",
|
198
|
-
"What size? \e[34mLarge\e[0m\n\e[?25h"
|
199
|
-
].join)
|
200
|
-
end
|
201
|
-
|
202
|
-
it "changes help text" do
|
203
|
-
choices = %w(Large Medium Small)
|
204
|
-
prompt.input << " "
|
205
|
-
prompt.input.rewind
|
206
|
-
value = prompt.select('What size?', choices, help: "(Bash keyboard)")
|
207
|
-
expect(value).to eq('Large')
|
208
|
-
expect(prompt.output.string).to eq([
|
209
|
-
"\e[?25lWhat size? \e[90m(Bash keyboard)\e[0m\n",
|
210
|
-
"\e[32m#{symbols[:pointer]} Large\e[0m\n",
|
211
|
-
" Medium\n",
|
212
|
-
" Small",
|
213
|
-
"\e[2K\e[1G\e[1A" * 3,
|
214
|
-
"\e[2K\e[1G",
|
215
|
-
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
216
|
-
].join)
|
217
|
-
end
|
218
|
-
|
219
|
-
it "changes help text through DSL" do
|
220
|
-
choices = %w(Large Medium Small)
|
221
|
-
prompt.input << " "
|
222
|
-
prompt.input.rewind
|
223
|
-
value = prompt.select('What size?') do |menu|
|
224
|
-
menu.help "(Bash keyboard)"
|
225
|
-
menu.choices choices
|
226
|
-
end
|
227
|
-
expect(value).to eq('Large')
|
228
|
-
expect(prompt.output.string).to eq([
|
229
|
-
"\e[?25lWhat size? \e[90m(Bash keyboard)\e[0m\n",
|
230
|
-
"\e[32m#{symbols[:pointer]} Large\e[0m\n",
|
231
|
-
" Medium\n",
|
232
|
-
" Small",
|
233
|
-
"\e[2K\e[1G\e[1A" * 3,
|
234
|
-
"\e[2K\e[1G",
|
235
|
-
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
236
|
-
].join)
|
237
|
-
end
|
238
|
-
|
239
|
-
it "sets prompt prefix" do
|
240
|
-
prompt = TTY::TestPrompt.new(prefix: '[?] ')
|
241
|
-
choices = %w(Large Medium Small)
|
242
|
-
prompt.input << "\r"
|
243
|
-
prompt.input.rewind
|
244
|
-
expect(prompt.select('What size?', choices)).to eq('Large')
|
245
|
-
expect(prompt.output.string).to eq([
|
246
|
-
"\e[?25l[?] What size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
247
|
-
"\e[32m#{symbols[:pointer]} Large\e[0m\n",
|
248
|
-
" Medium\n",
|
249
|
-
" Small",
|
250
|
-
"\e[2K\e[1G\e[1A" * 3,
|
251
|
-
"\e[2K\e[1G",
|
252
|
-
"[?] What size? \e[32mLarge\e[0m\n\e[?25h"
|
253
|
-
].join)
|
254
|
-
end
|
255
|
-
|
256
|
-
it "paginates long selections" do
|
257
|
-
choices = %w(A B C D E F G H)
|
258
|
-
prompt.input << "\r"
|
259
|
-
prompt.input.rewind
|
260
|
-
value = prompt.select("What letter?", choices, per_page: 3, default: 4)
|
261
|
-
expect(value).to eq('D')
|
262
|
-
expect(prompt.output.string).to eq([
|
263
|
-
"\e[?25lWhat letter? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
264
|
-
"\e[32m#{symbols[:pointer]} D\e[0m\n",
|
265
|
-
" E\n",
|
266
|
-
" F\n",
|
267
|
-
"\e[90m(Move up or down to reveal more choices)\e[0m",
|
268
|
-
"\e[2K\e[1G\e[1A" * 4,
|
269
|
-
"\e[2K\e[1G",
|
270
|
-
"What letter? \e[32mD\e[0m\n\e[?25h",
|
271
|
-
].join)
|
272
|
-
end
|
273
|
-
|
274
|
-
it "paginates choices as hash object" do
|
275
|
-
prompt = TTY::TestPrompt.new
|
276
|
-
choices = {A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8}
|
277
|
-
prompt.input << "\r"
|
278
|
-
prompt.input.rewind
|
279
|
-
value = prompt.select("What letter?", choices, per_page: 3, default: 4)
|
280
|
-
expect(value).to eq(4)
|
281
|
-
expect(prompt.output.string).to eq([
|
282
|
-
"\e[?25lWhat letter? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
283
|
-
"\e[32m#{symbols[:pointer]} D\e[0m\n",
|
284
|
-
" E\n",
|
285
|
-
" F\n",
|
286
|
-
"\e[90m(Move up or down to reveal more choices)\e[0m",
|
287
|
-
"\e[2K\e[1G\e[1A" * 4,
|
288
|
-
"\e[2K\e[1G",
|
289
|
-
"What letter? \e[32mD\e[0m\n\e[?25h",
|
290
|
-
].join)
|
291
|
-
end
|
292
|
-
|
293
|
-
it "paginates long selections through DSL" do
|
294
|
-
prompt = TTY::TestPrompt.new
|
295
|
-
choices = %w(A B C D E F G H)
|
296
|
-
prompt.input << "\r"
|
297
|
-
prompt.input.rewind
|
298
|
-
value = prompt.select('What letter?') do |menu|
|
299
|
-
menu.per_page 3
|
300
|
-
menu.page_help '(Wiggle thy finger up or down to see more)'
|
301
|
-
menu.default 4
|
302
|
-
|
303
|
-
menu.choices choices
|
304
|
-
end
|
305
|
-
expect(value).to eq('D')
|
306
|
-
expect(prompt.output.string).to eq([
|
307
|
-
"\e[?25lWhat letter? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
308
|
-
"\e[32m#{symbols[:pointer]} D\e[0m\n",
|
309
|
-
" E\n",
|
310
|
-
" F\n",
|
311
|
-
"\e[90m(Wiggle thy finger up or down to see more)\e[0m",
|
312
|
-
"\e[2K\e[1G\e[1A" * 4,
|
313
|
-
"\e[2K\e[1G",
|
314
|
-
"What letter? \e[32mD\e[0m\n\e[?25h",
|
315
|
-
].join)
|
316
|
-
end
|
317
|
-
|
318
|
-
it "verifies default index format" do
|
319
|
-
prompt = TTY::TestPrompt.new
|
320
|
-
choices = %w(Large Medium Small)
|
321
|
-
prompt.input << "\r"
|
322
|
-
prompt.input.rewind
|
323
|
-
|
324
|
-
expect {
|
325
|
-
prompt.select('What size?', choices, default: '')
|
326
|
-
}.to raise_error(TTY::Prompt::ConfigurationError, /in range \(1 - 3\)/)
|
327
|
-
end
|
328
|
-
|
329
|
-
it "doesn't paginate short selections" do
|
330
|
-
prompt = TTY::TestPrompt.new
|
331
|
-
choices = %w(A B C D)
|
332
|
-
prompt.input << "\r"
|
333
|
-
prompt.input.rewind
|
334
|
-
value = prompt.select("What letter?", choices, per_page: 4, default: 1)
|
335
|
-
expect(value).to eq('A')
|
336
|
-
|
337
|
-
expect(prompt.output.string).to eq([
|
338
|
-
"\e[?25lWhat letter? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
339
|
-
"\e[32m#{symbols[:pointer]} A\e[0m\n",
|
340
|
-
" B\n",
|
341
|
-
" C\n",
|
342
|
-
" D",
|
343
|
-
"\e[2K\e[1G\e[1A" * 4,
|
344
|
-
"\e[2K\e[1G",
|
345
|
-
"What letter? \e[32mA\e[0m\n\e[?25h",
|
346
|
-
].join)
|
347
|
-
end
|
348
|
-
|
349
|
-
it "verifies default index range" do
|
350
|
-
prompt = TTY::TestPrompt.new
|
351
|
-
choices = %w(Large Medium Small)
|
352
|
-
prompt.input << "\r"
|
353
|
-
prompt.input.rewind
|
354
|
-
|
355
|
-
expect {
|
356
|
-
prompt.select('What size?', choices, default: 10)
|
357
|
-
}.to raise_error(TTY::Prompt::ConfigurationError, /`10` out of range \(1 - 3\)/)
|
358
|
-
end
|
359
|
-
end
|
data/spec/unit/slider_spec.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt, '#slider' do
|
4
|
-
|
5
|
-
subject(:prompt) { TTY::TestPrompt.new }
|
6
|
-
|
7
|
-
let(:symbols) { TTY::Prompt::Symbols.symbols }
|
8
|
-
|
9
|
-
it "specifies ranges & step" do
|
10
|
-
prompt.input << "\r"
|
11
|
-
prompt.input.rewind
|
12
|
-
expect(prompt.slider('What size?', min: 32, max: 54, step: 2)).to eq(44)
|
13
|
-
expect(prompt.output.string).to eq([
|
14
|
-
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
15
|
-
symbols[:pipe] + symbols[:line] * 6,
|
16
|
-
"\e[32m#{symbols[:handle]}\e[0m",
|
17
|
-
"#{symbols[:line] * 5 + symbols[:pipe]} 44",
|
18
|
-
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
19
|
-
"What size? \e[32m44\e[0m\n\e[?25h"
|
20
|
-
].join)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "specifies default value" do
|
24
|
-
prompt.input << "\r"
|
25
|
-
prompt.input.rewind
|
26
|
-
expect(prompt.slider('What size?', min: 32, max: 54, step: 2, default: 38)).to eq(38)
|
27
|
-
expect(prompt.output.string).to eq([
|
28
|
-
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
29
|
-
symbols[:pipe] + symbols[:line] * 3,
|
30
|
-
"\e[32m#{symbols[:handle]}\e[0m",
|
31
|
-
"#{symbols[:line] * 8 + symbols[:pipe]} 38",
|
32
|
-
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
33
|
-
"What size? \e[32m38\e[0m\n\e[?25h"
|
34
|
-
].join)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "specifies range through DSL" do
|
38
|
-
prompt.input << "\r"
|
39
|
-
prompt.input.rewind
|
40
|
-
value = prompt.slider('What size?') do |range|
|
41
|
-
range.default 6
|
42
|
-
range.min 0
|
43
|
-
range.max 20
|
44
|
-
range.step 2
|
45
|
-
end
|
46
|
-
expect(value).to eq(6)
|
47
|
-
expect(prompt.output.string).to eq([
|
48
|
-
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
49
|
-
symbols[:pipe] + symbols[:line] * 3,
|
50
|
-
"\e[32m#{symbols[:handle]}\e[0m",
|
51
|
-
"#{symbols[:line] * 7 + symbols[:pipe]} 6",
|
52
|
-
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
53
|
-
"What size? \e[32m6\e[0m\n\e[?25h"
|
54
|
-
].join)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "changes display colors" do
|
58
|
-
prompt.input << "\r"
|
59
|
-
prompt.input.rewind
|
60
|
-
options = {active_color: :red, help_color: :cyan}
|
61
|
-
expect(prompt.slider('What size?', options)).to eq(5)
|
62
|
-
expect(prompt.output.string).to eq([
|
63
|
-
"\e[?25lWhat size? \e[36m(Use arrow keys, press Enter to select)\e[0m\n",
|
64
|
-
symbols[:pipe] + symbols[:line] * 5,
|
65
|
-
"\e[31m#{symbols[:handle]}\e[0m",
|
66
|
-
"#{symbols[:line] * 5 + symbols[:pipe]} 5",
|
67
|
-
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
68
|
-
"What size? \e[31m5\e[0m\n\e[?25h"
|
69
|
-
].join)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "doesn't allow values outside of range" do
|
73
|
-
prompt.input << "l\r"
|
74
|
-
prompt.input.rewind
|
75
|
-
prompt.on(:keypress) do |event|
|
76
|
-
if event.value = 'l'
|
77
|
-
prompt.trigger(:keyright)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
res = prompt.slider('What size?', min: 0, max: 10, step: 1, default: 10)
|
81
|
-
expect(res).to eq(10)
|
82
|
-
expect(prompt.output.string).to eq([
|
83
|
-
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
84
|
-
symbols[:pipe] + symbols[:line] * 10,
|
85
|
-
"\e[32m#{symbols[:handle]}\e[0m",
|
86
|
-
"#{symbols[:pipe]} 10",
|
87
|
-
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
88
|
-
"What size? \n",
|
89
|
-
symbols[:pipe] + symbols[:line] * 10,
|
90
|
-
"\e[32m#{symbols[:handle]}\e[0m",
|
91
|
-
"#{symbols[:pipe]} 10",
|
92
|
-
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
93
|
-
"What size? \e[32m10\e[0m\n\e[?25h"
|
94
|
-
].join)
|
95
|
-
end
|
96
|
-
end
|