tty-prompt 0.2.0 → 0.3.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 +9 -6
- data/CHANGELOG.md +40 -3
- data/Gemfile +0 -1
- data/README.md +246 -65
- data/examples/ask.rb +7 -0
- data/examples/echo.rb +7 -0
- data/examples/in.rb +7 -0
- data/examples/mask.rb +9 -0
- data/examples/multi_select.rb +8 -0
- data/examples/select.rb +8 -0
- data/examples/validation.rb +9 -0
- data/examples/yes_no.rb +7 -0
- data/lib/tty-prompt.rb +6 -4
- data/lib/tty/prompt.rb +100 -25
- data/lib/tty/prompt/choice.rb +1 -1
- data/lib/tty/prompt/converter_dsl.rb +19 -0
- data/lib/tty/prompt/converter_registry.rb +56 -0
- data/lib/tty/prompt/converters.rb +77 -0
- data/lib/tty/prompt/evaluator.rb +29 -0
- data/lib/tty/prompt/list.rb +38 -36
- data/lib/tty/prompt/mask_question.rb +85 -0
- data/lib/tty/prompt/multi_list.rb +21 -32
- data/lib/tty/prompt/question.rb +184 -162
- data/lib/tty/prompt/question/checks.rb +85 -0
- data/lib/tty/prompt/question/modifier.rb +4 -5
- data/lib/tty/prompt/question/validation.rb +29 -35
- data/lib/tty/prompt/reader.rb +98 -52
- data/lib/tty/prompt/reader/codes.rb +63 -0
- data/lib/tty/prompt/reader/key_event.rb +67 -0
- data/lib/tty/prompt/reader/mode.rb +66 -0
- data/lib/tty/prompt/reader/mode/echo.rb +43 -0
- data/lib/tty/prompt/reader/mode/raw.rb +43 -0
- data/lib/tty/prompt/result.rb +42 -0
- data/lib/tty/prompt/statement.rb +9 -14
- data/lib/tty/prompt/suggestion.rb +4 -2
- data/lib/tty/prompt/symbols.rb +13 -0
- data/lib/tty/prompt/test.rb +3 -2
- data/lib/tty/prompt/utils.rb +1 -1
- data/lib/tty/prompt/version.rb +1 -1
- data/spec/unit/ask_spec.rb +31 -48
- data/spec/unit/choice/eql_spec.rb +0 -2
- data/spec/unit/choice/from_spec.rb +0 -2
- data/spec/unit/choices/add_spec.rb +0 -2
- data/spec/unit/choices/each_spec.rb +0 -2
- data/spec/unit/choices/new_spec.rb +0 -2
- data/spec/unit/choices/pluck_spec.rb +0 -2
- data/spec/unit/converters/convert_bool_spec.rb +58 -0
- data/spec/unit/{response/read_char_spec.rb → converters/convert_char_spec.rb} +2 -4
- data/spec/unit/converters/convert_custom_spec.rb +14 -0
- data/spec/unit/converters/convert_date_spec.rb +25 -0
- data/spec/unit/converters/convert_file_spec.rb +14 -0
- data/spec/unit/{response/read_number_spec.rb → converters/convert_number_spec.rb} +5 -7
- data/spec/unit/converters/convert_path_spec.rb +15 -0
- data/spec/unit/{response/read_range_spec.rb → converters/convert_range_spec.rb} +3 -5
- data/spec/unit/converters/convert_regex_spec.rb +12 -0
- data/spec/unit/converters/convert_string_spec.rb +21 -0
- data/spec/unit/distance/distance_spec.rb +0 -2
- data/spec/unit/error_spec.rb +0 -6
- data/spec/unit/evaluator_spec.rb +67 -0
- data/spec/unit/keypress_spec.rb +19 -0
- data/spec/unit/mask_spec.rb +95 -0
- data/spec/unit/multi_select_spec.rb +36 -24
- data/spec/unit/multiline_spec.rb +19 -0
- data/spec/unit/new_spec.rb +18 -0
- data/spec/unit/ok_spec.rb +10 -0
- data/spec/unit/question/default_spec.rb +17 -4
- data/spec/unit/question/echo_spec.rb +31 -0
- data/spec/unit/question/in_spec.rb +48 -16
- data/spec/unit/question/initialize_spec.rb +2 -9
- data/spec/unit/question/modifier/apply_to_spec.rb +9 -16
- data/spec/unit/question/modifier/letter_case_spec.rb +0 -2
- data/spec/unit/question/modifier/whitespace_spec.rb +12 -20
- data/spec/unit/question/modify_spec.rb +3 -7
- data/spec/unit/question/required_spec.rb +20 -14
- data/spec/unit/question/validate_spec.rb +20 -19
- data/spec/unit/question/validation/call_spec.rb +15 -6
- data/spec/unit/question/validation/coerce_spec.rb +17 -11
- data/spec/unit/reader/publish_keypress_event_spec.rb +81 -0
- data/spec/unit/reader/read_keypress_spec.rb +22 -0
- data/spec/unit/reader/read_line_spec.rb +31 -0
- data/spec/unit/reader/read_multiline_spec.rb +37 -0
- data/spec/unit/result_spec.rb +40 -0
- data/spec/unit/say_spec.rb +18 -23
- data/spec/unit/select_spec.rb +37 -32
- data/spec/unit/statement/initialize_spec.rb +4 -4
- data/spec/unit/suggest_spec.rb +0 -2
- data/spec/unit/warn_spec.rb +0 -5
- data/spec/unit/yes_no_spec.rb +70 -0
- data/tty-prompt.gemspec +7 -4
- metadata +123 -40
- data/lib/tty/prompt/codes.rb +0 -32
- data/lib/tty/prompt/cursor.rb +0 -131
- data/lib/tty/prompt/error.rb +0 -26
- data/lib/tty/prompt/mode.rb +0 -64
- data/lib/tty/prompt/mode/echo.rb +0 -41
- data/lib/tty/prompt/mode/raw.rb +0 -41
- data/lib/tty/prompt/response.rb +0 -247
- data/lib/tty/prompt/response_delegation.rb +0 -42
- data/spec/unit/cursor/new_spec.rb +0 -74
- data/spec/unit/question/character_spec.rb +0 -13
- data/spec/unit/reader/getc_spec.rb +0 -42
- data/spec/unit/response/read_bool_spec.rb +0 -58
- data/spec/unit/response/read_date_spec.rb +0 -16
- data/spec/unit/response/read_email_spec.rb +0 -45
- data/spec/unit/response/read_multiple_spec.rb +0 -21
- data/spec/unit/response/read_spec.rb +0 -69
- data/spec/unit/response/read_string_spec.rb +0 -14
data/spec/unit/say_spec.rb
CHANGED
@@ -1,62 +1,57 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
RSpec.describe TTY::Prompt, '#say' do
|
6
|
-
let(:color) { Pastel.new(enabled: true) }
|
7
4
|
|
8
5
|
subject(:prompt) { TTY::TestPrompt.new }
|
9
6
|
|
10
|
-
before { allow(Pastel).to receive(:new).and_return(color) }
|
11
|
-
|
12
7
|
it 'prints an empty message' do
|
13
|
-
prompt.say
|
14
|
-
expect(prompt.output.string).to
|
8
|
+
prompt.say('')
|
9
|
+
expect(prompt.output.string).to eq('')
|
15
10
|
end
|
16
11
|
|
17
12
|
context 'with new line' do
|
18
13
|
it 'prints a message with newline' do
|
19
|
-
prompt.say
|
20
|
-
expect(prompt.output.string).to
|
14
|
+
prompt.say("Hell yeah!\n")
|
15
|
+
expect(prompt.output.string).to eq("Hell yeah!\n")
|
21
16
|
end
|
22
17
|
|
23
18
|
it 'prints a message with implicit newline' do
|
24
|
-
prompt.say
|
25
|
-
expect(prompt.output.string).to
|
19
|
+
prompt.say("Hell yeah!\n")
|
20
|
+
expect(prompt.output.string).to eq("Hell yeah!\n")
|
26
21
|
end
|
27
22
|
|
28
23
|
it 'prints a message with newline within text' do
|
29
|
-
prompt.say
|
30
|
-
expect(prompt.output.string).to
|
24
|
+
prompt.say("Hell\n yeah!")
|
25
|
+
expect(prompt.output.string).to eq("Hell\n yeah!\n")
|
31
26
|
end
|
32
27
|
|
33
28
|
it 'prints a message with newline within text and blank space' do
|
34
|
-
prompt.say
|
35
|
-
expect(prompt.output.string).to
|
29
|
+
prompt.say("Hell\n yeah! ")
|
30
|
+
expect(prompt.output.string).to eq("Hell\n yeah! ")
|
36
31
|
end
|
37
32
|
|
38
33
|
it 'prints a message without newline' do
|
39
|
-
prompt.say
|
40
|
-
expect(prompt.output.string).to
|
34
|
+
prompt.say("Hell yeah!", newline: false)
|
35
|
+
expect(prompt.output.string).to eq("Hell yeah!")
|
41
36
|
end
|
42
37
|
end
|
43
38
|
|
44
39
|
context 'with tab or space' do
|
45
40
|
it 'prints ' do
|
46
|
-
prompt.say
|
47
|
-
expect(prompt.output.string).to
|
41
|
+
prompt.say("Hell yeah!\t")
|
42
|
+
expect(prompt.output.string).to eq("Hell yeah!\t")
|
48
43
|
end
|
49
44
|
end
|
50
45
|
|
51
46
|
context 'with color' do
|
52
47
|
it 'prints message with ansi color' do
|
53
|
-
prompt.say
|
54
|
-
expect(prompt.output.string).to
|
48
|
+
prompt.say('Hell yeah!', color: :green)
|
49
|
+
expect(prompt.output.string).to eq("\e[32mHell yeah!\e[0m\n")
|
55
50
|
end
|
56
51
|
|
57
52
|
it 'prints message with ansi color without newline' do
|
58
|
-
prompt.say
|
59
|
-
expect(prompt.output.string).to
|
53
|
+
prompt.say('Hell yeah! ', color: :green)
|
54
|
+
expect(prompt.output.string).to eq("\e[32mHell yeah! \e[0m")
|
60
55
|
end
|
61
56
|
end
|
62
57
|
end
|
data/spec/unit/select_spec.rb
CHANGED
@@ -3,12 +3,10 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe TTY::Prompt, '#select' do
|
6
|
-
let(:color) { Pastel.new(enabled: true) }
|
7
6
|
|
8
|
-
|
7
|
+
subject(:prompt) { TTY::TestPrompt.new }
|
9
8
|
|
10
9
|
it "selects by default first option" do
|
11
|
-
prompt = TTY::TestPrompt.new
|
12
10
|
choices = %w(Large Medium Small)
|
13
11
|
prompt.input << "\r"
|
14
12
|
prompt.input.rewind
|
@@ -17,14 +15,13 @@ RSpec.describe TTY::Prompt, '#select' do
|
|
17
15
|
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
18
16
|
"\e[32m‣ Large\e[0m\n",
|
19
17
|
" Medium\n",
|
20
|
-
" Small
|
21
|
-
"\e[
|
18
|
+
" Small",
|
19
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
22
20
|
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
23
21
|
].join)
|
24
22
|
end
|
25
23
|
|
26
24
|
it "sets choice name and value" do
|
27
|
-
prompt = TTY::TestPrompt.new
|
28
25
|
choices = {large: 1, medium: 2, small: 3}
|
29
26
|
prompt.input << " "
|
30
27
|
prompt.input.rewind
|
@@ -33,14 +30,13 @@ RSpec.describe TTY::Prompt, '#select' do
|
|
33
30
|
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
34
31
|
"\e[32m‣ large\e[0m\n",
|
35
32
|
" medium\n",
|
36
|
-
" small
|
37
|
-
"\e[
|
33
|
+
" small",
|
34
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
38
35
|
"What size? \e[32mlarge\e[0m\n\e[?25h"
|
39
36
|
].join)
|
40
37
|
end
|
41
38
|
|
42
39
|
it "sets choice name through DSL" do
|
43
|
-
prompt = TTY::TestPrompt.new
|
44
40
|
prompt.input << " "
|
45
41
|
prompt.input.rewind
|
46
42
|
value = prompt.select('What size?') do |menu|
|
@@ -53,14 +49,13 @@ RSpec.describe TTY::Prompt, '#select' do
|
|
53
49
|
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
54
50
|
"\e[32m‣ Large\e[0m\n",
|
55
51
|
" Medium\n",
|
56
|
-
" Small
|
57
|
-
"\e[
|
52
|
+
" Small",
|
53
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
58
54
|
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
59
55
|
].join)
|
60
56
|
end
|
61
57
|
|
62
58
|
it "sets choice name & value through DSL" do
|
63
|
-
prompt = TTY::TestPrompt.new
|
64
59
|
prompt.input << " "
|
65
60
|
prompt.input.rewind
|
66
61
|
value = prompt.select('What size?') do |menu|
|
@@ -73,14 +68,13 @@ RSpec.describe TTY::Prompt, '#select' do
|
|
73
68
|
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
74
69
|
"\e[32m‣ large\e[0m\n",
|
75
70
|
" medium\n",
|
76
|
-
" small
|
77
|
-
"\e[
|
71
|
+
" small",
|
72
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
78
73
|
"What size? \e[32mlarge\e[0m\n\e[?25h"
|
79
74
|
].join)
|
80
75
|
end
|
81
76
|
|
82
77
|
it "sets choices and single choice through DSL" do
|
83
|
-
prompt = TTY::TestPrompt.new
|
84
78
|
prompt.input << " "
|
85
79
|
prompt.input.rewind
|
86
80
|
value = prompt.select('What size?') do |menu|
|
@@ -92,14 +86,13 @@ RSpec.describe TTY::Prompt, '#select' do
|
|
92
86
|
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
93
87
|
"\e[32m‣ Large\e[0m\n",
|
94
88
|
" Medium\n",
|
95
|
-
" Small
|
96
|
-
"\e[
|
89
|
+
" Small",
|
90
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
97
91
|
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
98
92
|
].join)
|
99
93
|
end
|
100
94
|
|
101
95
|
it "sets choice name & value through DSL" do
|
102
|
-
prompt = TTY::TestPrompt.new
|
103
96
|
prompt.input << " "
|
104
97
|
prompt.input.rewind
|
105
98
|
value = prompt.select('What size?') do |menu|
|
@@ -114,14 +107,13 @@ RSpec.describe TTY::Prompt, '#select' do
|
|
114
107
|
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
115
108
|
" large\n",
|
116
109
|
"\e[32m‣ medium\e[0m\n",
|
117
|
-
" small
|
118
|
-
"\e[
|
110
|
+
" small",
|
111
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
119
112
|
"What size? \e[32mmedium\e[0m\n\e[?25h"
|
120
113
|
].join)
|
121
114
|
end
|
122
115
|
|
123
116
|
it "sets choice value to proc and executes it" do
|
124
|
-
prompt = TTY::TestPrompt.new
|
125
117
|
prompt.input << " "
|
126
118
|
prompt.input.rewind
|
127
119
|
value = prompt.select('What size?', default: 2) do |menu|
|
@@ -134,14 +126,13 @@ RSpec.describe TTY::Prompt, '#select' do
|
|
134
126
|
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
135
127
|
" large\n",
|
136
128
|
"\e[32m‣ medium\e[0m\n",
|
137
|
-
" small
|
138
|
-
"\e[
|
129
|
+
" small",
|
130
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
139
131
|
"What size? \e[32mmedium\e[0m\n\e[?25h"
|
140
132
|
].join)
|
141
133
|
end
|
142
134
|
|
143
135
|
it "sets default option through hash syntax" do
|
144
|
-
prompt = TTY::TestPrompt.new
|
145
136
|
choices = %w(Large Medium Small)
|
146
137
|
prompt.input << " "
|
147
138
|
prompt.input.rewind
|
@@ -150,14 +141,13 @@ RSpec.describe TTY::Prompt, '#select' do
|
|
150
141
|
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
151
142
|
" Large\n",
|
152
143
|
"\e[32m‣ Medium\e[0m\n",
|
153
|
-
" Small
|
154
|
-
"\e[
|
144
|
+
" Small",
|
145
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
155
146
|
"What size? \e[32mMedium\e[0m\n\e[?25h"
|
156
147
|
].join)
|
157
148
|
end
|
158
149
|
|
159
150
|
it "changes selected item color & marker" do
|
160
|
-
prompt = TTY::TestPrompt.new
|
161
151
|
choices = %w(Large Medium Small)
|
162
152
|
prompt.input << " "
|
163
153
|
prompt.input.rewind
|
@@ -167,14 +157,13 @@ RSpec.describe TTY::Prompt, '#select' do
|
|
167
157
|
"\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
168
158
|
"\e[34m> Large\e[0m\n",
|
169
159
|
" Medium\n",
|
170
|
-
" Small
|
171
|
-
"\e[
|
160
|
+
" Small",
|
161
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
172
162
|
"What size? \e[34mLarge\e[0m\n\e[?25h"
|
173
163
|
].join)
|
174
164
|
end
|
175
165
|
|
176
166
|
it "changes help text" do
|
177
|
-
prompt = TTY::TestPrompt.new
|
178
167
|
choices = %w(Large Medium Small)
|
179
168
|
prompt.input << " "
|
180
169
|
prompt.input.rewind
|
@@ -184,9 +173,25 @@ RSpec.describe TTY::Prompt, '#select' do
|
|
184
173
|
"\e[?25lWhat size? \e[90m(Bash keyboard)\e[0m\n",
|
185
174
|
"\e[32m‣ Large\e[0m\n",
|
186
175
|
" Medium\n",
|
187
|
-
" Small
|
188
|
-
"\e[
|
176
|
+
" Small",
|
177
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
189
178
|
"What size? \e[32mLarge\e[0m\n\e[?25h"
|
190
179
|
].join)
|
191
180
|
end
|
181
|
+
|
182
|
+
it "sets prompt prefix" do
|
183
|
+
prompt = TTY::TestPrompt.new(prefix: '[?] ')
|
184
|
+
choices = %w(Large Medium Small)
|
185
|
+
prompt.input << "\r"
|
186
|
+
prompt.input.rewind
|
187
|
+
expect(prompt.select('What size?', choices)).to eq('Large')
|
188
|
+
expect(prompt.output.string).to eq([
|
189
|
+
"\e[?25l[?] What size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
|
190
|
+
"\e[32m‣ Large\e[0m\n",
|
191
|
+
" Medium\n",
|
192
|
+
" Small",
|
193
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
|
194
|
+
"[?] What size? \e[32mLarge\e[0m\n\e[?25h"
|
195
|
+
].join)
|
196
|
+
end
|
192
197
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
RSpec.describe TTY::Prompt::Statement, '#new' do
|
6
4
|
it "forces newline after the prompt message" do
|
7
|
-
|
5
|
+
prompt = TTY::TestPrompt.new
|
6
|
+
statement = described_class.new(prompt)
|
8
7
|
expect(statement.newline).to eq(true)
|
9
8
|
end
|
10
9
|
|
11
10
|
it "displays prompt message in color" do
|
12
|
-
|
11
|
+
prompt = TTY::TestPrompt.new
|
12
|
+
statement = described_class.new(prompt)
|
13
13
|
expect(statement.color).to eq(false)
|
14
14
|
end
|
15
15
|
end
|
data/spec/unit/suggest_spec.rb
CHANGED
data/spec/unit/warn_spec.rb
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
RSpec.describe TTY::Prompt, '#warn' do
|
6
|
-
let(:color) { Pastel.new(enabled: true) }
|
7
4
|
|
8
5
|
subject(:prompt) { TTY::TestPrompt.new }
|
9
6
|
|
10
|
-
before { allow(Pastel).to receive(:new).and_return(color) }
|
11
|
-
|
12
7
|
it 'displays one message' do
|
13
8
|
prompt.warn "Careful young apprentice!"
|
14
9
|
expect(prompt.output.string).to eql "\e[33mCareful young apprentice!\e[0m\n"
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::Prompt, '#yes?' do
|
4
|
+
|
5
|
+
subject(:prompt) { TTY::TestPrompt.new }
|
6
|
+
|
7
|
+
context 'yes?' do
|
8
|
+
it 'agrees' 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[1000D\e[K\e[1A",
|
15
|
+
"\e[1000D\e[K",
|
16
|
+
"Are you a human? \e[32myes\e[0m\n"
|
17
|
+
].join)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'disagrees' do
|
21
|
+
prompt.input << 'no'
|
22
|
+
prompt.input.rewind
|
23
|
+
expect(prompt.yes?("Are you a human?")).to eq(false)
|
24
|
+
expect(prompt.output.string).to eq([
|
25
|
+
"Are you a human? \e[90m(Y/n)\e[0m ",
|
26
|
+
"\e[1000D\e[K\e[1A",
|
27
|
+
"\e[1000D\e[K",
|
28
|
+
"Are you a human? \e[32mno\e[0m\n"
|
29
|
+
].join)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'assumes default true' do
|
33
|
+
prompt.input << "\r"
|
34
|
+
prompt.input.rewind
|
35
|
+
expect(prompt.yes?("Are you a human?", default: true)).to eq(true)
|
36
|
+
expect(prompt.output.string).to eq([
|
37
|
+
"Are you a human? \e[90m(Y/n)\e[0m ",
|
38
|
+
"\e[1000D\e[K\e[1A",
|
39
|
+
"\e[1000D\e[K",
|
40
|
+
"Are you a human? \e[32mtrue\e[0m\n"
|
41
|
+
].join)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'no?' do
|
46
|
+
it 'disagrees' do
|
47
|
+
prompt.input << 'no'
|
48
|
+
prompt.input.rewind
|
49
|
+
expect(prompt.no?("Are you a human?")).to eq(true)
|
50
|
+
expect(prompt.output.string).to eq([
|
51
|
+
"Are you a human? \e[90m(Y/n)\e[0m ",
|
52
|
+
"\e[1000D\e[K\e[1A",
|
53
|
+
"\e[1000D\e[K",
|
54
|
+
"Are you a human? \e[32mno\e[0m\n"
|
55
|
+
].join)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'agrees' do
|
59
|
+
prompt.input << 'yes'
|
60
|
+
prompt.input.rewind
|
61
|
+
expect(prompt.no?("Are you a human?")).to eq(false)
|
62
|
+
expect(prompt.output.string).to eq([
|
63
|
+
"Are you a human? \e[90m(Y/n)\e[0m ",
|
64
|
+
"\e[1000D\e[K\e[1A",
|
65
|
+
"\e[1000D\e[K",
|
66
|
+
"Are you a human? \e[32myes\e[0m\n"
|
67
|
+
].join)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/tty-prompt.gemspec
CHANGED
@@ -18,9 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
23
|
-
spec.add_dependency
|
21
|
+
spec.add_dependency 'necromancer', '~> 0.3.0'
|
22
|
+
spec.add_dependency 'pastel', '~> 0.5.2'
|
23
|
+
spec.add_dependency 'tty-cursor', '~> 0.2.0'
|
24
|
+
spec.add_dependency 'tty-platform', '~> 0.1.0'
|
25
|
+
spec.add_dependency 'wisper', '~> 1.6.1'
|
24
26
|
|
25
|
-
spec.add_development_dependency
|
27
|
+
spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
|
28
|
+
spec.add_development_dependency 'rake'
|
26
29
|
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.3.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
|
+
date: 2015-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: necromancer
|
@@ -30,14 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.5.
|
33
|
+
version: 0.5.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.5.
|
40
|
+
version: 0.5.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tty-cursor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: tty-platform
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,19 +67,53 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: 0.1.0
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: wisper
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ~>
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
type: :
|
75
|
+
version: 1.6.1
|
76
|
+
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - ~>
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: 1.6.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.5.0
|
90
|
+
- - <
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '2.0'
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 1.5.0
|
100
|
+
- - <
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rake
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
69
117
|
description: A beautiful and powerful interactive command line prompt with a robust
|
70
118
|
API for getting and validating complex inputs.
|
71
119
|
email:
|
@@ -83,28 +131,41 @@ files:
|
|
83
131
|
- LICENSE.txt
|
84
132
|
- README.md
|
85
133
|
- Rakefile
|
134
|
+
- examples/ask.rb
|
135
|
+
- examples/echo.rb
|
136
|
+
- examples/in.rb
|
137
|
+
- examples/mask.rb
|
138
|
+
- examples/multi_select.rb
|
139
|
+
- examples/select.rb
|
140
|
+
- examples/validation.rb
|
141
|
+
- examples/yes_no.rb
|
86
142
|
- lib/tty-prompt.rb
|
87
143
|
- lib/tty/prompt.rb
|
88
144
|
- lib/tty/prompt/choice.rb
|
89
145
|
- lib/tty/prompt/choices.rb
|
90
|
-
- lib/tty/prompt/
|
91
|
-
- lib/tty/prompt/
|
146
|
+
- lib/tty/prompt/converter_dsl.rb
|
147
|
+
- lib/tty/prompt/converter_registry.rb
|
148
|
+
- lib/tty/prompt/converters.rb
|
92
149
|
- lib/tty/prompt/distance.rb
|
93
|
-
- lib/tty/prompt/
|
150
|
+
- lib/tty/prompt/evaluator.rb
|
94
151
|
- lib/tty/prompt/history.rb
|
95
152
|
- lib/tty/prompt/list.rb
|
96
|
-
- lib/tty/prompt/
|
97
|
-
- lib/tty/prompt/mode/echo.rb
|
98
|
-
- lib/tty/prompt/mode/raw.rb
|
153
|
+
- lib/tty/prompt/mask_question.rb
|
99
154
|
- lib/tty/prompt/multi_list.rb
|
100
155
|
- lib/tty/prompt/question.rb
|
156
|
+
- lib/tty/prompt/question/checks.rb
|
101
157
|
- lib/tty/prompt/question/modifier.rb
|
102
158
|
- lib/tty/prompt/question/validation.rb
|
103
159
|
- lib/tty/prompt/reader.rb
|
104
|
-
- lib/tty/prompt/
|
105
|
-
- lib/tty/prompt/
|
160
|
+
- lib/tty/prompt/reader/codes.rb
|
161
|
+
- lib/tty/prompt/reader/key_event.rb
|
162
|
+
- lib/tty/prompt/reader/mode.rb
|
163
|
+
- lib/tty/prompt/reader/mode/echo.rb
|
164
|
+
- lib/tty/prompt/reader/mode/raw.rb
|
165
|
+
- lib/tty/prompt/result.rb
|
106
166
|
- lib/tty/prompt/statement.rb
|
107
167
|
- lib/tty/prompt/suggestion.rb
|
168
|
+
- lib/tty/prompt/symbols.rb
|
108
169
|
- lib/tty/prompt/test.rb
|
109
170
|
- lib/tty/prompt/utils.rb
|
110
171
|
- lib/tty/prompt/version.rb
|
@@ -116,12 +177,27 @@ files:
|
|
116
177
|
- spec/unit/choices/each_spec.rb
|
117
178
|
- spec/unit/choices/new_spec.rb
|
118
179
|
- spec/unit/choices/pluck_spec.rb
|
119
|
-
- spec/unit/
|
180
|
+
- spec/unit/converters/convert_bool_spec.rb
|
181
|
+
- spec/unit/converters/convert_char_spec.rb
|
182
|
+
- spec/unit/converters/convert_custom_spec.rb
|
183
|
+
- spec/unit/converters/convert_date_spec.rb
|
184
|
+
- spec/unit/converters/convert_file_spec.rb
|
185
|
+
- spec/unit/converters/convert_number_spec.rb
|
186
|
+
- spec/unit/converters/convert_path_spec.rb
|
187
|
+
- spec/unit/converters/convert_range_spec.rb
|
188
|
+
- spec/unit/converters/convert_regex_spec.rb
|
189
|
+
- spec/unit/converters/convert_string_spec.rb
|
120
190
|
- spec/unit/distance/distance_spec.rb
|
121
191
|
- spec/unit/error_spec.rb
|
192
|
+
- spec/unit/evaluator_spec.rb
|
193
|
+
- spec/unit/keypress_spec.rb
|
194
|
+
- spec/unit/mask_spec.rb
|
122
195
|
- spec/unit/multi_select_spec.rb
|
123
|
-
- spec/unit/
|
196
|
+
- spec/unit/multiline_spec.rb
|
197
|
+
- spec/unit/new_spec.rb
|
198
|
+
- spec/unit/ok_spec.rb
|
124
199
|
- spec/unit/question/default_spec.rb
|
200
|
+
- spec/unit/question/echo_spec.rb
|
125
201
|
- spec/unit/question/in_spec.rb
|
126
202
|
- spec/unit/question/initialize_spec.rb
|
127
203
|
- spec/unit/question/modifier/apply_to_spec.rb
|
@@ -132,21 +208,17 @@ files:
|
|
132
208
|
- spec/unit/question/validate_spec.rb
|
133
209
|
- spec/unit/question/validation/call_spec.rb
|
134
210
|
- spec/unit/question/validation/coerce_spec.rb
|
135
|
-
- spec/unit/reader/
|
136
|
-
- spec/unit/
|
137
|
-
- spec/unit/
|
138
|
-
- spec/unit/
|
139
|
-
- spec/unit/
|
140
|
-
- spec/unit/response/read_multiple_spec.rb
|
141
|
-
- spec/unit/response/read_number_spec.rb
|
142
|
-
- spec/unit/response/read_range_spec.rb
|
143
|
-
- spec/unit/response/read_spec.rb
|
144
|
-
- spec/unit/response/read_string_spec.rb
|
211
|
+
- spec/unit/reader/publish_keypress_event_spec.rb
|
212
|
+
- spec/unit/reader/read_keypress_spec.rb
|
213
|
+
- spec/unit/reader/read_line_spec.rb
|
214
|
+
- spec/unit/reader/read_multiline_spec.rb
|
215
|
+
- spec/unit/result_spec.rb
|
145
216
|
- spec/unit/say_spec.rb
|
146
217
|
- spec/unit/select_spec.rb
|
147
218
|
- spec/unit/statement/initialize_spec.rb
|
148
219
|
- spec/unit/suggest_spec.rb
|
149
220
|
- spec/unit/warn_spec.rb
|
221
|
+
- spec/unit/yes_no_spec.rb
|
150
222
|
- tasks/console.rake
|
151
223
|
- tasks/coverage.rake
|
152
224
|
- tasks/spec.rake
|
@@ -184,12 +256,27 @@ test_files:
|
|
184
256
|
- spec/unit/choices/each_spec.rb
|
185
257
|
- spec/unit/choices/new_spec.rb
|
186
258
|
- spec/unit/choices/pluck_spec.rb
|
187
|
-
- spec/unit/
|
259
|
+
- spec/unit/converters/convert_bool_spec.rb
|
260
|
+
- spec/unit/converters/convert_char_spec.rb
|
261
|
+
- spec/unit/converters/convert_custom_spec.rb
|
262
|
+
- spec/unit/converters/convert_date_spec.rb
|
263
|
+
- spec/unit/converters/convert_file_spec.rb
|
264
|
+
- spec/unit/converters/convert_number_spec.rb
|
265
|
+
- spec/unit/converters/convert_path_spec.rb
|
266
|
+
- spec/unit/converters/convert_range_spec.rb
|
267
|
+
- spec/unit/converters/convert_regex_spec.rb
|
268
|
+
- spec/unit/converters/convert_string_spec.rb
|
188
269
|
- spec/unit/distance/distance_spec.rb
|
189
270
|
- spec/unit/error_spec.rb
|
271
|
+
- spec/unit/evaluator_spec.rb
|
272
|
+
- spec/unit/keypress_spec.rb
|
273
|
+
- spec/unit/mask_spec.rb
|
190
274
|
- spec/unit/multi_select_spec.rb
|
191
|
-
- spec/unit/
|
275
|
+
- spec/unit/multiline_spec.rb
|
276
|
+
- spec/unit/new_spec.rb
|
277
|
+
- spec/unit/ok_spec.rb
|
192
278
|
- spec/unit/question/default_spec.rb
|
279
|
+
- spec/unit/question/echo_spec.rb
|
193
280
|
- spec/unit/question/in_spec.rb
|
194
281
|
- spec/unit/question/initialize_spec.rb
|
195
282
|
- spec/unit/question/modifier/apply_to_spec.rb
|
@@ -200,19 +287,15 @@ test_files:
|
|
200
287
|
- spec/unit/question/validate_spec.rb
|
201
288
|
- spec/unit/question/validation/call_spec.rb
|
202
289
|
- spec/unit/question/validation/coerce_spec.rb
|
203
|
-
- spec/unit/reader/
|
204
|
-
- spec/unit/
|
205
|
-
- spec/unit/
|
206
|
-
- spec/unit/
|
207
|
-
- spec/unit/
|
208
|
-
- spec/unit/response/read_multiple_spec.rb
|
209
|
-
- spec/unit/response/read_number_spec.rb
|
210
|
-
- spec/unit/response/read_range_spec.rb
|
211
|
-
- spec/unit/response/read_spec.rb
|
212
|
-
- spec/unit/response/read_string_spec.rb
|
290
|
+
- spec/unit/reader/publish_keypress_event_spec.rb
|
291
|
+
- spec/unit/reader/read_keypress_spec.rb
|
292
|
+
- spec/unit/reader/read_line_spec.rb
|
293
|
+
- spec/unit/reader/read_multiline_spec.rb
|
294
|
+
- spec/unit/result_spec.rb
|
213
295
|
- spec/unit/say_spec.rb
|
214
296
|
- spec/unit/select_spec.rb
|
215
297
|
- spec/unit/statement/initialize_spec.rb
|
216
298
|
- spec/unit/suggest_spec.rb
|
217
299
|
- spec/unit/warn_spec.rb
|
300
|
+
- spec/unit/yes_no_spec.rb
|
218
301
|
has_rdoc:
|