tty-prompt 0.2.0 → 0.3.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 +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
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::Prompt::Question, 'convert bool' do
|
4
|
+
|
5
|
+
subject(:prompt) { TTY::TestPrompt.new}
|
6
|
+
|
7
|
+
it 'fails to convert boolean' do
|
8
|
+
prompt.input << 'invalid'
|
9
|
+
prompt.input.rewind
|
10
|
+
expect {
|
11
|
+
prompt.ask("Do you read books?", convert: :bool)
|
12
|
+
}.to raise_error(Necromancer::ConversionTypeError)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "handles default values" do
|
16
|
+
prompt.input << "\n"
|
17
|
+
prompt.input.rewind
|
18
|
+
response = prompt.ask('Do you read books?', convert: :bool, default: true)
|
19
|
+
expect(response).to eql(true)
|
20
|
+
expect(prompt.output.string).to eq([
|
21
|
+
"Do you read books? \e[90m(Y/n)\e[0m ",
|
22
|
+
"\e[1000D\e[K\e[1A",
|
23
|
+
"\e[1000D\e[K",
|
24
|
+
"Do you read books? \e[32mtrue\e[0m\n"
|
25
|
+
].join)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "handles default values" do
|
29
|
+
prompt.input << "\n"
|
30
|
+
prompt.input.rewind
|
31
|
+
response = prompt.ask("Do you read books?") { |q|
|
32
|
+
q.default true
|
33
|
+
q.convert :bool
|
34
|
+
}
|
35
|
+
expect(response).to eq(true)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'converts negative boolean' do
|
39
|
+
prompt.input << 'No'
|
40
|
+
prompt.input.rewind
|
41
|
+
response = prompt.ask('Do you read books?', convert: :bool)
|
42
|
+
expect(response).to eq(false)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'converts positive boolean' do
|
46
|
+
prompt.input << 'Yes'
|
47
|
+
prompt.input.rewind
|
48
|
+
response = prompt.ask("Do you read books?", convert: :bool)
|
49
|
+
expect(response).to eq(true)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'converts single positive boolean' do
|
53
|
+
prompt.input << 'y'
|
54
|
+
prompt.input.rewind
|
55
|
+
response = prompt.ask('Do you read books?', convert: :bool)
|
56
|
+
expect(response).to eq(true)
|
57
|
+
end
|
58
|
+
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
RSpec.describe TTY::Prompt::Question, '#read_char' do
|
3
|
+
RSpec.describe TTY::Prompt::Question, 'convert char' do
|
6
4
|
it 'reads single character' do
|
7
5
|
prompt = TTY::TestPrompt.new
|
8
6
|
prompt.input << "abcde"
|
9
7
|
prompt.input.rewind
|
10
|
-
response = prompt.ask("What is your favourite letter?",
|
8
|
+
response = prompt.ask("What is your favourite letter?", convert: :char)
|
11
9
|
expect(response).to eq('a')
|
12
10
|
end
|
13
11
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::Prompt::Question, 'convert custom' do
|
4
|
+
|
5
|
+
subject(:prompt) { TTY::TestPrompt.new }
|
6
|
+
|
7
|
+
it 'converts response with custom conversion' do
|
8
|
+
prompt.input << "one,two,three\n"
|
9
|
+
prompt.input.rewind
|
10
|
+
conversion = proc { |input| input.split(/,\s*/) }
|
11
|
+
answer = prompt.ask('Ingredients? (comma sep list)', convert: conversion)
|
12
|
+
expect(answer).to eq(['one','two','three'])
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::Prompt::Question, 'convert date' do
|
4
|
+
it 'converts date' do
|
5
|
+
prompt = TTY::TestPrompt.new
|
6
|
+
prompt.input << "20th April 1887"
|
7
|
+
prompt.input.rewind
|
8
|
+
response = prompt.ask("When were your born?", convert: :date)
|
9
|
+
expect(response).to be_kind_of(Date)
|
10
|
+
expect(response.day).to eq(20)
|
11
|
+
expect(response.month).to eq(4)
|
12
|
+
expect(response.year).to eq(1887)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "converts datetime" do
|
16
|
+
prompt = TTY::TestPrompt.new
|
17
|
+
prompt.input << "20th April 1887"
|
18
|
+
prompt.input.rewind
|
19
|
+
response = prompt.ask("When were your born?", convert: :datetime)
|
20
|
+
expect(response).to be_kind_of(DateTime)
|
21
|
+
expect(response.day).to eq(20)
|
22
|
+
expect(response.month).to eq(4)
|
23
|
+
expect(response.year).to eq(1887)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::Prompt::Question, 'convert file' do
|
4
|
+
it "converts to file" do
|
5
|
+
file = double(:file)
|
6
|
+
allow(File).to receive(:open).with(/test\.txt/).and_return(file)
|
7
|
+
prompt = TTY::TestPrompt.new
|
8
|
+
prompt.input << "test.txt"
|
9
|
+
prompt.input.rewind
|
10
|
+
answer = prompt.ask("Which file to open?", convert: :file)
|
11
|
+
expect(answer).to eq(file)
|
12
|
+
# expect(File).to have_received(:open).with(/test\.txt/)
|
13
|
+
end
|
14
|
+
end
|
@@ -1,23 +1,21 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
RSpec.describe TTY::Prompt::Question, '#read_numbers' do
|
6
|
-
it 'reads integer' do
|
3
|
+
RSpec.describe TTY::Prompt::Question, 'convert numbers' do
|
4
|
+
it 'converts integer' do
|
7
5
|
prompt = TTY::TestPrompt.new
|
8
6
|
prompt.input << 35
|
9
7
|
prompt.input.rewind
|
10
|
-
answer = prompt.ask("What temperature?",
|
8
|
+
answer = prompt.ask("What temperature?", convert: :int)
|
11
9
|
expect(answer).to be_a(Integer)
|
12
10
|
expect(answer).to eq(35)
|
13
11
|
end
|
14
12
|
|
15
|
-
it '
|
13
|
+
it 'converts float' do
|
16
14
|
prompt = TTY::TestPrompt.new
|
17
15
|
number = 6.666
|
18
16
|
prompt.input << number
|
19
17
|
prompt.input.rewind
|
20
|
-
answer = prompt.ask('How tall are you?',
|
18
|
+
answer = prompt.ask('How tall are you?', convert: :float)
|
21
19
|
expect(answer).to be_a(Float)
|
22
20
|
expect(answer).to eq(number)
|
23
21
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::Prompt::Question, 'convert path' do
|
4
|
+
subject(:prompt) { TTY::TestPrompt.new }
|
5
|
+
|
6
|
+
it "converts pathname" do
|
7
|
+
path = double(:path)
|
8
|
+
allow(Pathname).to receive(:new).and_return(path)
|
9
|
+
prompt.input << "/path/to/file"
|
10
|
+
prompt.input.rewind
|
11
|
+
answer = prompt.ask('File location?', convert: :path)
|
12
|
+
# expect(Pathname).to have_received(:new).with(/path\/to\/file/)
|
13
|
+
expect(answer).to eql(path)
|
14
|
+
end
|
15
|
+
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
RSpec.describe TTY::Prompt::Question, '#read_range' do
|
3
|
+
RSpec.describe TTY::Prompt::Question, 'convert range' do
|
6
4
|
it 'converts with valid range' do
|
7
5
|
prompt = TTY::TestPrompt.new
|
8
6
|
prompt.input << "20-30"
|
9
7
|
prompt.input.rewind
|
10
|
-
answer = prompt.ask("Which age group?",
|
8
|
+
answer = prompt.ask("Which age group?", convert: :range)
|
11
9
|
expect(answer).to be_a(Range)
|
12
10
|
expect(answer).to eq(20..30)
|
13
11
|
end
|
@@ -17,7 +15,7 @@ RSpec.describe TTY::Prompt::Question, '#read_range' do
|
|
17
15
|
prompt.input << "abcd"
|
18
16
|
prompt.input.rewind
|
19
17
|
expect {
|
20
|
-
prompt.ask('Which age group?',
|
18
|
+
prompt.ask('Which age group?', convert: :range)
|
21
19
|
}.to raise_error(Necromancer::ConversionTypeError)
|
22
20
|
end
|
23
21
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::Prompt::Question, 'convert regexp' do
|
4
|
+
it "converts regex" do
|
5
|
+
prompt = TTY::TestPrompt.new
|
6
|
+
prompt.input << "[a-z]*"
|
7
|
+
prompt.input.rewind
|
8
|
+
answer = prompt.ask("Regex?", convert: :regexp)
|
9
|
+
expect(answer).to be_a(Regexp)
|
10
|
+
expect(answer).to eq(/[a-z]*/)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::Prompt::Question, 'convert string' do
|
4
|
+
it 'converts string' do
|
5
|
+
prompt = TTY::TestPrompt.new
|
6
|
+
prompt.input << 'Piotr'
|
7
|
+
prompt.input.rewind
|
8
|
+
answer = prompt.ask("What is your name?", convert: :string)
|
9
|
+
expect(answer).to be_a(String)
|
10
|
+
expect(answer).to eq('Piotr')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "converts symbol" do
|
14
|
+
prompt = TTY::TestPrompt.new
|
15
|
+
prompt.input << 'Piotr'
|
16
|
+
prompt.input.rewind
|
17
|
+
answer = prompt.ask("What is your name?", convert: :symbol)
|
18
|
+
expect(answer).to be_a(Symbol)
|
19
|
+
expect(answer).to eq(:Piotr)
|
20
|
+
end
|
21
|
+
end
|
data/spec/unit/error_spec.rb
CHANGED
@@ -1,14 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
RSpec.describe TTY::Prompt, '.error' do
|
6
|
-
let(:color) { Pastel.new(enabled: true) }
|
7
|
-
|
8
4
|
subject(:prompt) { TTY::TestPrompt.new }
|
9
5
|
|
10
|
-
before { allow(Pastel).to receive(:new).and_return(color) }
|
11
|
-
|
12
6
|
it 'displays one message' do
|
13
7
|
prompt.error "Nothing is fine!"
|
14
8
|
expect(prompt.output.string).to eql "\e[31mNothing is fine!\e[0m\n"
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::Prompt::Evaluator do
|
4
|
+
it "checks chained validation procs" do
|
5
|
+
question = double(:question)
|
6
|
+
evaluator = TTY::Prompt::Evaluator.new(question)
|
7
|
+
|
8
|
+
evaluator.check { |quest, value|
|
9
|
+
if value < 21
|
10
|
+
[value, ["#{value} is not bigger than 21"]]
|
11
|
+
else
|
12
|
+
value
|
13
|
+
end
|
14
|
+
}
|
15
|
+
|
16
|
+
evaluator.check { |quest, value|
|
17
|
+
if value < 42
|
18
|
+
[value, ["#{value} is not bigger than 42"]]
|
19
|
+
else
|
20
|
+
value
|
21
|
+
end
|
22
|
+
}
|
23
|
+
|
24
|
+
answer = evaluator.call(2)
|
25
|
+
expect(answer.errors.count).to eq(2)
|
26
|
+
expect(answer.value).to eq(2)
|
27
|
+
expect(answer.success?).to eq(false)
|
28
|
+
expect(answer.failure?).to eq(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "checks chained validation objects" do
|
32
|
+
question = double(:question)
|
33
|
+
evaluator = TTY::Prompt::Evaluator.new(question)
|
34
|
+
|
35
|
+
LessThan21 = Class.new do
|
36
|
+
def self.call(quest, value)
|
37
|
+
if value < 21
|
38
|
+
[value, ["#{value} is not bigger than 21"]]
|
39
|
+
else
|
40
|
+
value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
LessThan42 = Class.new do
|
46
|
+
def self.call(quest, value)
|
47
|
+
if value < 42
|
48
|
+
[value, ["#{value} is not bigger than 42"]]
|
49
|
+
else
|
50
|
+
value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
evaluator.check(LessThan21)
|
56
|
+
evaluator.check(LessThan42)
|
57
|
+
|
58
|
+
answer = evaluator.call(2)
|
59
|
+
expect(answer.errors).to match_array([
|
60
|
+
"2 is not bigger than 21",
|
61
|
+
"2 is not bigger than 42"
|
62
|
+
])
|
63
|
+
expect(answer.value).to eq(2)
|
64
|
+
expect(answer.success?).to eq(false)
|
65
|
+
expect(answer.failure?).to eq(true)
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::Prompt::Question, 'ask keypress' do
|
4
|
+
it 'asks for a keypress with :read option' do
|
5
|
+
prompt = TTY::TestPrompt.new
|
6
|
+
prompt.input << "abcd"
|
7
|
+
prompt.input.rewind
|
8
|
+
answer = prompt.ask("Which one do you prefer a, b, c or d?", read: :keypress)
|
9
|
+
expect(answer).to eq("a")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'asks for a keypress with method' do
|
13
|
+
prompt = TTY::TestPrompt.new
|
14
|
+
prompt.input << "abcd"
|
15
|
+
prompt.input.rewind
|
16
|
+
answer = prompt.keypress("Which one do you prefer a, b, c or d?")
|
17
|
+
expect(answer).to eq("a")
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::Prompt, '#mask' do
|
4
|
+
|
5
|
+
subject(:prompt) { TTY::TestPrompt.new }
|
6
|
+
|
7
|
+
it "masks output by default" do
|
8
|
+
prompt.input << "pass\r"
|
9
|
+
prompt.input.rewind
|
10
|
+
answer = prompt.mask("What is your password?")
|
11
|
+
expect(answer).to eql("pass")
|
12
|
+
expect(prompt.output.string).to eq([
|
13
|
+
"What is your password? ",
|
14
|
+
"\e[1000D\e[K",
|
15
|
+
"What is your password? •",
|
16
|
+
"\e[1000D\e[K",
|
17
|
+
"What is your password? ••",
|
18
|
+
"\e[1000D\e[K",
|
19
|
+
"What is your password? •••",
|
20
|
+
"\e[1000D\e[K",
|
21
|
+
"What is your password? ••••",
|
22
|
+
"\e[1000D\e[K",
|
23
|
+
"What is your password? \e[32m••••\e[0m\n",
|
24
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K",
|
25
|
+
"What is your password? \e[32m••••\e[0m\n"
|
26
|
+
].join)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'masks output with custom character' do
|
30
|
+
prompt.input << "pass\r"
|
31
|
+
prompt.input.rewind
|
32
|
+
answer = prompt.mask("What is your password?") { |q| q.mask('*') }
|
33
|
+
expect(answer).to eql("pass")
|
34
|
+
expect(prompt.output.string).to eq([
|
35
|
+
"What is your password? ",
|
36
|
+
"\e[1000D\e[K",
|
37
|
+
"What is your password? *",
|
38
|
+
"\e[1000D\e[K",
|
39
|
+
"What is your password? **",
|
40
|
+
"\e[1000D\e[K",
|
41
|
+
"What is your password? ***",
|
42
|
+
"\e[1000D\e[K",
|
43
|
+
"What is your password? ****",
|
44
|
+
"\e[1000D\e[K",
|
45
|
+
"What is your password? \e[32m****\e[0m\n",
|
46
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K",
|
47
|
+
"What is your password? \e[32m****\e[0m\n",
|
48
|
+
].join)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "masks with unicode character" do
|
52
|
+
prompt.input << "lov\n"
|
53
|
+
prompt.input.rewind
|
54
|
+
answer = prompt.mask("What is your password?", mask: "\u2665")
|
55
|
+
expect(answer).to eql("lov")
|
56
|
+
expect(prompt.output.string).to eq([
|
57
|
+
"What is your password? ",
|
58
|
+
"\e[1000D\e[K",
|
59
|
+
"What is your password? ♥",
|
60
|
+
"\e[1000D\e[K",
|
61
|
+
"What is your password? ♥♥",
|
62
|
+
"\e[1000D\e[K",
|
63
|
+
"What is your password? ♥♥♥",
|
64
|
+
"\e[1000D\e[K",
|
65
|
+
"What is your password? \e[32m♥♥♥\e[0m\n",
|
66
|
+
"\e[1000D\e[K\e[1A\e[1000D\e[K",
|
67
|
+
"What is your password? \e[32m♥♥♥\e[0m\n",
|
68
|
+
].join)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'ignores mask if echo is off' do
|
72
|
+
prompt.input << "pass\n"
|
73
|
+
prompt.input.rewind
|
74
|
+
answer = prompt.mask('What is your password?') do |q|
|
75
|
+
q.echo false
|
76
|
+
q.mask '*'
|
77
|
+
end
|
78
|
+
expect(answer).to eql("pass")
|
79
|
+
expect(prompt.output.string).to eq([
|
80
|
+
"What is your password? ",
|
81
|
+
"\e[1000D\e[K",
|
82
|
+
"What is your password? ",
|
83
|
+
"\e[1000D\e[K",
|
84
|
+
"What is your password? ",
|
85
|
+
"\e[1000D\e[K",
|
86
|
+
"What is your password? ",
|
87
|
+
"\e[1000D\e[K",
|
88
|
+
"What is your password? ",
|
89
|
+
"\e[1000D\e[K",
|
90
|
+
"What is your password? \n",
|
91
|
+
"\e[1000D\e[K",
|
92
|
+
"What is your password? \n",
|
93
|
+
].join)
|
94
|
+
end
|
95
|
+
end
|