tty-prompt 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/CHANGELOG.md +12 -0
- data/README.md +3 -3
- data/appveyor.yml +2 -0
- data/lib/tty/prompt/keypress.rb +7 -4
- data/lib/tty/prompt/reader.rb +1 -1
- data/lib/tty/prompt/reader/win_api.rb +14 -0
- data/lib/tty/prompt/reader/win_console.rb +9 -2
- data/lib/tty/prompt/timeout.rb +44 -23
- data/lib/tty/prompt/version.rb +1 -1
- data/tty-prompt.gemspec +6 -3
- metadata +21 -131
- data/spec/spec_helper.rb +0 -45
- data/spec/unit/ask_spec.rb +0 -132
- data/spec/unit/choice/eql_spec.rb +0 -22
- data/spec/unit/choice/from_spec.rb +0 -29
- data/spec/unit/choices/add_spec.rb +0 -12
- data/spec/unit/choices/each_spec.rb +0 -13
- data/spec/unit/choices/find_by_spec.rb +0 -10
- data/spec/unit/choices/new_spec.rb +0 -10
- data/spec/unit/choices/pluck_spec.rb +0 -9
- data/spec/unit/collect_spec.rb +0 -33
- data/spec/unit/converters/convert_bool_spec.rb +0 -58
- data/spec/unit/converters/convert_char_spec.rb +0 -11
- data/spec/unit/converters/convert_custom_spec.rb +0 -14
- data/spec/unit/converters/convert_date_spec.rb +0 -34
- data/spec/unit/converters/convert_file_spec.rb +0 -17
- data/spec/unit/converters/convert_number_spec.rb +0 -39
- data/spec/unit/converters/convert_path_spec.rb +0 -18
- data/spec/unit/converters/convert_range_spec.rb +0 -22
- data/spec/unit/converters/convert_regex_spec.rb +0 -12
- data/spec/unit/converters/convert_string_spec.rb +0 -21
- data/spec/unit/converters/on_error_spec.rb +0 -9
- data/spec/unit/distance/distance_spec.rb +0 -73
- data/spec/unit/enum_paginator_spec.rb +0 -65
- data/spec/unit/enum_select_spec.rb +0 -310
- data/spec/unit/error_spec.rb +0 -20
- data/spec/unit/evaluator_spec.rb +0 -67
- data/spec/unit/expand_spec.rb +0 -198
- data/spec/unit/keypress_spec.rb +0 -58
- data/spec/unit/mask_spec.rb +0 -132
- data/spec/unit/multi_select_spec.rb +0 -319
- data/spec/unit/multiline_spec.rb +0 -77
- data/spec/unit/new_spec.rb +0 -20
- data/spec/unit/ok_spec.rb +0 -10
- data/spec/unit/paginator_spec.rb +0 -63
- data/spec/unit/question/checks_spec.rb +0 -97
- data/spec/unit/question/default_spec.rb +0 -31
- data/spec/unit/question/echo_spec.rb +0 -38
- data/spec/unit/question/in_spec.rb +0 -115
- data/spec/unit/question/initialize_spec.rb +0 -12
- data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
- data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
- data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
- data/spec/unit/question/modify_spec.rb +0 -41
- data/spec/unit/question/required_spec.rb +0 -92
- data/spec/unit/question/validate_spec.rb +0 -115
- data/spec/unit/question/validation/call_spec.rb +0 -31
- data/spec/unit/question/validation/coerce_spec.rb +0 -30
- data/spec/unit/reader/history_spec.rb +0 -172
- data/spec/unit/reader/key_event_spec.rb +0 -86
- data/spec/unit/reader/line_spec.rb +0 -110
- data/spec/unit/reader/publish_keypress_event_spec.rb +0 -94
- data/spec/unit/reader/read_keypress_spec.rb +0 -80
- data/spec/unit/reader/read_line_spec.rb +0 -68
- data/spec/unit/reader/read_multiline_spec.rb +0 -60
- data/spec/unit/result_spec.rb +0 -40
- data/spec/unit/say_spec.rb +0 -67
- data/spec/unit/select_spec.rb +0 -359
- data/spec/unit/slider_spec.rb +0 -96
- data/spec/unit/statement/initialize_spec.rb +0 -15
- data/spec/unit/suggest_spec.rb +0 -28
- data/spec/unit/warn_spec.rb +0 -21
- data/spec/unit/yes_no_spec.rb +0 -235
@@ -1,17 +0,0 @@
|
|
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
|
-
prompt = TTY::TestPrompt.new
|
7
|
-
prompt.input << "test.txt"
|
8
|
-
prompt.input.rewind
|
9
|
-
|
10
|
-
allow(::File).to receive(:open).with(/test\.txt/).and_return(file)
|
11
|
-
expect(::File).to receive(:open).with(/test\.txt/)
|
12
|
-
|
13
|
-
answer = prompt.ask("Which file to open?", convert: :file)
|
14
|
-
|
15
|
-
expect(answer).to eq(file)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt::Question, 'convert numbers' do
|
4
|
-
|
5
|
-
subject(:prompt) { TTY::TestPrompt.new }
|
6
|
-
|
7
|
-
it 'fails to convert integer' do
|
8
|
-
prompt.input << 'invalid'
|
9
|
-
prompt.input.rewind
|
10
|
-
expect {
|
11
|
-
prompt.ask("What temparture?", convert: :int)
|
12
|
-
}.to raise_error(TTY::Prompt::ConversionError)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'converts integer' do
|
16
|
-
prompt.input << 35
|
17
|
-
prompt.input.rewind
|
18
|
-
answer = prompt.ask("What temperature?", convert: :int)
|
19
|
-
expect(answer).to be_a(Integer)
|
20
|
-
expect(answer).to eq(35)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'fails to convert float' do
|
24
|
-
prompt.input << 'invalid'
|
25
|
-
prompt.input.rewind
|
26
|
-
expect {
|
27
|
-
prompt.ask("How tall are you?", convert: :float)
|
28
|
-
}.to raise_error(TTY::Prompt::ConversionError)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'converts float' do
|
32
|
-
number = 6.666
|
33
|
-
prompt.input << number
|
34
|
-
prompt.input.rewind
|
35
|
-
answer = prompt.ask('How tall are you?', convert: :float)
|
36
|
-
expect(answer).to be_a(Float)
|
37
|
-
expect(answer).to eq(number)
|
38
|
-
end
|
39
|
-
end
|
@@ -1,18 +0,0 @@
|
|
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
|
-
prompt.input << "/path/to/file"
|
9
|
-
prompt.input.rewind
|
10
|
-
|
11
|
-
allow(Pathname).to receive(:new).and_return(path)
|
12
|
-
expect(Pathname).to receive(:new).with(/path\/to\/file/)
|
13
|
-
|
14
|
-
answer = prompt.ask('File location?', convert: :path)
|
15
|
-
|
16
|
-
expect(answer).to eql(path)
|
17
|
-
end
|
18
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt::Question, 'convert range' do
|
4
|
-
|
5
|
-
subject(:prompt) { TTY::TestPrompt.new}
|
6
|
-
|
7
|
-
it 'converts with valid range' do
|
8
|
-
prompt.input << "20-30"
|
9
|
-
prompt.input.rewind
|
10
|
-
answer = prompt.ask("Which age group?", convert: :range)
|
11
|
-
expect(answer).to be_a(Range)
|
12
|
-
expect(answer).to eq(20..30)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "fails to convert to range" do
|
16
|
-
prompt.input << "abcd"
|
17
|
-
prompt.input.rewind
|
18
|
-
expect {
|
19
|
-
prompt.ask('Which age group?', convert: :range)
|
20
|
-
}.to raise_error(TTY::Prompt::ConversionError)
|
21
|
-
end
|
22
|
-
end
|
@@ -1,12 +0,0 @@
|
|
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
|
@@ -1,21 +0,0 @@
|
|
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
|
@@ -1,73 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt::Distance, '.distance' do
|
4
|
-
let(:object) { described_class.new }
|
5
|
-
|
6
|
-
subject(:distance) { object.distance(*strings) }
|
7
|
-
|
8
|
-
context 'when nil' do
|
9
|
-
let(:strings) { [nil, nil] }
|
10
|
-
|
11
|
-
it { is_expected.to eql(0) }
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'when empty' do
|
15
|
-
let(:strings) { ['', ''] }
|
16
|
-
|
17
|
-
it { is_expected.to eql(0) }
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with one non empty' do
|
21
|
-
let(:strings) { ['abc', ''] }
|
22
|
-
|
23
|
-
it { is_expected.to eql(3) }
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when single char' do
|
27
|
-
let(:strings) { ['a', 'abc'] }
|
28
|
-
|
29
|
-
it { is_expected.to eql(2) }
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when similar' do
|
33
|
-
let(:strings) { ['abc', 'abc'] }
|
34
|
-
|
35
|
-
it { is_expected.to eql(0) }
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when similar' do
|
39
|
-
let(:strings) { ['abc', 'acb'] }
|
40
|
-
|
41
|
-
it { is_expected.to eql(1) }
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when end similar' do
|
45
|
-
let(:strings) { ['saturday', 'sunday'] }
|
46
|
-
|
47
|
-
it { is_expected.to eql(3) }
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when contain similar' do
|
51
|
-
let(:strings) { ['which', 'witch'] }
|
52
|
-
|
53
|
-
it { is_expected.to eql(2) }
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'when prefix' do
|
57
|
-
let(:strings) { ['sta', 'status'] }
|
58
|
-
|
59
|
-
it { is_expected.to eql(3) }
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'when similar' do
|
63
|
-
let(:strings) { ['smellyfish','jellyfish'] }
|
64
|
-
|
65
|
-
it { is_expected.to eql(2) }
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'when unicode' do
|
69
|
-
let(:strings) { ['マラソン五輪代表', 'ララソン五輪代表'] }
|
70
|
-
|
71
|
-
it { is_expected.to eql(1) }
|
72
|
-
end
|
73
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt::EnumPaginator, '#paginate' do
|
4
|
-
it "ignores per_page when equal items " do
|
5
|
-
list = %w(a b c d)
|
6
|
-
paginator = described_class.new({per_page: 4})
|
7
|
-
|
8
|
-
expect(paginator.paginate(list, 1).to_a).to eq([
|
9
|
-
['a',0],['b',1],['c',2],['d',3]])
|
10
|
-
end
|
11
|
-
|
12
|
-
it "ignores per_page when less items " do
|
13
|
-
list = %w(a b c d)
|
14
|
-
paginator = described_class.new({per_page: 5})
|
15
|
-
|
16
|
-
expect(paginator.paginate(list, 1).to_a).to eq([
|
17
|
-
['a',0],['b',1],['c',2],['d',3]])
|
18
|
-
end
|
19
|
-
|
20
|
-
it "paginates items matching per_page count" do
|
21
|
-
list = %w(a b c d e f)
|
22
|
-
paginator = described_class.new({per_page: 3})
|
23
|
-
|
24
|
-
expect(paginator.paginate(list, 1).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
25
|
-
expect(paginator.paginate(list, 2).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
26
|
-
expect(paginator.paginate(list, 3).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
27
|
-
expect(paginator.paginate(list, 4).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
28
|
-
expect(paginator.paginate(list, 5).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
29
|
-
expect(paginator.paginate(list, 6).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
30
|
-
expect(paginator.paginate(list, 7).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
31
|
-
end
|
32
|
-
|
33
|
-
it "paginates items not matching per_page count" do
|
34
|
-
list = %w(a b c d e f g)
|
35
|
-
paginator = described_class.new({per_page: 3})
|
36
|
-
|
37
|
-
expect(paginator.paginate(list, 1).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
38
|
-
expect(paginator.paginate(list, 2).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
39
|
-
expect(paginator.paginate(list, 3).to_a).to eq([['a',0], ['b',1], ['c',2]])
|
40
|
-
expect(paginator.paginate(list, 4).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
41
|
-
expect(paginator.paginate(list, 5).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
42
|
-
expect(paginator.paginate(list, 6).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
43
|
-
expect(paginator.paginate(list, 7).to_a).to eq([['g',6]])
|
44
|
-
expect(paginator.paginate(list, 8).to_a).to eq([['g',6]])
|
45
|
-
end
|
46
|
-
|
47
|
-
it "finds maximum index for current selection" do
|
48
|
-
list = %w(a b c d e f g)
|
49
|
-
paginator = described_class.new({per_page: 3, default: 0})
|
50
|
-
|
51
|
-
paginator.paginate(list, 4)
|
52
|
-
expect(paginator.max_index).to eq(5)
|
53
|
-
paginator.paginate(list, 5)
|
54
|
-
expect(paginator.max_index).to eq(5)
|
55
|
-
paginator.paginate(list, 7)
|
56
|
-
expect(paginator.max_index).to eq(8)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "starts with default selection" do
|
60
|
-
list = %w(a b c d e f g)
|
61
|
-
paginator = described_class.new({per_page: 3, default: 3})
|
62
|
-
|
63
|
-
expect(paginator.paginate(list, 4).to_a).to eq([['d',3], ['e',4], ['f',5]])
|
64
|
-
end
|
65
|
-
end
|
@@ -1,310 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Prompt do
|
4
|
-
it "selects default option when return pressed immediately" do
|
5
|
-
prompt = TTY::TestPrompt.new
|
6
|
-
choices = %w(/bin/nano /usr/bin/vim.basic /usr/bin/vim.tiny)
|
7
|
-
prompt.input << "\n"
|
8
|
-
prompt.input.rewind
|
9
|
-
|
10
|
-
expect(prompt.enum_select("Select an editor?", choices)).to eq('/bin/nano')
|
11
|
-
expect(prompt.output.string).to eq([
|
12
|
-
"Select an editor? \n",
|
13
|
-
"\e[32m 1) /bin/nano\e[0m\n",
|
14
|
-
" 2) /usr/bin/vim.basic\n",
|
15
|
-
" 3) /usr/bin/vim.tiny\n",
|
16
|
-
" Choose 1-3 [1]: ",
|
17
|
-
"\e[2K\e[1G\e[1A" * 4,
|
18
|
-
"\e[2K\e[1G\e[J",
|
19
|
-
"Select an editor? \e[32m/bin/nano\e[0m\n"
|
20
|
-
].join)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "selects option by index from the list" do
|
24
|
-
prompt = TTY::TestPrompt.new
|
25
|
-
choices = %w(/bin/nano /usr/bin/vim.basic /usr/bin/vim.tiny)
|
26
|
-
prompt.input << "3\n"
|
27
|
-
prompt.input.rewind
|
28
|
-
|
29
|
-
expect(prompt.enum_select("Select an editor?", choices, default: 2)).to eq('/usr/bin/vim.tiny')
|
30
|
-
expect(prompt.output.string).to eq([
|
31
|
-
"Select an editor? \n",
|
32
|
-
" 1) /bin/nano\n",
|
33
|
-
"\e[32m 2) /usr/bin/vim.basic\e[0m\n",
|
34
|
-
" 3) /usr/bin/vim.tiny\n",
|
35
|
-
" Choose 1-3 [2]: ",
|
36
|
-
"\e[2K\e[1G\e[1A" * 4,
|
37
|
-
"\e[2K\e[1G\e[J",
|
38
|
-
"Select an editor? \n",
|
39
|
-
" 1) /bin/nano\n",
|
40
|
-
" 2) /usr/bin/vim.basic\n",
|
41
|
-
"\e[32m 3) /usr/bin/vim.tiny\e[0m\n",
|
42
|
-
" Choose 1-3 [2]: 3",
|
43
|
-
"\e[2K\e[1G\e[1A" * 4,
|
44
|
-
"\e[2K\e[1G\e[J",
|
45
|
-
"Select an editor? \e[32m/usr/bin/vim.tiny\e[0m\n"
|
46
|
-
].join)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "selects option through DSL" do
|
50
|
-
prompt = TTY::TestPrompt.new
|
51
|
-
prompt.input << "1\n"
|
52
|
-
prompt.input.rewind
|
53
|
-
value = prompt.enum_select("Select an editor?") do |menu|
|
54
|
-
menu.default 2
|
55
|
-
menu.enum '.'
|
56
|
-
|
57
|
-
menu.choice "/bin/nano"
|
58
|
-
menu.choice "/usr/bin/vim.basic"
|
59
|
-
menu.choice "/usr/bin/vim.tiny"
|
60
|
-
end
|
61
|
-
|
62
|
-
expect(value).to eq('/bin/nano')
|
63
|
-
expect(prompt.output.string).to eq([
|
64
|
-
"Select an editor? \n",
|
65
|
-
" 1. /bin/nano\n",
|
66
|
-
"\e[32m 2. /usr/bin/vim.basic\e[0m\n",
|
67
|
-
" 3. /usr/bin/vim.tiny\n",
|
68
|
-
" Choose 1-3 [2]: ",
|
69
|
-
"\e[2K\e[1G\e[1A" * 4,
|
70
|
-
"\e[2K\e[1G\e[J",
|
71
|
-
"Select an editor? \n",
|
72
|
-
"\e[32m 1. /bin/nano\e[0m\n",
|
73
|
-
" 2. /usr/bin/vim.basic\n",
|
74
|
-
" 3. /usr/bin/vim.tiny\n",
|
75
|
-
" Choose 1-3 [2]: 1",
|
76
|
-
"\e[2K\e[1G\e[1A" * 4,
|
77
|
-
"\e[2K\e[1G\e[J",
|
78
|
-
"Select an editor? \e[32m/bin/nano\e[0m\n"
|
79
|
-
].join)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "selects option through DSL with key and value" do
|
83
|
-
prompt = TTY::TestPrompt.new
|
84
|
-
prompt.input << "\n"
|
85
|
-
prompt.input.rewind
|
86
|
-
value = prompt.enum_select("Select an editor?") do |menu|
|
87
|
-
menu.default 2
|
88
|
-
|
89
|
-
menu.choice :nano, '/bin/nano'
|
90
|
-
menu.choice :vim, '/usr/bin/vim'
|
91
|
-
menu.choice :emacs, '/usr/bin/emacs'
|
92
|
-
end
|
93
|
-
|
94
|
-
expect(value).to eq('/usr/bin/vim')
|
95
|
-
expect(prompt.output.string).to eq([
|
96
|
-
"Select an editor? \n",
|
97
|
-
" 1) nano\n",
|
98
|
-
"\e[32m 2) vim\e[0m\n",
|
99
|
-
" 3) emacs\n",
|
100
|
-
" Choose 1-3 [2]: ",
|
101
|
-
"\e[2K\e[1G\e[1A" * 4,
|
102
|
-
"\e[2K\e[1G\e[J",
|
103
|
-
"Select an editor? \e[32mvim\e[0m\n"
|
104
|
-
].join)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "changes colors for selection, hint and error" do
|
108
|
-
prompt = TTY::TestPrompt.new
|
109
|
-
choices = %w(/bin/nano /usr/bin/vim.basic /usr/bin/vim.tiny)
|
110
|
-
prompt.input << "\n"
|
111
|
-
prompt.input.rewind
|
112
|
-
options = {active_color: :red, help_color: :blue, error_color: :green}
|
113
|
-
expect(prompt.enum_select("Select an editor?", choices, options)).to eq('/bin/nano')
|
114
|
-
expect(prompt.output.string).to eq([
|
115
|
-
"Select an editor? \n",
|
116
|
-
"\e[31m 1) /bin/nano\e[0m\n",
|
117
|
-
" 2) /usr/bin/vim.basic\n",
|
118
|
-
" 3) /usr/bin/vim.tiny\n",
|
119
|
-
" Choose 1-3 [1]: ",
|
120
|
-
"\e[2K\e[1G\e[1A" * 4,
|
121
|
-
"\e[2K\e[1G\e[J",
|
122
|
-
"Select an editor? \e[31m/bin/nano\e[0m\n"
|
123
|
-
].join)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "displays error with unrecognized input" do
|
127
|
-
prompt = TTY::TestPrompt.new
|
128
|
-
choices = %w(/bin/nano /usr/bin/vim.basic /usr/bin/vim.tiny)
|
129
|
-
prompt.input << "11\n2\n"
|
130
|
-
prompt.input.rewind
|
131
|
-
value = prompt.enum_select("Select an editor?", choices)
|
132
|
-
expect(value).to eq('/usr/bin/vim.basic')
|
133
|
-
expect(prompt.output.string).to eq([
|
134
|
-
"Select an editor? \n",
|
135
|
-
"\e[32m 1) /bin/nano\e[0m\n",
|
136
|
-
" 2) /usr/bin/vim.basic\n",
|
137
|
-
" 3) /usr/bin/vim.tiny\n",
|
138
|
-
" Choose 1-3 [1]: ",
|
139
|
-
"\e[2K\e[1G\e[1A" * 4,
|
140
|
-
"\e[2K\e[1G\e[J",
|
141
|
-
"Select an editor? \n",
|
142
|
-
"\e[32m 1) /bin/nano\e[0m\n",
|
143
|
-
" 2) /usr/bin/vim.basic\n",
|
144
|
-
" 3) /usr/bin/vim.tiny\n",
|
145
|
-
" Choose 1-3 [1]: 1",
|
146
|
-
"\e[2K\e[1G\e[1A" * 4,
|
147
|
-
"\e[2K\e[1G\e[J",
|
148
|
-
"Select an editor? \n",
|
149
|
-
"\e[32m 1) /bin/nano\e[0m\n",
|
150
|
-
" 2) /usr/bin/vim.basic\n",
|
151
|
-
" 3) /usr/bin/vim.tiny\n",
|
152
|
-
" Choose 1-3 [1]: 11",
|
153
|
-
"\e[2K\e[1G\e[1A" * 4,
|
154
|
-
"\e[2K\e[1G\e[J",
|
155
|
-
"Select an editor? \n",
|
156
|
-
"\e[32m 1) /bin/nano\e[0m\n",
|
157
|
-
" 2) /usr/bin/vim.basic\n",
|
158
|
-
" 3) /usr/bin/vim.tiny\n",
|
159
|
-
" Choose 1-3 [1]: \n",
|
160
|
-
"\e[31m>>\e[0m Please enter a valid number",
|
161
|
-
"\e[A\e[1G\e[18C",
|
162
|
-
"\e[2K\e[1G\e[1A" * 4,
|
163
|
-
"\e[2K\e[1G\e[J",
|
164
|
-
"Select an editor? \n",
|
165
|
-
" 1) /bin/nano\n",
|
166
|
-
"\e[32m 2) /usr/bin/vim.basic\e[0m\n",
|
167
|
-
" 3) /usr/bin/vim.tiny\n",
|
168
|
-
" Choose 1-3 [1]: 2\n",
|
169
|
-
"\e[31m>>\e[0m Please enter a valid number",
|
170
|
-
"\e[A\e[1G\e[19C",
|
171
|
-
"\e[2K\e[1G\e[1A" * 4,
|
172
|
-
"\e[2K\e[1G\e[J",
|
173
|
-
"Select an editor? \e[32m/usr/bin/vim.basic\e[0m\n"
|
174
|
-
].join)
|
175
|
-
end
|
176
|
-
|
177
|
-
it "paginates long selections" do
|
178
|
-
prompt = TTY::TestPrompt.new
|
179
|
-
choices = %w(A B C D E F G H)
|
180
|
-
prompt.input << "\n"
|
181
|
-
prompt.input.rewind
|
182
|
-
value = prompt.enum_select("What letter?", choices, per_page: 3, default: 4)
|
183
|
-
expect(value).to eq('D')
|
184
|
-
expect(prompt.output.string).to eq([
|
185
|
-
"What letter? \n",
|
186
|
-
"\e[32m 4) D\e[0m\n",
|
187
|
-
" 5) E\n",
|
188
|
-
" 6) F\n",
|
189
|
-
" Choose 1-8 [4]: ",
|
190
|
-
"\n\e[90m(Press tab/right or left to reveal more choices)\e[0m",
|
191
|
-
"\e[A\e[1G\e[18C",
|
192
|
-
"\e[2K\e[1G\e[1A" * 4,
|
193
|
-
"\e[2K\e[1G\e[J",
|
194
|
-
"What letter? \e[32mD\e[0m\n"
|
195
|
-
].join)
|
196
|
-
end
|
197
|
-
|
198
|
-
it "doesn't paginate short selections" do
|
199
|
-
prompt = TTY::TestPrompt.new
|
200
|
-
choices = %w(A B C D)
|
201
|
-
prompt.input << "\r"
|
202
|
-
prompt.input.rewind
|
203
|
-
value = prompt.enum_select("What letter?", choices, per_page: 4, default: 1)
|
204
|
-
expect(value).to eq('A')
|
205
|
-
|
206
|
-
expect(prompt.output.string).to eq([
|
207
|
-
"What letter? \n",
|
208
|
-
"\e[32m 1) A\e[0m\n",
|
209
|
-
" 2) B\n",
|
210
|
-
" 3) C\n",
|
211
|
-
" 4) D\n",
|
212
|
-
" Choose 1-4 [1]: ",
|
213
|
-
"\e[2K\e[1G\e[1A" * 5,
|
214
|
-
"\e[2K\e[1G\e[J",
|
215
|
-
"What letter? \e[32mA\e[0m\n"
|
216
|
-
].join)
|
217
|
-
end
|
218
|
-
|
219
|
-
it "shows pages matching input" do
|
220
|
-
prompt = TTY::TestPrompt.new
|
221
|
-
choices = %w(A B C D E F G H)
|
222
|
-
prompt.input << "11\n\b\n"
|
223
|
-
prompt.input.rewind
|
224
|
-
value = prompt.enum_select("What letter?", choices, per_page: 3)
|
225
|
-
expect(value).to eq('A')
|
226
|
-
expect(prompt.output.string).to eq([
|
227
|
-
"What letter? \n",
|
228
|
-
"\e[32m 1) A\e[0m\n",
|
229
|
-
" 2) B\n",
|
230
|
-
" 3) C\n",
|
231
|
-
" Choose 1-8 [1]: ",
|
232
|
-
"\n\e[90m(Press tab/right or left to reveal more choices)\e[0m",
|
233
|
-
"\e[A\e[1G\e[18C",
|
234
|
-
"\e[2K\e[1G\e[1A" * 4,
|
235
|
-
"\e[2K\e[1G\e[J",
|
236
|
-
"What letter? \n",
|
237
|
-
"\e[32m 1) A\e[0m\n",
|
238
|
-
" 2) B\n",
|
239
|
-
" 3) C\n",
|
240
|
-
" Choose 1-8 [1]: 1",
|
241
|
-
"\n\e[90m(Press tab/right or left to reveal more choices)\e[0m",
|
242
|
-
"\e[A\e[1G\e[19C",
|
243
|
-
"\e[2K\e[1G\e[1A" * 4,
|
244
|
-
"\e[2K\e[1G\e[J",
|
245
|
-
"What letter? \n",
|
246
|
-
"\e[32m 1) A\e[0m\n",
|
247
|
-
" 2) B\n",
|
248
|
-
" 3) C\n",
|
249
|
-
" Choose 1-8 [1]: 11",
|
250
|
-
"\n\e[90m(Press tab/right or left to reveal more choices)\e[0m",
|
251
|
-
"\e[A\e[1G\e[20C",
|
252
|
-
"\e[2K\e[1G\e[1A" * 4,
|
253
|
-
"\e[2K\e[1G\e[J",
|
254
|
-
"What letter? \n",
|
255
|
-
"\e[32m 1) A\e[0m\n",
|
256
|
-
" 2) B\n",
|
257
|
-
" 3) C\n",
|
258
|
-
" Choose 1-8 [1]: \n",
|
259
|
-
"\e[31m>>\e[0m Please enter a valid number",
|
260
|
-
"\n\e[90m(Press tab/right or left to reveal more choices)\e[0m",
|
261
|
-
"\e[A\e[1G\e[A\e[1G\e[18C",
|
262
|
-
"\e[2K\e[1G\e[1A" * 4,
|
263
|
-
"\e[2K\e[1G\e[J",
|
264
|
-
"What letter? \n",
|
265
|
-
"\e[32m 1) A\e[0m\n",
|
266
|
-
" 2) B\n",
|
267
|
-
" 3) C\n",
|
268
|
-
" Choose 1-8 [1]: \n",
|
269
|
-
"\e[31m>>\e[0m Please enter a valid number",
|
270
|
-
"\n\e[90m(Press tab/right or left to reveal more choices)\e[0m",
|
271
|
-
"\e[A\e[1G\e[A\e[1G\e[18C",
|
272
|
-
"\e[2K\e[1G\e[1A" * 4,
|
273
|
-
"\e[2K\e[1G\e[J",
|
274
|
-
"What letter? \e[32mA\e[0m\n"
|
275
|
-
].join)
|
276
|
-
end
|
277
|
-
|
278
|
-
it "switches through pages with tab key" do
|
279
|
-
prompt = TTY::TestPrompt.new
|
280
|
-
choices = %w(A B C D E F G H)
|
281
|
-
prompt.input << "\t\n"
|
282
|
-
prompt.input.rewind
|
283
|
-
value = prompt.enum_select("What letter?") do |menu|
|
284
|
-
menu.default 4
|
285
|
-
menu.per_page 3
|
286
|
-
menu.choices choices
|
287
|
-
end
|
288
|
-
expect(value).to eq('D')
|
289
|
-
expect(prompt.output.string).to eq([
|
290
|
-
"What letter? \n",
|
291
|
-
"\e[32m 4) D\e[0m\n",
|
292
|
-
" 5) E\n",
|
293
|
-
" 6) F\n",
|
294
|
-
" Choose 1-8 [4]: ",
|
295
|
-
"\n\e[90m(Press tab/right or left to reveal more choices)\e[0m",
|
296
|
-
"\e[A\e[1G\e[18C",
|
297
|
-
"\e[2K\e[1G\e[1A" * 4,
|
298
|
-
"\e[2K\e[1G\e[J",
|
299
|
-
"What letter? \n",
|
300
|
-
" 7) G\n",
|
301
|
-
" 8) H\n",
|
302
|
-
" Choose 1-8 [4]: ",
|
303
|
-
"\n\e[90m(Press tab/right or left to reveal more choices)\e[0m",
|
304
|
-
"\e[A\e[1G\e[18C",
|
305
|
-
"\e[2K\e[1G\e[1A" * 3,
|
306
|
-
"\e[2K\e[1G\e[J",
|
307
|
-
"What letter? \e[32mD\e[0m\n"
|
308
|
-
].join)
|
309
|
-
end
|
310
|
-
end
|