tty-prompt 0.16.1 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/tty/prompt/messages.rb +49 -0
- data/lib/tty/prompt/version.rb +1 -3
- data/spec/spec_helper.rb +45 -0
- data/spec/unit/ask_spec.rb +132 -0
- data/spec/unit/choice/eql_spec.rb +22 -0
- data/spec/unit/choice/from_spec.rb +96 -0
- data/spec/unit/choices/add_spec.rb +12 -0
- data/spec/unit/choices/each_spec.rb +13 -0
- data/spec/unit/choices/find_by_spec.rb +10 -0
- data/spec/unit/choices/new_spec.rb +10 -0
- data/spec/unit/choices/pluck_spec.rb +9 -0
- data/spec/unit/collect_spec.rb +96 -0
- data/spec/unit/converters/convert_bool_spec.rb +58 -0
- data/spec/unit/converters/convert_char_spec.rb +11 -0
- data/spec/unit/converters/convert_custom_spec.rb +14 -0
- data/spec/unit/converters/convert_date_spec.rb +34 -0
- data/spec/unit/converters/convert_file_spec.rb +18 -0
- data/spec/unit/converters/convert_number_spec.rb +39 -0
- data/spec/unit/converters/convert_path_spec.rb +15 -0
- data/spec/unit/converters/convert_range_spec.rb +22 -0
- data/spec/unit/converters/convert_regex_spec.rb +12 -0
- data/spec/unit/converters/convert_string_spec.rb +21 -0
- data/spec/unit/converters/on_error_spec.rb +9 -0
- data/spec/unit/distance/distance_spec.rb +73 -0
- data/spec/unit/enum_paginator_spec.rb +75 -0
- data/spec/unit/enum_select_spec.rb +446 -0
- data/spec/unit/error_spec.rb +20 -0
- data/spec/unit/evaluator_spec.rb +67 -0
- data/spec/unit/expand_spec.rb +198 -0
- data/spec/unit/keypress_spec.rb +72 -0
- data/spec/unit/mask_spec.rb +132 -0
- data/spec/unit/multi_select_spec.rb +495 -0
- data/spec/unit/multiline_spec.rb +77 -0
- data/spec/unit/new_spec.rb +20 -0
- data/spec/unit/ok_spec.rb +10 -0
- data/spec/unit/paginator_spec.rb +73 -0
- data/spec/unit/question/checks_spec.rb +97 -0
- data/spec/unit/question/default_spec.rb +31 -0
- data/spec/unit/question/echo_spec.rb +38 -0
- data/spec/unit/question/in_spec.rb +115 -0
- data/spec/unit/question/initialize_spec.rb +12 -0
- data/spec/unit/question/modifier/apply_to_spec.rb +24 -0
- data/spec/unit/question/modifier/letter_case_spec.rb +41 -0
- data/spec/unit/question/modifier/whitespace_spec.rb +51 -0
- data/spec/unit/question/modify_spec.rb +41 -0
- data/spec/unit/question/required_spec.rb +92 -0
- data/spec/unit/question/validate_spec.rb +115 -0
- data/spec/unit/question/validation/call_spec.rb +31 -0
- data/spec/unit/question/validation/coerce_spec.rb +30 -0
- data/spec/unit/result_spec.rb +40 -0
- data/spec/unit/say_spec.rb +67 -0
- data/spec/unit/select_spec.rb +624 -0
- data/spec/unit/slider_spec.rb +100 -0
- data/spec/unit/statement/initialize_spec.rb +15 -0
- data/spec/unit/subscribe_spec.rb +20 -0
- data/spec/unit/suggest_spec.rb +28 -0
- data/spec/unit/warn_spec.rb +21 -0
- data/spec/unit/yes_no_spec.rb +235 -0
- data/tty-prompt.gemspec +4 -6
- metadata +120 -15
- data/.gitignore +0 -16
- data/.rspec +0 -3
- data/.travis.yml +0 -27
- data/CHANGELOG.md +0 -289
- data/CODE_OF_CONDUCT.md +0 -49
- data/Gemfile +0 -21
- data/appveyor.yml +0 -22
- data/benchmarks/speed.rb +0 -27
@@ -0,0 +1,100 @@
|
|
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? ",
|
15
|
+
symbols[:line] * 6,
|
16
|
+
"\e[32m#{symbols[:handle]}\e[0m",
|
17
|
+
"#{symbols[:line] * 5} 44",
|
18
|
+
"\n\e[90m(Use arrow keys, press Enter to select)\e[0m",
|
19
|
+
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
20
|
+
"What size? \e[32m44\e[0m\n\e[?25h"
|
21
|
+
].join)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "specifies default value" do
|
25
|
+
prompt.input << "\r"
|
26
|
+
prompt.input.rewind
|
27
|
+
expect(prompt.slider('What size?', min: 32, max: 54, step: 2, default: 38)).to eq(38)
|
28
|
+
expect(prompt.output.string).to eq([
|
29
|
+
"\e[?25lWhat size? ",
|
30
|
+
symbols[:line] * 3,
|
31
|
+
"\e[32m#{symbols[:handle]}\e[0m",
|
32
|
+
"#{symbols[:line] * 8} 38",
|
33
|
+
"\n\e[90m(Use arrow keys, press Enter to select)\e[0m",
|
34
|
+
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
35
|
+
"What size? \e[32m38\e[0m\n\e[?25h"
|
36
|
+
].join)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "specifies range through DSL" do
|
40
|
+
prompt.input << "\r"
|
41
|
+
prompt.input.rewind
|
42
|
+
value = prompt.slider('What size?') do |range|
|
43
|
+
range.default 6
|
44
|
+
range.min 0
|
45
|
+
range.max 20
|
46
|
+
range.step 2
|
47
|
+
range.format "|:slider| %d%%"
|
48
|
+
end
|
49
|
+
expect(value).to eq(6)
|
50
|
+
expect(prompt.output.string).to eq([
|
51
|
+
"\e[?25lWhat size? ",
|
52
|
+
symbols[:pipe] + symbols[:line] * 3,
|
53
|
+
"\e[32m#{symbols[:handle]}\e[0m",
|
54
|
+
"#{symbols[:line] * 7 + symbols[:pipe]} 6%",
|
55
|
+
"\n\e[90m(Use arrow keys, press Enter to select)\e[0m",
|
56
|
+
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
57
|
+
"What size? \e[32m6\e[0m\n\e[?25h"
|
58
|
+
].join)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "changes display colors" do
|
62
|
+
prompt.input << "\r"
|
63
|
+
prompt.input.rewind
|
64
|
+
options = {active_color: :red, help_color: :cyan}
|
65
|
+
expect(prompt.slider('What size?', options)).to eq(5)
|
66
|
+
expect(prompt.output.string).to eq([
|
67
|
+
"\e[?25lWhat size? ",
|
68
|
+
symbols[:line] * 5,
|
69
|
+
"\e[31m#{symbols[:handle]}\e[0m",
|
70
|
+
"#{symbols[:line] * 5} 5",
|
71
|
+
"\n\e[36m(Use arrow keys, press Enter to select)\e[0m",
|
72
|
+
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
73
|
+
"What size? \e[31m5\e[0m\n\e[?25h"
|
74
|
+
].join)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "doesn't allow values outside of range" do
|
78
|
+
prompt.input << "l\r"
|
79
|
+
prompt.input.rewind
|
80
|
+
prompt.on(:keypress) do |event|
|
81
|
+
if event.value = 'l'
|
82
|
+
prompt.trigger(:keyright)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
res = prompt.slider('What size?', min: 0, max: 10, step: 1, default: 10)
|
86
|
+
expect(res).to eq(10)
|
87
|
+
expect(prompt.output.string).to eq([
|
88
|
+
"\e[?25lWhat size? ",
|
89
|
+
symbols[:line] * 10,
|
90
|
+
"\e[32m#{symbols[:handle]}\e[0m 10",
|
91
|
+
"\n\e[90m(Use arrow keys, press Enter to select)\e[0m",
|
92
|
+
"\e[2K\e[1G\e[1A\e[2K\e[1G",
|
93
|
+
"What size? ",
|
94
|
+
symbols[:line] * 10,
|
95
|
+
"\e[32m#{symbols[:handle]}\e[0m 10",
|
96
|
+
"\e[2K\e[1G",
|
97
|
+
"What size? \e[32m10\e[0m\n\e[?25h"
|
98
|
+
].join)
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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
|
@@ -0,0 +1,20 @@
|
|
1
|
+
RSpec.describe TTY::Prompt, '#subscribe' do
|
2
|
+
it "subscribes to key events only for the current prompt" do
|
3
|
+
prompt = TTY::TestPrompt.new
|
4
|
+
uuid = '14c3b412-e0c5-4ff5-9cd8-25ec3f18c702'
|
5
|
+
prompt.input << "3\n#{uuid}\n"
|
6
|
+
prompt.input.rewind
|
7
|
+
keys = []
|
8
|
+
|
9
|
+
prompt.on(:keypress) do |event|
|
10
|
+
keys << :enter if event.key.name == :enter
|
11
|
+
end
|
12
|
+
|
13
|
+
letter = prompt.enum_select('Select something', ('A'..'Z').to_a)
|
14
|
+
id = prompt.ask('Request ID?')
|
15
|
+
|
16
|
+
expect(letter).to eq('C')
|
17
|
+
expect(id).to eq(uuid)
|
18
|
+
expect(keys).to eq([:enter, :enter])
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1,235 @@
|
|
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
|
data/tty-prompt.gemspec
CHANGED
@@ -13,11 +13,9 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://piotrmurach.github.io/tty"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files =
|
17
|
-
f.match(%r{^(test|spec|features)/})
|
18
|
-
end
|
16
|
+
spec.files = Dir["README.md", "LICENSE.txt", "Rakefile", "lib/**/*.rb", "examples/**/*.rb", "tasks/**", "tty-prompt.gemspec"]
|
19
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
-
spec.test_files = spec
|
18
|
+
spec.test_files = Dir["spec/**/*.rb"]
|
21
19
|
spec.require_paths = ["lib"]
|
22
20
|
|
23
21
|
spec.required_ruby_version = '>= 2.0.0'
|
@@ -25,8 +23,8 @@ Gem::Specification.new do |spec|
|
|
25
23
|
spec.add_dependency 'necromancer', '~> 0.4.0'
|
26
24
|
spec.add_dependency 'pastel', '~> 0.7.0'
|
27
25
|
spec.add_dependency 'timers', '~> 4.0'
|
28
|
-
spec.add_dependency 'tty-cursor', '~> 0.
|
29
|
-
spec.add_dependency 'tty-reader', '~> 0.
|
26
|
+
spec.add_dependency 'tty-cursor', '~> 0.6.0'
|
27
|
+
spec.add_dependency 'tty-reader', '~> 0.4.0'
|
30
28
|
|
31
29
|
spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
|
32
30
|
spec.add_development_dependency 'rake'
|