tty-prompt 0.10.1 → 0.11.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 -1
- data/CHANGELOG.md +30 -0
- data/README.md +39 -9
- data/examples/echo.rb +5 -1
- data/examples/inputs.rb +10 -0
- data/examples/mask.rb +6 -2
- data/examples/multi_select.rb +1 -1
- data/examples/multi_select_paged.rb +9 -0
- data/examples/select.rb +5 -5
- data/examples/slider.rb +1 -1
- data/lib/tty-prompt.rb +2 -36
- data/lib/tty/prompt.rb +49 -8
- data/lib/tty/prompt/choices.rb +2 -0
- data/lib/tty/prompt/confirm_question.rb +6 -1
- data/lib/tty/prompt/converter_dsl.rb +9 -6
- data/lib/tty/prompt/converter_registry.rb +27 -19
- data/lib/tty/prompt/converters.rb +16 -22
- data/lib/tty/prompt/enum_list.rb +8 -4
- data/lib/tty/prompt/enum_paginator.rb +2 -0
- data/lib/tty/prompt/evaluator.rb +1 -1
- data/lib/tty/prompt/expander.rb +1 -1
- data/lib/tty/prompt/list.rb +21 -11
- data/lib/tty/prompt/mask_question.rb +15 -6
- data/lib/tty/prompt/multi_list.rb +12 -10
- data/lib/tty/prompt/question.rb +38 -36
- data/lib/tty/prompt/question/modifier.rb +2 -0
- data/lib/tty/prompt/question/validation.rb +5 -4
- data/lib/tty/prompt/reader.rb +104 -58
- data/lib/tty/prompt/reader/codes.rb +103 -63
- data/lib/tty/prompt/reader/console.rb +57 -0
- data/lib/tty/prompt/reader/key_event.rb +51 -88
- data/lib/tty/prompt/reader/mode.rb +5 -5
- data/lib/tty/prompt/reader/win_api.rb +29 -0
- data/lib/tty/prompt/reader/win_console.rb +49 -0
- data/lib/tty/prompt/slider.rb +10 -6
- data/lib/tty/prompt/suggestion.rb +1 -1
- data/lib/tty/prompt/symbols.rb +52 -10
- data/lib/tty/prompt/version.rb +1 -1
- data/lib/tty/{prompt/test.rb → test_prompt.rb} +2 -1
- data/spec/unit/ask_spec.rb +8 -16
- data/spec/unit/converters/convert_bool_spec.rb +1 -2
- data/spec/unit/converters/on_error_spec.rb +9 -0
- data/spec/unit/enum_paginator_spec.rb +16 -0
- data/spec/unit/enum_select_spec.rb +69 -25
- data/spec/unit/expand_spec.rb +14 -14
- data/spec/unit/mask_spec.rb +66 -29
- data/spec/unit/multi_select_spec.rb +120 -74
- data/spec/unit/new_spec.rb +5 -3
- data/spec/unit/paginator_spec.rb +16 -0
- data/spec/unit/question/default_spec.rb +2 -4
- data/spec/unit/question/echo_spec.rb +2 -3
- data/spec/unit/question/in_spec.rb +9 -14
- data/spec/unit/question/modifier/letter_case_spec.rb +32 -11
- data/spec/unit/question/modifier/whitespace_spec.rb +41 -15
- data/spec/unit/question/required_spec.rb +9 -13
- data/spec/unit/question/validate_spec.rb +7 -10
- data/spec/unit/reader/key_event_spec.rb +36 -50
- data/spec/unit/reader/publish_keypress_event_spec.rb +5 -3
- data/spec/unit/reader/read_keypress_spec.rb +8 -7
- data/spec/unit/reader/read_line_spec.rb +9 -9
- data/spec/unit/reader/read_multiline_spec.rb +8 -7
- data/spec/unit/select_spec.rb +85 -25
- data/spec/unit/slider_spec.rb +43 -16
- data/spec/unit/yes_no_spec.rb +14 -28
- data/tasks/console.rake +1 -0
- data/tty-prompt.gemspec +2 -2
- metadata +14 -7
@@ -12,8 +12,7 @@ RSpec.describe TTY::Prompt::Question, '#default' do
|
|
12
12
|
expect(answer).to eq(name)
|
13
13
|
expect(prompt.output.string).to eq([
|
14
14
|
"What is your name? \e[90m(Anonymous)\e[0m ",
|
15
|
-
"\e[
|
16
|
-
"\e[1000D\e[K",
|
15
|
+
"\e[1A\e[2K\e[1G",
|
17
16
|
"What is your name? \e[32mAnonymous\e[0m\n"
|
18
17
|
].join)
|
19
18
|
end
|
@@ -24,8 +23,7 @@ RSpec.describe TTY::Prompt::Question, '#default' do
|
|
24
23
|
expect(answer).to eq(name)
|
25
24
|
expect(prompt.output.string).to eq([
|
26
25
|
"What is your name? \e[90m(Anonymous)\e[0m ",
|
27
|
-
"\e[
|
28
|
-
"\e[1000D\e[K",
|
26
|
+
"\e[1A\e[2K\e[1G",
|
29
27
|
"What is your name? \e[32mAnonymous\e[0m\n"
|
30
28
|
].join)
|
31
29
|
end
|
@@ -11,8 +11,7 @@ RSpec.describe TTY::Prompt::Question, '#echo' do
|
|
11
11
|
expect(answer).to eql("password")
|
12
12
|
expect(prompt.output.string).to eq([
|
13
13
|
"What is your password? ",
|
14
|
-
"\e[
|
15
|
-
"\e[1000D\e[K",
|
14
|
+
"\e[1A\e[2K\e[1G",
|
16
15
|
"What is your password? \e[32mpassword\e[0m\n"
|
17
16
|
].join)
|
18
17
|
end
|
@@ -24,7 +23,7 @@ RSpec.describe TTY::Prompt::Question, '#echo' do
|
|
24
23
|
expect(answer).to eql("password")
|
25
24
|
expect(prompt.output.string).to eq([
|
26
25
|
"What is your password? ",
|
27
|
-
"\e[
|
26
|
+
"\e[2K\e[1G",
|
28
27
|
"What is your password? \n"
|
29
28
|
].join)
|
30
29
|
end
|
@@ -24,8 +24,7 @@ RSpec.describe TTY::Prompt::Question, '#in' do
|
|
24
24
|
expect(answer).to eq('8')
|
25
25
|
expect(prompt.output.string).to eq([
|
26
26
|
"How do you like it on scale 1-10? ",
|
27
|
-
"\e[
|
28
|
-
"\e[1000D\e[K",
|
27
|
+
"\e[1A\e[2K\e[1G",
|
29
28
|
"How do you like it on scale 1-10? \e[32m8\e[0m\n",
|
30
29
|
].join)
|
31
30
|
end
|
@@ -41,8 +40,7 @@ RSpec.describe TTY::Prompt::Question, '#in' do
|
|
41
40
|
expect(answer).to eq('8.1')
|
42
41
|
expect(prompt.output.string).to eq([
|
43
42
|
"How do you like it on scale 1-10? ",
|
44
|
-
"\e[
|
45
|
-
"\e[1000D\e[K",
|
43
|
+
"\e[1A\e[2K\e[1G",
|
46
44
|
"How do you like it on scale 1-10? \e[32m8.1\e[0m\n",
|
47
45
|
].join)
|
48
46
|
end
|
@@ -58,8 +56,7 @@ RSpec.describe TTY::Prompt::Question, '#in' do
|
|
58
56
|
expect(answer).to eq('E')
|
59
57
|
expect(prompt.output.string).to eq([
|
60
58
|
"Your favourite vitamin? (A-K) ",
|
61
|
-
"\e[
|
62
|
-
"\e[1000D\e[K",
|
59
|
+
"\e[1A\e[2K\e[1G",
|
63
60
|
"Your favourite vitamin? (A-K) \e[32mE\e[0m\n"
|
64
61
|
].join)
|
65
62
|
end
|
@@ -73,12 +70,11 @@ RSpec.describe TTY::Prompt::Question, '#in' do
|
|
73
70
|
expect(answer).to eq('2')
|
74
71
|
expect(prompt.output.string).to eq([
|
75
72
|
"How spicy on scale? (1-5) ",
|
76
|
-
"\e[1000D\e[K",
|
77
73
|
"\e[31m>>\e[0m Value A must be within the range 1..5\e[1A",
|
78
|
-
"\e[
|
74
|
+
"\e[2K\e[1G",
|
79
75
|
"How spicy on scale? (1-5) ",
|
80
|
-
"\e[
|
81
|
-
"\e[
|
76
|
+
"\e[2K\e[1G",
|
77
|
+
"\e[1A\e[2K\e[1G",
|
82
78
|
"How spicy on scale? (1-5) \e[32m2\e[0m\n"
|
83
79
|
].join)
|
84
80
|
end
|
@@ -95,12 +91,11 @@ RSpec.describe TTY::Prompt::Question, '#in' do
|
|
95
91
|
expect(answer).to eq('2')
|
96
92
|
expect(prompt.output.string).to eq([
|
97
93
|
"How spicy on scale? (1-5) ",
|
98
|
-
"\e[1000D\e[K",
|
99
94
|
"\e[31m>>\e[0m Ohh dear what is this A doing in 1..5?\e[1A",
|
100
|
-
"\e[
|
95
|
+
"\e[2K\e[1G",
|
101
96
|
"How spicy on scale? (1-5) ",
|
102
|
-
"\e[
|
103
|
-
"\e[
|
97
|
+
"\e[2K\e[1G",
|
98
|
+
"\e[1A\e[2K\e[1G",
|
104
99
|
"How spicy on scale? (1-5) \e[32m2\e[0m\n"
|
105
100
|
].join)
|
106
101
|
end
|
@@ -1,20 +1,41 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
RSpec.describe TTY::Prompt::Question::Modifier, '#letter_case' do
|
4
|
-
|
4
|
+
context "string" do
|
5
|
+
let(:string) { 'text to modify' }
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
it "changes to uppercase" do
|
8
|
+
modified = described_class.letter_case(:up, string)
|
9
|
+
expect(modified).to eq('TEXT TO MODIFY')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "changes to lower case" do
|
13
|
+
modified = described_class.letter_case(:down, string)
|
14
|
+
expect(modified).to eq('text to modify')
|
15
|
+
end
|
10
16
|
|
11
|
-
|
12
|
-
|
13
|
-
|
17
|
+
it "capitalizes text" do
|
18
|
+
modified = described_class.letter_case(:capitalize, string)
|
19
|
+
expect(modified).to eq('Text to modify')
|
20
|
+
end
|
14
21
|
end
|
15
22
|
|
16
|
-
|
17
|
-
|
18
|
-
|
23
|
+
context "nil (empty user input)" do
|
24
|
+
let(:string) { nil }
|
25
|
+
|
26
|
+
example "up returns nil" do
|
27
|
+
modified = described_class.letter_case(:up, string)
|
28
|
+
expect(modified).to be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
example "down returns nil" do
|
32
|
+
modified = described_class.letter_case(:down, string)
|
33
|
+
expect(modified).to be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
example "capitalize returns nil" do
|
37
|
+
modified = described_class.letter_case(:capitalize, string)
|
38
|
+
expect(modified).to be_nil
|
39
|
+
end
|
19
40
|
end
|
20
41
|
end
|
@@ -1,25 +1,51 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
RSpec.describe TTY::Prompt::Question::Modifier, '#whitespace' do
|
4
|
-
|
4
|
+
context "string with whitespaces" do
|
5
|
+
let(:string) { " text\t \n to\t modify\r\n" }
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
it "trims whitespace" do
|
8
|
+
modified = described_class.whitespace(:trim, string)
|
9
|
+
expect(modified).to eq("text\t \n to\t modify")
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
it "chomps whitespace" do
|
13
|
+
modified = described_class.whitespace(:chomp, string)
|
14
|
+
expect(modified).to eq(" text\t \n to\t modify")
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
it "collapses text" do
|
18
|
+
modified = described_class.whitespace(:collapse, string)
|
19
|
+
expect(modified).to eq(" text to modify ")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "removes whitespace" do
|
23
|
+
modified = described_class.whitespace(:remove, string)
|
24
|
+
expect(modified).to eq("texttomodify")
|
25
|
+
end
|
19
26
|
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
context "nil (empty user input)" do
|
29
|
+
let(:string) { nil }
|
30
|
+
|
31
|
+
example "trim returns nil" do
|
32
|
+
modified = described_class.whitespace(:trim, string)
|
33
|
+
expect(modified).to be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
example "chomp returns nil" do
|
37
|
+
modified = described_class.whitespace(:chomp, string)
|
38
|
+
expect(modified).to be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
example "collapse returns nil" do
|
42
|
+
modified = described_class.whitespace(:collapse, string)
|
43
|
+
expect(modified).to be_nil
|
44
|
+
end
|
45
|
+
|
46
|
+
example "remove returns nil" do
|
47
|
+
modified = described_class.whitespace(:remove, string)
|
48
|
+
expect(modified).to be_nil
|
49
|
+
end
|
24
50
|
end
|
25
51
|
end
|
@@ -10,8 +10,7 @@ RSpec.describe TTY::Prompt::Question, '#required' do
|
|
10
10
|
prompt.ask('What is your name?') { |q| q.required(true) }
|
11
11
|
expect(prompt.output.string).to eq([
|
12
12
|
"What is your name? ",
|
13
|
-
"\e[
|
14
|
-
"\e[1000D\e[K",
|
13
|
+
"\e[1A\e[2K\e[1G",
|
15
14
|
"What is your name? \e[32mPiotr\e[0m\n"
|
16
15
|
].join)
|
17
16
|
end
|
@@ -22,12 +21,11 @@ RSpec.describe TTY::Prompt::Question, '#required' do
|
|
22
21
|
prompt.ask('What is your name?', required: true)
|
23
22
|
expect(prompt.output.string).to eq([
|
24
23
|
"What is your name? ",
|
25
|
-
"\e[1000D\e[K",
|
26
24
|
"\e[31m>>\e[0m Value must be provided\e[1A",
|
27
|
-
"\e[
|
25
|
+
"\e[2K\e[1G",
|
28
26
|
"What is your name? ",
|
29
|
-
"\e[
|
30
|
-
"\e[
|
27
|
+
"\e[2K\e[1G",
|
28
|
+
"\e[1A\e[2K\e[1G",
|
31
29
|
"What is your name? \e[32mPiotr\e[0m\n"
|
32
30
|
].join)
|
33
31
|
end
|
@@ -50,16 +48,14 @@ RSpec.describe TTY::Prompt::Question, '#required' do
|
|
50
48
|
end
|
51
49
|
expect(prompt.output.string).to eq([
|
52
50
|
"File name? ",
|
53
|
-
|
54
|
-
|
55
|
-
"\e[1A\e[1000D\e[K",
|
51
|
+
"\e[31m>>\e[0m File name must not be empty!",
|
52
|
+
"\e[1A\e[2K\e[1G",
|
56
53
|
"File name? ",
|
57
|
-
"\e[1000D\e[K",
|
58
54
|
"\e[31m>>\e[0m File already exists!",
|
59
|
-
"\e[1A\e[
|
55
|
+
"\e[1A\e[2K\e[1G",
|
60
56
|
"File name? ",
|
61
|
-
"\e[
|
62
|
-
"\e[1A\e[
|
57
|
+
"\e[2K\e[1G",
|
58
|
+
"\e[1A\e[2K\e[1G",
|
63
59
|
"File name? \e[32mtest\e[0m\n",
|
64
60
|
].join)
|
65
61
|
expect(answer).to eq('test')
|
@@ -15,8 +15,7 @@ RSpec.describe TTY::Prompt::Question, '#validate' do
|
|
15
15
|
expect(answer).to eq('piotr.murach')
|
16
16
|
expect(prompt.output.string).to eq([
|
17
17
|
"What is your username? ",
|
18
|
-
"\e[
|
19
|
-
"\e[1000D\e[K",
|
18
|
+
"\e[1A\e[2K\e[1G",
|
20
19
|
"What is your username? \e[32mpiotr.murach\e[0m\n"
|
21
20
|
].join)
|
22
21
|
end
|
@@ -54,12 +53,11 @@ RSpec.describe TTY::Prompt::Question, '#validate' do
|
|
54
53
|
expect(answer).to eq('piotr@example.com')
|
55
54
|
expect(prompt.output.string).to eq([
|
56
55
|
"What is your email? ",
|
57
|
-
"\e[1000D\e[K",
|
58
56
|
"\e[31m>>\e[0m Your answer is invalid (must match :email)\e[1A",
|
59
|
-
"\e[
|
57
|
+
"\e[2K\e[1G",
|
60
58
|
"What is your email? ",
|
61
|
-
"\e[
|
62
|
-
"\e[
|
59
|
+
"\e[2K\e[1G",
|
60
|
+
"\e[1A\e[2K\e[1G",
|
63
61
|
"What is your email? \e[32mpiotr@example.com\e[0m\n"
|
64
62
|
].join)
|
65
63
|
end
|
@@ -76,12 +74,11 @@ RSpec.describe TTY::Prompt::Question, '#validate' do
|
|
76
74
|
expect(answer).to eq('piotr@example.com')
|
77
75
|
expect(prompt.output.string).to eq([
|
78
76
|
"What is your email? ",
|
79
|
-
"\e[1000D\e[K",
|
80
77
|
"\e[31m>>\e[0m Not an email!\e[1A",
|
81
|
-
"\e[
|
78
|
+
"\e[2K\e[1G",
|
82
79
|
"What is your email? ",
|
83
|
-
"\e[
|
84
|
-
"\e[
|
80
|
+
"\e[2K\e[1G",
|
81
|
+
"\e[1A\e[2K\e[1G",
|
85
82
|
"What is your email? \e[32mpiotr@example.com\e[0m\n"
|
86
83
|
].join)
|
87
84
|
end
|
@@ -1,51 +1,56 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'shellwords'
|
4
|
+
require 'tty/prompt/reader/codes'
|
4
5
|
|
5
6
|
RSpec.describe TTY::Prompt::Reader::KeyEvent, '#from' do
|
6
|
-
|
7
|
-
event = described_class.from("\b")
|
8
|
-
expect(event.key.name).to eq(:backspace)
|
9
|
-
expect(event.value).to eq("\b")
|
10
|
-
end
|
7
|
+
let(:keys) { TTY::Prompt::Reader::Codes.keys }
|
11
8
|
|
12
9
|
it "parses backspace" do
|
13
|
-
event = described_class.from("\
|
10
|
+
event = described_class.from(keys, "\x7f")
|
14
11
|
expect(event.key.name).to eq(:backspace)
|
15
|
-
expect(event.
|
16
|
-
expect(event.value).to eq("\e\x7f")
|
12
|
+
expect(event.value).to eq("\x7f")
|
17
13
|
end
|
18
14
|
|
19
15
|
it "parses lowercase char" do
|
20
|
-
event = described_class.from('a')
|
21
|
-
expect(event.key.name).to eq(
|
16
|
+
event = described_class.from(keys, 'a')
|
17
|
+
expect(event.key.name).to eq(:alpha)
|
22
18
|
expect(event.value).to eq('a')
|
23
19
|
end
|
24
20
|
|
25
21
|
it "parses uppercase char" do
|
26
|
-
event = described_class.from('A')
|
27
|
-
expect(event.key.name).to eq(
|
22
|
+
event = described_class.from(keys, 'A')
|
23
|
+
expect(event.key.name).to eq(:alpha)
|
28
24
|
expect(event.value).to eq('A')
|
29
25
|
end
|
30
26
|
|
27
|
+
it "parses ctrl-a to ctrl-z inputs" do
|
28
|
+
(1..26).zip('a'..'z').each do |code, char|
|
29
|
+
next if ['i', 'j', 'm'].include?(char)
|
30
|
+
event = described_class.from(keys, code.chr)
|
31
|
+
expect(event.key.name).to eq(:"ctrl_#{char}")
|
32
|
+
expect(event.value).to eq(code.chr)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
31
36
|
# F1-F12 keys
|
32
37
|
{
|
33
|
-
f1: ["\eOP", "\e[11~"
|
34
|
-
f2: ["\eOQ", "\e[12~"
|
35
|
-
f3: ["\eOR", "\e[13~"
|
36
|
-
f4: ["\eOS", "\e[14~"
|
37
|
-
f5: [ "\e[15~"
|
38
|
-
f6: [ "\e[17~"
|
39
|
-
f7: [ "\e[18~"
|
40
|
-
f8: [ "\e[19~"
|
41
|
-
f9: [ "\e[20~"
|
42
|
-
f10: [ "\e[21~"
|
43
|
-
f11: [ "\e[23~"
|
44
|
-
f12: [ "\e[24~"
|
38
|
+
f1: ["\eOP", "\e[11~"],
|
39
|
+
f2: ["\eOQ", "\e[12~"],
|
40
|
+
f3: ["\eOR", "\e[13~"],
|
41
|
+
f4: ["\eOS", "\e[14~"],
|
42
|
+
f5: [ "\e[15~"],
|
43
|
+
f6: [ "\e[17~"],
|
44
|
+
f7: [ "\e[18~"],
|
45
|
+
f8: [ "\e[19~"],
|
46
|
+
f9: [ "\e[20~"],
|
47
|
+
f10: [ "\e[21~"],
|
48
|
+
f11: [ "\e[23~"],
|
49
|
+
f12: [ "\e[24~"]
|
45
50
|
}.each do |name, codes|
|
46
51
|
codes.each do |code|
|
47
52
|
it "parses #{Shellwords.escape(code)} as #{name} key" do
|
48
|
-
event = described_class.from(code)
|
53
|
+
event = described_class.from(keys, code)
|
49
54
|
expect(event.key.name).to eq(name)
|
50
55
|
expect(event.key.meta).to eq(false)
|
51
56
|
expect(event.key.ctrl).to eq(false)
|
@@ -55,19 +60,18 @@ RSpec.describe TTY::Prompt::Reader::KeyEvent, '#from' do
|
|
55
60
|
end
|
56
61
|
|
57
62
|
# arrow keys & page navigation
|
58
|
-
#
|
59
63
|
{
|
60
|
-
up: ["\e[A"
|
61
|
-
down: ["\e[B"
|
62
|
-
right: ["\e[C"
|
63
|
-
left: ["\e[D"
|
64
|
-
clear: ["\e[E"
|
64
|
+
up: ["\e[A"],
|
65
|
+
down: ["\e[B"],
|
66
|
+
right: ["\e[C"],
|
67
|
+
left: ["\e[D"],
|
68
|
+
clear: ["\e[E"],
|
65
69
|
end: ["\e[F"],
|
66
70
|
home: ["\e[H"]
|
67
71
|
}.each do |name, codes|
|
68
72
|
codes.each do |code|
|
69
73
|
it "parses #{Shellwords.escape(code)} as #{name} key" do
|
70
|
-
event = described_class.from(code)
|
74
|
+
event = described_class.from(keys, code)
|
71
75
|
expect(event.key.name).to eq(name)
|
72
76
|
expect(event.key.meta).to eq(false)
|
73
77
|
expect(event.key.ctrl).to eq(false)
|
@@ -75,22 +79,4 @@ RSpec.describe TTY::Prompt::Reader::KeyEvent, '#from' do
|
|
75
79
|
end
|
76
80
|
end
|
77
81
|
end
|
78
|
-
|
79
|
-
{
|
80
|
-
up: ["\e[a"],
|
81
|
-
down: ["\e[b"],
|
82
|
-
right: ["\e[c"],
|
83
|
-
left: ["\e[d"],
|
84
|
-
clear: ["\e[e"],
|
85
|
-
}.each do |name, codes|
|
86
|
-
codes.each do |code|
|
87
|
-
it "parses #{Shellwords.escape(code)} as SHIFT + #{name} key" do
|
88
|
-
event = described_class.from(code)
|
89
|
-
expect(event.key.name).to eq(name)
|
90
|
-
expect(event.key.meta).to eq(false)
|
91
|
-
expect(event.key.ctrl).to eq(false)
|
92
|
-
expect(event.key.shift).to eq(true)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
82
|
end
|
@@ -3,7 +3,9 @@
|
|
3
3
|
RSpec.describe TTY::Prompt::Reader, '#publish_keypress_event' do
|
4
4
|
let(:input) { StringIO.new }
|
5
5
|
let(:out) { StringIO.new }
|
6
|
-
let(:
|
6
|
+
let(:env) { { "TTY_TEST" => true } }
|
7
|
+
|
8
|
+
let(:reader) { described_class.new(input, out, env: env) }
|
7
9
|
|
8
10
|
it "publishes :keypress events" do
|
9
11
|
input << "abc\n"
|
@@ -11,8 +13,8 @@ RSpec.describe TTY::Prompt::Reader, '#publish_keypress_event' do
|
|
11
13
|
chars = []
|
12
14
|
reader.on(:keypress) { |event| chars << event.value }
|
13
15
|
answer = reader.read_line
|
14
|
-
expect(chars).to eq(%
|
15
|
-
expect(answer).to eq("abc")
|
16
|
+
expect(chars).to eq(%W(a b c \n))
|
17
|
+
expect(answer).to eq("abc\n")
|
16
18
|
end
|
17
19
|
|
18
20
|
it "publishes :keyup for read_keypress" do
|