tty-prompt 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt::Statement, '#new' do
|
4
|
-
it "forces newline after the prompt message" do
|
5
|
-
prompt = TTY::TestPrompt.new
|
6
|
-
statement = described_class.new(prompt)
|
7
|
-
expect(statement.newline).to eq(true)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "displays prompt message in color" do
|
11
|
-
prompt = TTY::TestPrompt.new
|
12
|
-
statement = described_class.new(prompt)
|
13
|
-
expect(statement.color).to eq(false)
|
14
|
-
end
|
15
|
-
end
|
data/spec/unit/suggest_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt, '#suggest' do
|
4
|
-
let(:possible) { %w(status stage stash commit branch blame) }
|
5
|
-
|
6
|
-
subject(:prompt) { TTY::TestPrompt.new }
|
7
|
-
|
8
|
-
it 'suggests few matches' do
|
9
|
-
prompt.suggest('sta', possible)
|
10
|
-
expect(prompt.output.string).
|
11
|
-
to eql("Did you mean one of these?\n stage\n stash\n")
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'suggests a single match for one character' do
|
15
|
-
prompt.suggest('b', possible)
|
16
|
-
expect(prompt.output.string).to eql("Did you mean this?\n blame\n")
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'suggests a single match for two characters' do
|
20
|
-
prompt.suggest('co', possible)
|
21
|
-
expect(prompt.output.string).to eql("Did you mean this?\n commit\n")
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'suggests with different text and indentation' do
|
25
|
-
prompt.suggest('b', possible, indent: 4, single_text: 'Perhaps you meant?')
|
26
|
-
expect(prompt.output.string).to eql("Perhaps you meant?\n blame\n")
|
27
|
-
end
|
28
|
-
end
|
data/spec/unit/warn_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt, '#warn' do
|
4
|
-
|
5
|
-
subject(:prompt) { TTY::TestPrompt.new }
|
6
|
-
|
7
|
-
it 'displays one message' do
|
8
|
-
prompt.warn "Careful young apprentice!"
|
9
|
-
expect(prompt.output.string).to eql "\e[33mCareful young apprentice!\e[0m\n"
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'displays many messages' do
|
13
|
-
prompt.warn "Careful there!", "It's dangerous!"
|
14
|
-
expect(prompt.output.string).to eql "\e[33mCareful there!\e[0m\n\e[33mIt's dangerous!\e[0m\n"
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'displays message with option' do
|
18
|
-
prompt.warn "Careful young apprentice!", newline: false
|
19
|
-
expect(prompt.output.string).to eql "\e[33mCareful young apprentice!\e[0m"
|
20
|
-
end
|
21
|
-
end
|
data/spec/unit/yes_no_spec.rb
DELETED
@@ -1,235 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt, 'confirmation' do
|
4
|
-
|
5
|
-
subject(:prompt) { TTY::TestPrompt.new }
|
6
|
-
|
7
|
-
context '#yes?' do
|
8
|
-
it 'agrees with question' do
|
9
|
-
prompt.input << 'yes'
|
10
|
-
prompt.input.rewind
|
11
|
-
expect(prompt.yes?("Are you a human?")).to eq(true)
|
12
|
-
expect(prompt.output.string).to eq([
|
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",
|
17
|
-
"\e[1A\e[2K\e[1G",
|
18
|
-
"Are you a human? \e[32mYes\e[0m\n"
|
19
|
-
].join)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'disagrees with question' do
|
23
|
-
prompt.input << 'no'
|
24
|
-
prompt.input.rewind
|
25
|
-
expect(prompt.yes?("Are you a human?")).to eq(false)
|
26
|
-
expect(prompt.output.string).to eq([
|
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",
|
30
|
-
"\e[1A\e[2K\e[1G",
|
31
|
-
"Are you a human? \e[32mno\e[0m\n"
|
32
|
-
].join)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'assumes default true' do
|
36
|
-
prompt.input << "\r"
|
37
|
-
prompt.input.rewind
|
38
|
-
expect(prompt.yes?("Are you a human?")).to eq(true)
|
39
|
-
expect(prompt.output.string).to eq([
|
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",
|
42
|
-
"\e[1A\e[2K\e[1G",
|
43
|
-
"Are you a human? \e[32mYes\e[0m\n"
|
44
|
-
].join)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'changes default' do
|
48
|
-
prompt.input << "\n"
|
49
|
-
prompt.input.rewind
|
50
|
-
expect(prompt.yes?("Are you a human?", default: false)).to eq(false)
|
51
|
-
expect(prompt.output.string).to eq([
|
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",
|
54
|
-
"\e[1A\e[2K\e[1G",
|
55
|
-
"Are you a human? \e[32mNo\e[0m\n"
|
56
|
-
].join)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "defaults suffix and converter" do
|
60
|
-
prompt.input << "Nope\n"
|
61
|
-
prompt.input.rewind
|
62
|
-
result = prompt.yes?("Are you a human?") do |q|
|
63
|
-
q.positive 'Yup'
|
64
|
-
q.negative 'nope'
|
65
|
-
end
|
66
|
-
expect(result).to eq(false)
|
67
|
-
expect(prompt.output.string).to eq([
|
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",
|
74
|
-
"\e[1A\e[2K\e[1G",
|
75
|
-
"Are you a human? \e[32mnope\e[0m\n"
|
76
|
-
].join)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "defaults positive and negative" do
|
80
|
-
prompt.input << "Nope\n"
|
81
|
-
prompt.input.rewind
|
82
|
-
result = prompt.yes?("Are you a human?") do |q|
|
83
|
-
q.suffix 'Yup/nope'
|
84
|
-
end
|
85
|
-
expect(result).to eq(false)
|
86
|
-
expect(prompt.output.string).to eq([
|
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",
|
93
|
-
"\e[1A\e[2K\e[1G",
|
94
|
-
"Are you a human? \e[32mnope\e[0m\n"
|
95
|
-
].join)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "customizes question through options" do
|
99
|
-
prompt.input << "\r"
|
100
|
-
prompt.input.rewind
|
101
|
-
result = prompt.yes?("Are you a human?", suffix: 'Agree/Disagree',
|
102
|
-
positive: 'Agree', negative: 'Disagree')
|
103
|
-
expect(result).to eq(true)
|
104
|
-
expect(prompt.output.string).to eq([
|
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",
|
107
|
-
"\e[1A\e[2K\e[1G",
|
108
|
-
"Are you a human? \e[32mAgree\e[0m\n"
|
109
|
-
].join)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "customizes question through DSL" do
|
113
|
-
prompt.input << "disagree\r"
|
114
|
-
prompt.input.rewind
|
115
|
-
conversion = proc { |input| !input.match(/^agree$/i).nil? }
|
116
|
-
result = prompt.yes?("Are you a human?") do |q|
|
117
|
-
q.suffix 'Agree/Disagree'
|
118
|
-
q.positive 'Agree'
|
119
|
-
q.negative 'Disagree'
|
120
|
-
q.convert conversion
|
121
|
-
end
|
122
|
-
expect(result).to eq(false)
|
123
|
-
expect(prompt.output.string).to eq([
|
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",
|
134
|
-
"\e[1A\e[2K\e[1G",
|
135
|
-
"Are you a human? \e[32mDisagree\e[0m\n"
|
136
|
-
].join)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context '#no?' do
|
141
|
-
it 'agrees with question' do
|
142
|
-
prompt.input << 'no'
|
143
|
-
prompt.input.rewind
|
144
|
-
expect(prompt.no?("Are you a human?")).to eq(true)
|
145
|
-
expect(prompt.output.string).to eq([
|
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",
|
149
|
-
"\e[1A\e[2K\e[1G",
|
150
|
-
"Are you a human? \e[32mNo\e[0m\n"
|
151
|
-
].join)
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'disagrees with question' do
|
155
|
-
prompt.input << 'yes'
|
156
|
-
prompt.input.rewind
|
157
|
-
expect(prompt.no?("Are you a human?")).to eq(false)
|
158
|
-
expect(prompt.output.string).to eq([
|
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",
|
163
|
-
"\e[1A\e[2K\e[1G",
|
164
|
-
"Are you a human? \e[32myes\e[0m\n"
|
165
|
-
].join)
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'assumes default false' do
|
169
|
-
prompt.input << "\r"
|
170
|
-
prompt.input.rewind
|
171
|
-
expect(prompt.no?("Are you a human?")).to eq(true)
|
172
|
-
expect(prompt.output.string).to eq([
|
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",
|
175
|
-
"\e[1A\e[2K\e[1G",
|
176
|
-
"Are you a human? \e[32mNo\e[0m\n"
|
177
|
-
].join)
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'changes default' do
|
181
|
-
prompt.input << "\r"
|
182
|
-
prompt.input.rewind
|
183
|
-
expect(prompt.no?("Are you a human?", default: true)).to eq(false)
|
184
|
-
expect(prompt.output.string).to eq([
|
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",
|
187
|
-
"\e[1A\e[2K\e[1G",
|
188
|
-
"Are you a human? \e[32mYes\e[0m\n"
|
189
|
-
].join)
|
190
|
-
end
|
191
|
-
|
192
|
-
it "defaults suffix and converter" do
|
193
|
-
prompt.input << "Yup\n"
|
194
|
-
prompt.input.rewind
|
195
|
-
result = prompt.no?("Are you a human?") do |q|
|
196
|
-
q.positive 'yup'
|
197
|
-
q.negative 'Nope'
|
198
|
-
end
|
199
|
-
expect(result).to eq(false)
|
200
|
-
expect(prompt.output.string).to eq([
|
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",
|
206
|
-
"\e[1A\e[2K\e[1G",
|
207
|
-
"Are you a human? \e[32myup\e[0m\n"
|
208
|
-
].join)
|
209
|
-
end
|
210
|
-
|
211
|
-
it "customizes question through DSL" do
|
212
|
-
prompt.input << "agree\r"
|
213
|
-
prompt.input.rewind
|
214
|
-
conversion = proc { |input| !input.match(/^agree$/i).nil? }
|
215
|
-
result = prompt.no?("Are you a human?") do |q|
|
216
|
-
q.suffix 'Agree/Disagree'
|
217
|
-
q.positive 'Agree'
|
218
|
-
q.negative 'Disagree'
|
219
|
-
q.convert conversion
|
220
|
-
end
|
221
|
-
expect(result).to eq(false)
|
222
|
-
expect(prompt.output.string).to eq([
|
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",
|
230
|
-
"\e[1A\e[2K\e[1G",
|
231
|
-
"Are you a human? \e[32mAgree\e[0m\n"
|
232
|
-
].join)
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|