tty-prompt 0.1.0 → 0.2.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 +0 -2
- data/CHANGELOG.md +12 -0
- data/README.md +223 -59
- data/lib/tty/prompt/choice.rb +83 -0
- data/lib/tty/prompt/choices.rb +92 -0
- data/lib/tty/prompt/codes.rb +32 -0
- data/lib/tty/prompt/cursor.rb +131 -0
- data/lib/tty/prompt/list.rb +209 -0
- data/lib/tty/prompt/mode/echo.rb +10 -9
- data/lib/tty/prompt/mode/raw.rb +10 -9
- data/lib/tty/prompt/multi_list.rb +105 -0
- data/lib/tty/prompt/question/validation.rb +12 -27
- data/lib/tty/prompt/question.rb +58 -107
- data/lib/tty/prompt/reader.rb +44 -11
- data/lib/tty/prompt/response.rb +31 -36
- data/lib/tty/prompt/response_delegation.rb +3 -2
- data/lib/tty/prompt/statement.rb +10 -10
- data/lib/tty/prompt/test.rb +15 -0
- data/lib/tty/prompt/version.rb +3 -3
- data/lib/tty/prompt.rb +72 -9
- data/lib/tty-prompt.rb +11 -0
- data/spec/unit/ask_spec.rb +32 -35
- data/spec/unit/choice/eql_spec.rb +24 -0
- data/spec/unit/choice/from_spec.rb +25 -0
- data/spec/unit/choices/add_spec.rb +14 -0
- data/spec/unit/choices/each_spec.rb +15 -0
- data/spec/unit/choices/new_spec.rb +12 -0
- data/spec/unit/choices/pluck_spec.rb +11 -0
- data/spec/unit/cursor/new_spec.rb +74 -0
- data/spec/unit/error_spec.rb +4 -8
- data/spec/unit/multi_select_spec.rb +163 -0
- data/spec/unit/question/character_spec.rb +5 -16
- data/spec/unit/question/default_spec.rb +4 -10
- data/spec/unit/question/in_spec.rb +15 -12
- data/spec/unit/question/initialize_spec.rb +1 -6
- data/spec/unit/question/modify_spec.rb +25 -24
- data/spec/unit/question/required_spec.rb +31 -0
- data/spec/unit/question/validate_spec.rb +25 -17
- data/spec/unit/question/validation/call_spec.rb +22 -0
- data/spec/unit/response/read_bool_spec.rb +38 -27
- data/spec/unit/response/read_char_spec.rb +5 -8
- data/spec/unit/response/read_date_spec.rb +8 -12
- data/spec/unit/response/read_email_spec.rb +25 -22
- data/spec/unit/response/read_multiple_spec.rb +11 -13
- data/spec/unit/response/read_number_spec.rb +12 -16
- data/spec/unit/response/read_range_spec.rb +10 -13
- data/spec/unit/response/read_spec.rb +39 -38
- data/spec/unit/response/read_string_spec.rb +7 -12
- data/spec/unit/say_spec.rb +10 -14
- data/spec/unit/select_spec.rb +192 -0
- data/spec/unit/statement/initialize_spec.rb +0 -4
- data/spec/unit/suggest_spec.rb +6 -9
- data/spec/unit/warn_spec.rb +4 -8
- metadata +32 -8
- data/spec/unit/question/argument_spec.rb +0 -30
- data/spec/unit/question/valid_spec.rb +0 -46
- data/spec/unit/question/validation/valid_value_spec.rb +0 -22
@@ -2,18 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
RSpec.describe TTY::Prompt::Question, '#
|
6
|
-
let(:input) { StringIO.new }
|
7
|
-
let(:output) { StringIO.new }
|
8
|
-
let(:prompt) { TTY::Prompt.new(input, output) }
|
9
|
-
|
5
|
+
RSpec.describe TTY::Prompt::Question, '#read_string' do
|
10
6
|
it 'reads string' do
|
11
|
-
|
12
|
-
input <<
|
13
|
-
input.rewind
|
14
|
-
|
15
|
-
answer
|
16
|
-
expect(answer).to
|
17
|
-
expect(answer).to eql name
|
7
|
+
prompt = TTY::TestPrompt.new
|
8
|
+
prompt.input << 'Piotr'
|
9
|
+
prompt.input.rewind
|
10
|
+
answer = prompt.ask("What is your name?", read: :string)
|
11
|
+
expect(answer).to be_a(String)
|
12
|
+
expect(answer).to eq('Piotr')
|
18
13
|
end
|
19
14
|
end
|
data/spec/unit/say_spec.rb
CHANGED
@@ -3,64 +3,60 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe TTY::Prompt, '#say' do
|
6
|
-
let(:input) { StringIO.new }
|
7
|
-
let(:output) { StringIO.new }
|
8
6
|
let(:color) { Pastel.new(enabled: true) }
|
9
7
|
|
10
|
-
subject(:prompt) {
|
8
|
+
subject(:prompt) { TTY::TestPrompt.new }
|
11
9
|
|
12
10
|
before { allow(Pastel).to receive(:new).and_return(color) }
|
13
11
|
|
14
|
-
after { output.rewind }
|
15
|
-
|
16
12
|
it 'prints an empty message' do
|
17
13
|
prompt.say ""
|
18
|
-
expect(output.string).to eql ""
|
14
|
+
expect(prompt.output.string).to eql ""
|
19
15
|
end
|
20
16
|
|
21
17
|
context 'with new line' do
|
22
18
|
it 'prints a message with newline' do
|
23
19
|
prompt.say "Hell yeah!\n"
|
24
|
-
expect(output.string).to eql "Hell yeah!\n"
|
20
|
+
expect(prompt.output.string).to eql "Hell yeah!\n"
|
25
21
|
end
|
26
22
|
|
27
23
|
it 'prints a message with implicit newline' do
|
28
24
|
prompt.say "Hell yeah!\n"
|
29
|
-
expect(output.string).to eql "Hell yeah!\n"
|
25
|
+
expect(prompt.output.string).to eql "Hell yeah!\n"
|
30
26
|
end
|
31
27
|
|
32
28
|
it 'prints a message with newline within text' do
|
33
29
|
prompt.say "Hell\n yeah!"
|
34
|
-
expect(output.string).to eql "Hell\n yeah!\n"
|
30
|
+
expect(prompt.output.string).to eql "Hell\n yeah!\n"
|
35
31
|
end
|
36
32
|
|
37
33
|
it 'prints a message with newline within text and blank space' do
|
38
34
|
prompt.say "Hell\n yeah! "
|
39
|
-
expect(output.string).to eql "Hell\n yeah! "
|
35
|
+
expect(prompt.output.string).to eql "Hell\n yeah! "
|
40
36
|
end
|
41
37
|
|
42
38
|
it 'prints a message without newline' do
|
43
39
|
prompt.say "Hell yeah!", newline: false
|
44
|
-
expect(output.string).to eql "Hell yeah!"
|
40
|
+
expect(prompt.output.string).to eql "Hell yeah!"
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
48
44
|
context 'with tab or space' do
|
49
45
|
it 'prints ' do
|
50
46
|
prompt.say "Hell yeah!\t"
|
51
|
-
expect(output.string).to eql "Hell yeah!\t"
|
47
|
+
expect(prompt.output.string).to eql "Hell yeah!\t"
|
52
48
|
end
|
53
49
|
end
|
54
50
|
|
55
51
|
context 'with color' do
|
56
52
|
it 'prints message with ansi color' do
|
57
53
|
prompt.say "Hell yeah!", color: :green
|
58
|
-
expect(output.string).to eql "\e[32mHell yeah!\e[0m\n"
|
54
|
+
expect(prompt.output.string).to eql "\e[32mHell yeah!\e[0m\n"
|
59
55
|
end
|
60
56
|
|
61
57
|
it 'prints message with ansi color without newline' do
|
62
58
|
prompt.say "Hell yeah! ", color: :green
|
63
|
-
expect(output.string).to eql "\e[32mHell yeah! \e[0m"
|
59
|
+
expect(prompt.output.string).to eql "\e[32mHell yeah! \e[0m"
|
64
60
|
end
|
65
61
|
end
|
66
62
|
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe TTY::Prompt, '#select' do
|
6
|
+
let(:color) { Pastel.new(enabled: true) }
|
7
|
+
|
8
|
+
before { allow(Pastel).to receive(:new).and_return(color) }
|
9
|
+
|
10
|
+
it "selects by default first option" do
|
11
|
+
prompt = TTY::TestPrompt.new
|
12
|
+
choices = %w(Large Medium Small)
|
13
|
+
prompt.input << "\r"
|
14
|
+
prompt.input.rewind
|
15
|
+
expect(prompt.select('What size?', choices)).to eq('Large')
|
16
|
+
expect(prompt.output.string).to eq([
|
17
|
+
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
18
|
+
"\e[32m‣ Large\e[0m\n",
|
19
|
+
" Medium\n",
|
20
|
+
" Small\n",
|
21
|
+
"\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
22
|
+
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
23
|
+
].join)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets choice name and value" do
|
27
|
+
prompt = TTY::TestPrompt.new
|
28
|
+
choices = {large: 1, medium: 2, small: 3}
|
29
|
+
prompt.input << " "
|
30
|
+
prompt.input.rewind
|
31
|
+
expect(prompt.select('What size?', choices)).to eq(1)
|
32
|
+
expect(prompt.output.string).to eq([
|
33
|
+
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
34
|
+
"\e[32m‣ large\e[0m\n",
|
35
|
+
" medium\n",
|
36
|
+
" small\n",
|
37
|
+
"\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
38
|
+
"What size? \e[32mlarge\e[0m\n\e[?25h"
|
39
|
+
].join)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "sets choice name through DSL" do
|
43
|
+
prompt = TTY::TestPrompt.new
|
44
|
+
prompt.input << " "
|
45
|
+
prompt.input.rewind
|
46
|
+
value = prompt.select('What size?') do |menu|
|
47
|
+
menu.choice "Large"
|
48
|
+
menu.choice "Medium"
|
49
|
+
menu.choice "Small"
|
50
|
+
end
|
51
|
+
expect(value).to eq('Large')
|
52
|
+
expect(prompt.output.string).to eq([
|
53
|
+
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
54
|
+
"\e[32m‣ Large\e[0m\n",
|
55
|
+
" Medium\n",
|
56
|
+
" Small\n",
|
57
|
+
"\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
58
|
+
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
59
|
+
].join)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "sets choice name & value through DSL" do
|
63
|
+
prompt = TTY::TestPrompt.new
|
64
|
+
prompt.input << " "
|
65
|
+
prompt.input.rewind
|
66
|
+
value = prompt.select('What size?') do |menu|
|
67
|
+
menu.choice :large, 1
|
68
|
+
menu.choice :medium, 2
|
69
|
+
menu.choice :small, 3
|
70
|
+
end
|
71
|
+
expect(value).to eq(1)
|
72
|
+
expect(prompt.output.string).to eq([
|
73
|
+
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
74
|
+
"\e[32m‣ large\e[0m\n",
|
75
|
+
" medium\n",
|
76
|
+
" small\n",
|
77
|
+
"\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
78
|
+
"What size? \e[32mlarge\e[0m\n\e[?25h"
|
79
|
+
].join)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "sets choices and single choice through DSL" do
|
83
|
+
prompt = TTY::TestPrompt.new
|
84
|
+
prompt.input << " "
|
85
|
+
prompt.input.rewind
|
86
|
+
value = prompt.select('What size?') do |menu|
|
87
|
+
menu.choice 'Large'
|
88
|
+
menu.choices %w(Medium Small)
|
89
|
+
end
|
90
|
+
expect(value).to eq('Large')
|
91
|
+
expect(prompt.output.string).to eq([
|
92
|
+
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
93
|
+
"\e[32m‣ Large\e[0m\n",
|
94
|
+
" Medium\n",
|
95
|
+
" Small\n",
|
96
|
+
"\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
97
|
+
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
98
|
+
].join)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "sets choice name & value through DSL" do
|
102
|
+
prompt = TTY::TestPrompt.new
|
103
|
+
prompt.input << " "
|
104
|
+
prompt.input.rewind
|
105
|
+
value = prompt.select('What size?') do |menu|
|
106
|
+
menu.default 2
|
107
|
+
|
108
|
+
menu.choice :large, 1
|
109
|
+
menu.choice :medium, 2
|
110
|
+
menu.choice :small, 3
|
111
|
+
end
|
112
|
+
expect(value).to eq(2)
|
113
|
+
expect(prompt.output.string).to eq([
|
114
|
+
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
115
|
+
" large\n",
|
116
|
+
"\e[32m‣ medium\e[0m\n",
|
117
|
+
" small\n",
|
118
|
+
"\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
119
|
+
"What size? \e[32mmedium\e[0m\n\e[?25h"
|
120
|
+
].join)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "sets choice value to proc and executes it" do
|
124
|
+
prompt = TTY::TestPrompt.new
|
125
|
+
prompt.input << " "
|
126
|
+
prompt.input.rewind
|
127
|
+
value = prompt.select('What size?', default: 2) do |menu|
|
128
|
+
menu.choice :large, 1
|
129
|
+
menu.choice :medium do 'Good choice!' end
|
130
|
+
menu.choice :small, 3
|
131
|
+
end
|
132
|
+
expect(value).to eq('Good choice!')
|
133
|
+
expect(prompt.output.string).to eq([
|
134
|
+
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
135
|
+
" large\n",
|
136
|
+
"\e[32m‣ medium\e[0m\n",
|
137
|
+
" small\n",
|
138
|
+
"\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
139
|
+
"What size? \e[32mmedium\e[0m\n\e[?25h"
|
140
|
+
].join)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "sets default option through hash syntax" do
|
144
|
+
prompt = TTY::TestPrompt.new
|
145
|
+
choices = %w(Large Medium Small)
|
146
|
+
prompt.input << " "
|
147
|
+
prompt.input.rewind
|
148
|
+
expect(prompt.select('What size?', choices, default: 2)).to eq('Medium')
|
149
|
+
expect(prompt.output.string).to eq([
|
150
|
+
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
151
|
+
" Large\n",
|
152
|
+
"\e[32m‣ Medium\e[0m\n",
|
153
|
+
" Small\n",
|
154
|
+
"\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
155
|
+
"What size? \e[32mMedium\e[0m\n\e[?25h"
|
156
|
+
].join)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "changes selected item color & marker" do
|
160
|
+
prompt = TTY::TestPrompt.new
|
161
|
+
choices = %w(Large Medium Small)
|
162
|
+
prompt.input << " "
|
163
|
+
prompt.input.rewind
|
164
|
+
value = prompt.select('What size?', choices, color: :blue, marker: '>')
|
165
|
+
expect(value).to eq('Large')
|
166
|
+
expect(prompt.output.string).to eq([
|
167
|
+
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
168
|
+
"\e[34m> Large\e[0m\n",
|
169
|
+
" Medium\n",
|
170
|
+
" Small\n",
|
171
|
+
"\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
172
|
+
"What size? \e[34mLarge\e[0m\n\e[?25h"
|
173
|
+
].join)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "changes help text" do
|
177
|
+
prompt = TTY::TestPrompt.new
|
178
|
+
choices = %w(Large Medium Small)
|
179
|
+
prompt.input << " "
|
180
|
+
prompt.input.rewind
|
181
|
+
value = prompt.select('What size?', choices, help: "(Bash keyboard)")
|
182
|
+
expect(value).to eq('Large')
|
183
|
+
expect(prompt.output.string).to eq([
|
184
|
+
"\e[?25lWhat size? \e[90m(Bash keyboard)\e[0m\n",
|
185
|
+
"\e[32m‣ Large\e[0m\n",
|
186
|
+
" Medium\n",
|
187
|
+
" Small\n",
|
188
|
+
"\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
189
|
+
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
190
|
+
].join)
|
191
|
+
end
|
192
|
+
end
|
@@ -3,10 +3,6 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe TTY::Prompt::Statement, '#new' do
|
6
|
-
let(:input) { StringIO.new }
|
7
|
-
let(:output) { StringIO.new }
|
8
|
-
let(:shell) { TTY::Prompt.new(input, output) }
|
9
|
-
|
10
6
|
it "forces newline after the prompt message" do
|
11
7
|
statement = described_class.new
|
12
8
|
expect(statement.newline).to eq(true)
|
data/spec/unit/suggest_spec.rb
CHANGED
@@ -3,31 +3,28 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe TTY::Prompt, '#suggest' do
|
6
|
-
let(:input) { StringIO.new }
|
7
|
-
let(:output) { StringIO.new }
|
8
6
|
let(:possible) { %w(status stage stash commit branch blame) }
|
9
7
|
|
10
|
-
subject(:prompt) {
|
11
|
-
|
12
|
-
after { output.rewind }
|
8
|
+
subject(:prompt) { TTY::TestPrompt.new }
|
13
9
|
|
14
10
|
it 'suggests few matches' do
|
15
11
|
prompt.suggest('sta', possible)
|
16
|
-
expect(output.string).
|
12
|
+
expect(prompt.output.string).
|
13
|
+
to eql("Did you mean one of these?\n stage\n stash\n")
|
17
14
|
end
|
18
15
|
|
19
16
|
it 'suggests a single match for one character' do
|
20
17
|
prompt.suggest('b', possible)
|
21
|
-
expect(output.string).to eql("Did you mean this?\n blame\n")
|
18
|
+
expect(prompt.output.string).to eql("Did you mean this?\n blame\n")
|
22
19
|
end
|
23
20
|
|
24
21
|
it 'suggests a single match for two characters' do
|
25
22
|
prompt.suggest('co', possible)
|
26
|
-
expect(output.string).to eql("Did you mean this?\n commit\n")
|
23
|
+
expect(prompt.output.string).to eql("Did you mean this?\n commit\n")
|
27
24
|
end
|
28
25
|
|
29
26
|
it 'suggests with different text and indentation' do
|
30
27
|
prompt.suggest('b', possible, indent: 4, single_text: 'Perhaps you meant?')
|
31
|
-
expect(output.string).to eql("Perhaps you meant?\n blame\n")
|
28
|
+
expect(prompt.output.string).to eql("Perhaps you meant?\n blame\n")
|
32
29
|
end
|
33
30
|
end
|
data/spec/unit/warn_spec.rb
CHANGED
@@ -3,28 +3,24 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe TTY::Prompt, '#warn' do
|
6
|
-
let(:input) { StringIO.new }
|
7
|
-
let(:output) { StringIO.new }
|
8
6
|
let(:color) { Pastel.new(enabled: true) }
|
9
7
|
|
10
|
-
subject(:prompt) { TTY::
|
8
|
+
subject(:prompt) { TTY::TestPrompt.new }
|
11
9
|
|
12
10
|
before { allow(Pastel).to receive(:new).and_return(color) }
|
13
11
|
|
14
|
-
after { output.rewind }
|
15
|
-
|
16
12
|
it 'displays one message' do
|
17
13
|
prompt.warn "Careful young apprentice!"
|
18
|
-
expect(output.string).to eql "\e[33mCareful young apprentice!\e[0m\n"
|
14
|
+
expect(prompt.output.string).to eql "\e[33mCareful young apprentice!\e[0m\n"
|
19
15
|
end
|
20
16
|
|
21
17
|
it 'displays many messages' do
|
22
18
|
prompt.warn "Careful there!", "It's dangerous!"
|
23
|
-
expect(output.string).to eql "\e[33mCareful there!\e[0m\n\e[33mIt's dangerous!\e[0m\n"
|
19
|
+
expect(prompt.output.string).to eql "\e[33mCareful there!\e[0m\n\e[33mIt's dangerous!\e[0m\n"
|
24
20
|
end
|
25
21
|
|
26
22
|
it 'displays message with option' do
|
27
23
|
prompt.warn "Careful young apprentice!", newline: false
|
28
|
-
expect(output.string).to eql "\e[33mCareful young apprentice!\e[0m"
|
24
|
+
expect(prompt.output.string).to eql "\e[33mCareful young apprentice!\e[0m"
|
29
25
|
end
|
30
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-prompt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: necromancer
|
@@ -78,18 +78,25 @@ files:
|
|
78
78
|
- .rspec
|
79
79
|
- .ruby-version
|
80
80
|
- .travis.yml
|
81
|
+
- CHANGELOG.md
|
81
82
|
- Gemfile
|
82
83
|
- LICENSE.txt
|
83
84
|
- README.md
|
84
85
|
- Rakefile
|
85
86
|
- lib/tty-prompt.rb
|
86
87
|
- lib/tty/prompt.rb
|
88
|
+
- lib/tty/prompt/choice.rb
|
89
|
+
- lib/tty/prompt/choices.rb
|
90
|
+
- lib/tty/prompt/codes.rb
|
91
|
+
- lib/tty/prompt/cursor.rb
|
87
92
|
- lib/tty/prompt/distance.rb
|
88
93
|
- lib/tty/prompt/error.rb
|
89
94
|
- lib/tty/prompt/history.rb
|
95
|
+
- lib/tty/prompt/list.rb
|
90
96
|
- lib/tty/prompt/mode.rb
|
91
97
|
- lib/tty/prompt/mode/echo.rb
|
92
98
|
- lib/tty/prompt/mode/raw.rb
|
99
|
+
- lib/tty/prompt/multi_list.rb
|
93
100
|
- lib/tty/prompt/question.rb
|
94
101
|
- lib/tty/prompt/question/modifier.rb
|
95
102
|
- lib/tty/prompt/question/validation.rb
|
@@ -98,13 +105,21 @@ files:
|
|
98
105
|
- lib/tty/prompt/response_delegation.rb
|
99
106
|
- lib/tty/prompt/statement.rb
|
100
107
|
- lib/tty/prompt/suggestion.rb
|
108
|
+
- lib/tty/prompt/test.rb
|
101
109
|
- lib/tty/prompt/utils.rb
|
102
110
|
- lib/tty/prompt/version.rb
|
103
111
|
- spec/spec_helper.rb
|
104
112
|
- spec/unit/ask_spec.rb
|
113
|
+
- spec/unit/choice/eql_spec.rb
|
114
|
+
- spec/unit/choice/from_spec.rb
|
115
|
+
- spec/unit/choices/add_spec.rb
|
116
|
+
- spec/unit/choices/each_spec.rb
|
117
|
+
- spec/unit/choices/new_spec.rb
|
118
|
+
- spec/unit/choices/pluck_spec.rb
|
119
|
+
- spec/unit/cursor/new_spec.rb
|
105
120
|
- spec/unit/distance/distance_spec.rb
|
106
121
|
- spec/unit/error_spec.rb
|
107
|
-
- spec/unit/
|
122
|
+
- spec/unit/multi_select_spec.rb
|
108
123
|
- spec/unit/question/character_spec.rb
|
109
124
|
- spec/unit/question/default_spec.rb
|
110
125
|
- spec/unit/question/in_spec.rb
|
@@ -113,10 +128,10 @@ files:
|
|
113
128
|
- spec/unit/question/modifier/letter_case_spec.rb
|
114
129
|
- spec/unit/question/modifier/whitespace_spec.rb
|
115
130
|
- spec/unit/question/modify_spec.rb
|
116
|
-
- spec/unit/question/
|
131
|
+
- spec/unit/question/required_spec.rb
|
117
132
|
- spec/unit/question/validate_spec.rb
|
133
|
+
- spec/unit/question/validation/call_spec.rb
|
118
134
|
- spec/unit/question/validation/coerce_spec.rb
|
119
|
-
- spec/unit/question/validation/valid_value_spec.rb
|
120
135
|
- spec/unit/reader/getc_spec.rb
|
121
136
|
- spec/unit/response/read_bool_spec.rb
|
122
137
|
- spec/unit/response/read_char_spec.rb
|
@@ -128,6 +143,7 @@ files:
|
|
128
143
|
- spec/unit/response/read_spec.rb
|
129
144
|
- spec/unit/response/read_string_spec.rb
|
130
145
|
- spec/unit/say_spec.rb
|
146
|
+
- spec/unit/select_spec.rb
|
131
147
|
- spec/unit/statement/initialize_spec.rb
|
132
148
|
- spec/unit/suggest_spec.rb
|
133
149
|
- spec/unit/warn_spec.rb
|
@@ -162,9 +178,16 @@ summary: A beautiful and powerful interactive command line prompt.
|
|
162
178
|
test_files:
|
163
179
|
- spec/spec_helper.rb
|
164
180
|
- spec/unit/ask_spec.rb
|
181
|
+
- spec/unit/choice/eql_spec.rb
|
182
|
+
- spec/unit/choice/from_spec.rb
|
183
|
+
- spec/unit/choices/add_spec.rb
|
184
|
+
- spec/unit/choices/each_spec.rb
|
185
|
+
- spec/unit/choices/new_spec.rb
|
186
|
+
- spec/unit/choices/pluck_spec.rb
|
187
|
+
- spec/unit/cursor/new_spec.rb
|
165
188
|
- spec/unit/distance/distance_spec.rb
|
166
189
|
- spec/unit/error_spec.rb
|
167
|
-
- spec/unit/
|
190
|
+
- spec/unit/multi_select_spec.rb
|
168
191
|
- spec/unit/question/character_spec.rb
|
169
192
|
- spec/unit/question/default_spec.rb
|
170
193
|
- spec/unit/question/in_spec.rb
|
@@ -173,10 +196,10 @@ test_files:
|
|
173
196
|
- spec/unit/question/modifier/letter_case_spec.rb
|
174
197
|
- spec/unit/question/modifier/whitespace_spec.rb
|
175
198
|
- spec/unit/question/modify_spec.rb
|
176
|
-
- spec/unit/question/
|
199
|
+
- spec/unit/question/required_spec.rb
|
177
200
|
- spec/unit/question/validate_spec.rb
|
201
|
+
- spec/unit/question/validation/call_spec.rb
|
178
202
|
- spec/unit/question/validation/coerce_spec.rb
|
179
|
-
- spec/unit/question/validation/valid_value_spec.rb
|
180
203
|
- spec/unit/reader/getc_spec.rb
|
181
204
|
- spec/unit/response/read_bool_spec.rb
|
182
205
|
- spec/unit/response/read_char_spec.rb
|
@@ -188,6 +211,7 @@ test_files:
|
|
188
211
|
- spec/unit/response/read_spec.rb
|
189
212
|
- spec/unit/response/read_string_spec.rb
|
190
213
|
- spec/unit/say_spec.rb
|
214
|
+
- spec/unit/select_spec.rb
|
191
215
|
- spec/unit/statement/initialize_spec.rb
|
192
216
|
- spec/unit/suggest_spec.rb
|
193
217
|
- spec/unit/warn_spec.rb
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Prompt::Question, '#argument' do
|
6
|
-
let(:input) { StringIO.new }
|
7
|
-
let(:output) { StringIO.new }
|
8
|
-
let(:prompt) { TTY::Prompt.new(input, output) }
|
9
|
-
|
10
|
-
it 'requires value to be present with helper' do
|
11
|
-
input << ''
|
12
|
-
input.rewind
|
13
|
-
q = prompt.ask("What is your name?").argument(:required)
|
14
|
-
expect { q.read }.to raise_error(ArgumentError)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'requires value to be present with option' do
|
18
|
-
input << ''
|
19
|
-
input.rewind
|
20
|
-
q = prompt.ask("What is your name?", required: true)
|
21
|
-
expect { q.read }.to raise_error(ArgumentError)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "doesn't require value to be present" do
|
25
|
-
input << ''
|
26
|
-
input.rewind
|
27
|
-
q = prompt.ask("What is your name?").argument(:optional)
|
28
|
-
expect(q.read).to be_nil
|
29
|
-
end
|
30
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Prompt::Question, '#valid' do
|
6
|
-
let(:input) { StringIO.new }
|
7
|
-
let(:output) { StringIO.new }
|
8
|
-
let(:prompt) { TTY::Prompt.new(input, output) }
|
9
|
-
|
10
|
-
let(:cards) { %w[ club diamond spade heart ] }
|
11
|
-
|
12
|
-
it 'reads valid optios with helper' do
|
13
|
-
input << 'club'
|
14
|
-
input.rewind
|
15
|
-
q = prompt.ask("What is your card suit sir?").valid(cards)
|
16
|
-
expect(q.read_choice).to eq('club')
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'reads valid options with option hash' do
|
20
|
-
input << 'club'
|
21
|
-
input.rewind
|
22
|
-
q = prompt.ask("What is your card suit sir?", valid: cards)
|
23
|
-
expect(q.read_choice).to eq('club')
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'reads invalid option' do
|
27
|
-
input << 'clover'
|
28
|
-
input.rewind
|
29
|
-
q = prompt.ask("What is your card suit sir?").valid(cards)
|
30
|
-
expect { q.read_choice }.to raise_error(TTY::Prompt::InvalidArgument)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'needs argument' do
|
34
|
-
input << ''
|
35
|
-
input.rewind
|
36
|
-
q = prompt.ask("What is your card suit sir?").valid(cards)
|
37
|
-
expect { q.read_choice }.to raise_error(TTY::Prompt::ArgumentRequired)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'reads with default' do
|
41
|
-
input << ''
|
42
|
-
input.rewind
|
43
|
-
q = prompt.ask("What is your card suit sir?").valid(cards).default('club')
|
44
|
-
expect(q.read_choice).to eq('club')
|
45
|
-
end
|
46
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe TTY::Prompt::Question::Validation, '#valid_value?' do
|
6
|
-
let(:validation) { /^[^\.]+\.[^\.]+/ }
|
7
|
-
let(:instance) { described_class.new validation }
|
8
|
-
|
9
|
-
it "validates nil input" do
|
10
|
-
expect(instance.valid_value?(nil)).to eq(false)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "validates successfully when the value matches pattern" do
|
14
|
-
expect(instance.valid_value?('piotr.murach')).to eq(true)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "fails validation when not maching pattern" do
|
18
|
-
expect {
|
19
|
-
instance.valid_value?('piotrmurach')
|
20
|
-
}.to raise_error(TTY::Prompt::InvalidArgument)
|
21
|
-
end
|
22
|
-
end
|