tty-prompt 0.18.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +92 -0
  3. data/README.md +549 -248
  4. data/lib/tty-prompt.rb +1 -2
  5. data/lib/tty/prompt.rb +187 -143
  6. data/lib/tty/prompt/answers_collector.rb +5 -5
  7. data/lib/tty/prompt/{enum_paginator.rb → block_paginator.rb} +20 -19
  8. data/lib/tty/prompt/choice.rb +5 -7
  9. data/lib/tty/prompt/choices.rb +29 -11
  10. data/lib/tty/prompt/confirm_question.rb +38 -16
  11. data/lib/tty/prompt/const.rb +17 -0
  12. data/lib/tty/prompt/converter_dsl.rb +6 -7
  13. data/lib/tty/prompt/converter_registry.rb +31 -26
  14. data/lib/tty/prompt/converters.rb +139 -32
  15. data/lib/tty/prompt/enum_list.rb +57 -27
  16. data/lib/tty/prompt/errors.rb +31 -0
  17. data/lib/tty/prompt/evaluator.rb +1 -1
  18. data/lib/tty/prompt/expander.rb +39 -13
  19. data/lib/tty/prompt/keypress.rb +31 -36
  20. data/lib/tty/prompt/list.rb +175 -65
  21. data/lib/tty/prompt/mask_question.rb +4 -5
  22. data/lib/tty/prompt/multi_list.rb +124 -33
  23. data/lib/tty/prompt/multiline.rb +7 -6
  24. data/lib/tty/prompt/paginator.rb +38 -26
  25. data/lib/tty/prompt/question.rb +83 -34
  26. data/lib/tty/prompt/question/checks.rb +18 -0
  27. data/lib/tty/prompt/question/validation.rb +3 -3
  28. data/lib/tty/prompt/selected_choices.rb +76 -0
  29. data/lib/tty/prompt/slider.rb +83 -16
  30. data/lib/tty/prompt/statement.rb +3 -3
  31. data/lib/tty/prompt/suggestion.rb +6 -6
  32. data/lib/tty/prompt/symbols.rb +58 -34
  33. data/lib/tty/prompt/test.rb +36 -0
  34. data/lib/tty/prompt/timer.rb +75 -0
  35. data/lib/tty/prompt/utils.rb +1 -3
  36. data/lib/tty/prompt/version.rb +1 -1
  37. metadata +29 -227
  38. data/Rakefile +0 -8
  39. data/examples/ask.rb +0 -7
  40. data/examples/ask_valid.rb +0 -12
  41. data/examples/collect.rb +0 -21
  42. data/examples/echo.rb +0 -11
  43. data/examples/enum_select.rb +0 -7
  44. data/examples/enum_select_disabled.rb +0 -16
  45. data/examples/enum_select_paged.rb +0 -9
  46. data/examples/enum_select_wrapped.rb +0 -15
  47. data/examples/expand.rb +0 -29
  48. data/examples/in.rb +0 -9
  49. data/examples/inputs.rb +0 -10
  50. data/examples/key_events.rb +0 -15
  51. data/examples/keypress.rb +0 -9
  52. data/examples/mask.rb +0 -13
  53. data/examples/multi_select.rb +0 -8
  54. data/examples/multi_select_disabled.rb +0 -17
  55. data/examples/multi_select_paged.rb +0 -9
  56. data/examples/multi_select_wrapped.rb +0 -15
  57. data/examples/multiline.rb +0 -9
  58. data/examples/pause.rb +0 -9
  59. data/examples/select.rb +0 -20
  60. data/examples/select_disabled.rb +0 -18
  61. data/examples/select_enum.rb +0 -8
  62. data/examples/select_filtered.rb +0 -11
  63. data/examples/select_paginated.rb +0 -11
  64. data/examples/select_wrapped.rb +0 -15
  65. data/examples/slider.rb +0 -6
  66. data/examples/validation.rb +0 -9
  67. data/examples/yes_no.rb +0 -7
  68. data/lib/tty/prompt/messages.rb +0 -49
  69. data/lib/tty/prompt/timeout.rb +0 -78
  70. data/lib/tty/test_prompt.rb +0 -20
  71. data/spec/spec_helper.rb +0 -45
  72. data/spec/unit/ask_spec.rb +0 -132
  73. data/spec/unit/choice/eql_spec.rb +0 -22
  74. data/spec/unit/choice/from_spec.rb +0 -96
  75. data/spec/unit/choices/add_spec.rb +0 -12
  76. data/spec/unit/choices/each_spec.rb +0 -13
  77. data/spec/unit/choices/find_by_spec.rb +0 -10
  78. data/spec/unit/choices/new_spec.rb +0 -10
  79. data/spec/unit/choices/pluck_spec.rb +0 -9
  80. data/spec/unit/collect_spec.rb +0 -96
  81. data/spec/unit/converters/convert_bool_spec.rb +0 -58
  82. data/spec/unit/converters/convert_char_spec.rb +0 -11
  83. data/spec/unit/converters/convert_custom_spec.rb +0 -14
  84. data/spec/unit/converters/convert_date_spec.rb +0 -34
  85. data/spec/unit/converters/convert_file_spec.rb +0 -18
  86. data/spec/unit/converters/convert_number_spec.rb +0 -39
  87. data/spec/unit/converters/convert_path_spec.rb +0 -15
  88. data/spec/unit/converters/convert_range_spec.rb +0 -22
  89. data/spec/unit/converters/convert_regex_spec.rb +0 -12
  90. data/spec/unit/converters/convert_string_spec.rb +0 -21
  91. data/spec/unit/converters/on_error_spec.rb +0 -9
  92. data/spec/unit/distance/distance_spec.rb +0 -73
  93. data/spec/unit/enum_paginator_spec.rb +0 -75
  94. data/spec/unit/enum_select_spec.rb +0 -446
  95. data/spec/unit/error_spec.rb +0 -20
  96. data/spec/unit/evaluator_spec.rb +0 -67
  97. data/spec/unit/expand_spec.rb +0 -198
  98. data/spec/unit/keypress_spec.rb +0 -72
  99. data/spec/unit/mask_spec.rb +0 -132
  100. data/spec/unit/multi_select_spec.rb +0 -495
  101. data/spec/unit/multiline_spec.rb +0 -77
  102. data/spec/unit/new_spec.rb +0 -20
  103. data/spec/unit/ok_spec.rb +0 -10
  104. data/spec/unit/paginator_spec.rb +0 -73
  105. data/spec/unit/question/checks_spec.rb +0 -97
  106. data/spec/unit/question/default_spec.rb +0 -31
  107. data/spec/unit/question/echo_spec.rb +0 -38
  108. data/spec/unit/question/in_spec.rb +0 -115
  109. data/spec/unit/question/initialize_spec.rb +0 -12
  110. data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
  111. data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
  112. data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
  113. data/spec/unit/question/modify_spec.rb +0 -41
  114. data/spec/unit/question/required_spec.rb +0 -92
  115. data/spec/unit/question/validate_spec.rb +0 -115
  116. data/spec/unit/question/validation/call_spec.rb +0 -31
  117. data/spec/unit/question/validation/coerce_spec.rb +0 -30
  118. data/spec/unit/result_spec.rb +0 -40
  119. data/spec/unit/say_spec.rb +0 -67
  120. data/spec/unit/select_spec.rb +0 -643
  121. data/spec/unit/slider_spec.rb +0 -100
  122. data/spec/unit/statement/initialize_spec.rb +0 -15
  123. data/spec/unit/subscribe_spec.rb +0 -22
  124. data/spec/unit/suggest_spec.rb +0 -28
  125. data/spec/unit/warn_spec.rb +0 -21
  126. data/spec/unit/yes_no_spec.rb +0 -251
  127. data/tasks/console.rake +0 -11
  128. data/tasks/coverage.rake +0 -11
  129. data/tasks/spec.rake +0 -29
  130. data/tty-prompt.gemspec +0 -33
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question, '#multiline' do
4
- it 'reads no lines' do
5
- prompt = TTY::TestPrompt.new
6
- prompt.input << "\C-d"
7
- prompt.input.rewind
8
-
9
- answer = prompt.multiline("Description?")
10
-
11
- expect(answer).to eq([])
12
- expect(prompt.output.string).to eq([
13
- "Description? \e[90m(Press CTRL-D or CTRL-Z to finish)\e[0m\n",
14
- "\e[2K\e[1G\e[1A\e[2K\e[1G",
15
- "Description? \n"
16
- ].join)
17
- end
18
-
19
- it "uses defualt when no input" do
20
- prompt = TTY::TestPrompt.new
21
- prompt.input << "\C-d"
22
- prompt.input.rewind
23
-
24
- answer = prompt.multiline("Description?", default: 'A super sweet prompt')
25
-
26
- expect(answer).to eq([])
27
- expect(prompt.output.string).to eq([
28
- "Description? \e[90m(Press CTRL-D or CTRL-Z to finish)\e[0m\n",
29
- "\e[2K\e[1G\e[1A\e[2K\e[1G",
30
- "Description? \e[32mA super sweet prompt\e[0m\n"
31
- ].join)
32
- end
33
-
34
- it "changes help text" do
35
- prompt = TTY::TestPrompt.new
36
- prompt.input << "\C-d"
37
- prompt.input.rewind
38
-
39
- answer = prompt.multiline("Description?") do |q|
40
- q.default 'A super sweet prompt'
41
- q.help '(Press thy ctrl-d to end)'
42
- end
43
-
44
- expect(answer).to eq([])
45
- expect(prompt.output.string).to eq([
46
- "Description? \e[90m(Press thy ctrl-d to end)\e[0m\n",
47
- "\e[2K\e[1G\e[1A\e[2K\e[1G",
48
- "Description? \e[32mA super sweet prompt\e[0m\n"
49
- ].join)
50
- end
51
-
52
- it 'reads multiple lines with empty lines' do
53
- prompt = TTY::TestPrompt.new
54
- prompt.input << "aa\n\nbb\n\n\ncc\C-d"
55
- prompt.input.rewind
56
-
57
- answer = prompt.multiline("Description?")
58
- expect(answer).to eq(["aa\n", "bb\n", "cc"])
59
- expect(prompt.output.string).to eq([
60
- "Description? \e[90m(Press CTRL-D or CTRL-Z to finish)\e[0m\n",
61
- "\e[2K\e[1Ga",
62
- "\e[2K\e[1Gaa",
63
- "\e[2K\e[1Gaa\n",
64
- "\e[2K\e[1G\n",
65
- "\e[2K\e[1Gb",
66
- "\e[2K\e[1Gbb",
67
- "\e[2K\e[1Gbb\n",
68
- "\e[2K\e[1G\n",
69
- "\e[2K\e[1G\n",
70
- "\e[2K\e[1Gc",
71
- "\e[2K\e[1Gcc",
72
- "\e[2K\e[1G\e[1A" * 6,
73
- "\e[2K\e[1G",
74
- "Description? \e[32maa ...\e[0m\n"
75
- ].join)
76
- end
77
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt, '#new' do
4
- let(:env) { { "TTY_TEST" => true } }
5
-
6
- it "sets prefix" do
7
- prompt = described_class.new(prefix: "[?]", env: env)
8
- expect(prompt.prefix).to eq("[?]")
9
- end
10
-
11
- it "sets input stream" do
12
- prompt = described_class.new(input: :stream1, env: env)
13
- expect(prompt.input).to eq(:stream1)
14
- end
15
-
16
- it "sets output stream" do
17
- prompt = described_class.new(output: :stream2, env: env)
18
- expect(prompt.output).to eq(:stream2)
19
- end
20
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt, 'ok' do
4
- subject(:prompt) { TTY::TestPrompt.new }
5
-
6
- it 'prints text in green' do
7
- prompt.ok("All is fine")
8
- expect(prompt.output.string).to eq("\e[32mAll is fine\e[0m\n")
9
- end
10
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Paginator, '#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([['b',1], ['c',2], ['d',3]])
28
- expect(paginator.paginate(list, 5).to_a).to eq([['c',2], ['d',3], ['e',4]])
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([['b',1], ['c',2], ['d',3]])
41
- expect(paginator.paginate(list, 5).to_a).to eq([['c',2], ['d',3], ['e',4]])
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([['e',4], ['f',5], ['g',6]])
44
- expect(paginator.paginate(list, 8).to_a).to eq([['e',4], ['f',5], ['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(3)
53
- paginator.paginate(list, 5)
54
- expect(paginator.max_index).to eq(4)
55
- end
56
-
57
- it "starts with default selection" do
58
- list = %w(a b c d e f g)
59
- paginator = described_class.new({per_page: 3, default: 3})
60
-
61
- expect(paginator.paginate(list, 4).to_a).to eq([['d',3], ['e',4], ['f',5]])
62
- end
63
-
64
- it "doesn't accept invalid pagination" do
65
- list = %w(a b c d e f g)
66
-
67
- paginator = described_class.new({per_page: 0})
68
-
69
- expect {
70
- paginator.paginate(list, 4)
71
- }.to raise_error(TTY::Prompt::InvalidArgument, /per_page must be > 0/)
72
- end
73
- end
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it "passes range check" do
8
- question = described_class.new(prompt)
9
- question.in 1..10
10
-
11
- result = TTY::Prompt::Question::Checks::CheckRange.call(question, 2)
12
-
13
- expect(result).to eq([2])
14
- end
15
-
16
- it "fails range check" do
17
- question = described_class.new(prompt, messages: TTY::Prompt.messages)
18
- question.in 1..10
19
-
20
- result = TTY::Prompt::Question::Checks::CheckRange.call(question, 11)
21
-
22
- expect(result).to eq([11, ["Value 11 must be within the range 1..10"]])
23
- end
24
-
25
- it "fails range check" do
26
- question = described_class.new(prompt)
27
- question.in 1..10, 'Outside of range!'
28
-
29
- result = TTY::Prompt::Question::Checks::CheckRange.call(question, 11)
30
-
31
- expect(result).to eq([11, ['Outside of range!']])
32
- end
33
-
34
- it "passes validation check" do
35
- question = described_class.new(prompt)
36
- question.validate(/\A\d{5}\Z/)
37
-
38
- result = TTY::Prompt::Question::Checks::CheckValidation.call(question, '12345')
39
-
40
- expect(result).to eq(['12345'])
41
- end
42
-
43
- it "fails validation check" do
44
- question = described_class.new(prompt, messages: TTY::Prompt.messages)
45
- question.validate(/\A\d{5}\Z/)
46
-
47
- result = TTY::Prompt::Question::Checks::CheckValidation.call(question, '123')
48
-
49
- expect(result).to eq(['123', ['Your answer is invalid (must match /\\A\\d{5}\\Z/)']])
50
- end
51
-
52
- it "fails validation check with inlined custom message" do
53
- question = described_class.new(prompt)
54
- question.validate(/\A\w+@\w+\.\w+\Z/, 'Invalid email address')
55
-
56
- result = TTY::Prompt::Question::Checks::CheckValidation.call(question, 'piotr@com')
57
-
58
- expect(result).to eq(['piotr@com', ['Invalid email address']])
59
- end
60
-
61
- it "fails validation check with custom message" do
62
- question = described_class.new(prompt)
63
- question.validate(/\A\w+@\w+\.\w+\Z/)
64
- question.messages[:valid?] = 'Invalid email address'
65
-
66
- result = TTY::Prompt::Question::Checks::CheckValidation.call(question, 'piotr@com')
67
-
68
- expect(result).to eq(['piotr@com', ['Invalid email address']])
69
- end
70
-
71
- it "passes required check" do
72
- question = described_class.new(prompt)
73
- question.required true
74
-
75
- result = TTY::Prompt::Question::Checks::CheckRequired.call(question, 'Piotr')
76
-
77
- expect(result).to eq(['Piotr'])
78
- end
79
-
80
- it "fails required check" do
81
- question = described_class.new(prompt, messages: TTY::Prompt.messages)
82
- question.required true
83
-
84
- result = TTY::Prompt::Question::Checks::CheckRequired.call(question, nil)
85
-
86
- expect(result).to eq([nil, ['Value must be provided']])
87
- end
88
-
89
- it "fails required check with custom message" do
90
- question = described_class.new(prompt)
91
- question.required true, 'Required input'
92
-
93
- result = TTY::Prompt::Question::Checks::CheckRequired.call(question, nil)
94
-
95
- expect(result).to eq([nil, ['Required input']])
96
- end
97
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question, '#default' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it 'uses default value' do
8
- name = 'Anonymous'
9
- prompt.input << "\n"
10
- prompt.input.rewind
11
- answer = prompt.ask('What is your name?', default: name)
12
- expect(answer).to eq(name)
13
- expect(prompt.output.string).to eq([
14
- "What is your name? \e[90m(Anonymous)\e[0m ",
15
- "\e[2K\e[1GWhat is your name? \e[90m(Anonymous)\e[0m \n",
16
- "\e[1A\e[2K\e[1G",
17
- "What is your name? \e[32mAnonymous\e[0m\n"
18
- ].join)
19
- end
20
-
21
- it 'uses default value in block' do
22
- name = 'Anonymous'
23
- answer = prompt.ask('What is your name?') { |q| q.default(name) }
24
- expect(answer).to eq(name)
25
- expect(prompt.output.string).to eq([
26
- "What is your name? \e[90m(Anonymous)\e[0m ",
27
- "\e[1A\e[2K\e[1G",
28
- "What is your name? \e[32mAnonymous\e[0m\n"
29
- ].join)
30
- end
31
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question, '#echo' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it 'asks with echo on' do
8
- prompt.input << "password"
9
- prompt.input.rewind
10
- answer = prompt.ask("What is your password?") { |q| q.echo(true) }
11
- expect(answer).to eql("password")
12
- expect(prompt.output.string).to eq([
13
- "What is your password? ",
14
- "\e[2K\e[1GWhat is your password? p",
15
- "\e[2K\e[1GWhat is your password? pa",
16
- "\e[2K\e[1GWhat is your password? pas",
17
- "\e[2K\e[1GWhat is your password? pass",
18
- "\e[2K\e[1GWhat is your password? passw",
19
- "\e[2K\e[1GWhat is your password? passwo",
20
- "\e[2K\e[1GWhat is your password? passwor",
21
- "\e[2K\e[1GWhat is your password? password",
22
- "\e[1A\e[2K\e[1G",
23
- "What is your password? \e[32mpassword\e[0m\n"
24
- ].join)
25
- end
26
-
27
- it 'asks with echo off' do
28
- prompt.input << "password"
29
- prompt.input.rewind
30
- answer = prompt.ask("What is your password?", echo: false)
31
- expect(answer).to eql("password")
32
- expect(prompt.output.string).to eq([
33
- "What is your password? ",
34
- "\e[1A\e[2K\e[1G",
35
- "What is your password? \n"
36
- ].join)
37
- end
38
- end
@@ -1,115 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question, '#in' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it "reads range from option" do
8
- prompt.input << '8'
9
- prompt.input.rewind
10
-
11
- answer = prompt.ask("How do you like it on scale 1-10?", in: '1-10')
12
-
13
- expect(answer).to eq('8')
14
- end
15
-
16
- it 'reads number within string range' do
17
- prompt.input << '8'
18
- prompt.input.rewind
19
-
20
- answer = prompt.ask("How do you like it on scale 1-10?") do |q|
21
- q.in('1-10')
22
- end
23
-
24
- expect(answer).to eq('8')
25
- expect(prompt.output.string).to eq([
26
- "How do you like it on scale 1-10? ",
27
- "\e[2K\e[1GHow do you like it on scale 1-10? 8",
28
- "\e[1A\e[2K\e[1G",
29
- "How do you like it on scale 1-10? \e[32m8\e[0m\n",
30
- ].join)
31
- end
32
-
33
- it 'reads number within digit range' do
34
- prompt.input << '8.1'
35
- prompt.input.rewind
36
-
37
- answer = prompt.ask("How do you like it on scale 1-10?") do |q|
38
- q.in(1.0..11.5)
39
- end
40
-
41
- expect(answer).to eq('8.1')
42
- expect(prompt.output.string).to eq([
43
- "How do you like it on scale 1-10? ",
44
- "\e[2K\e[1GHow do you like it on scale 1-10? 8",
45
- "\e[2K\e[1GHow do you like it on scale 1-10? 8.",
46
- "\e[2K\e[1GHow do you like it on scale 1-10? 8.1",
47
- "\e[1A\e[2K\e[1G",
48
- "How do you like it on scale 1-10? \e[32m8.1\e[0m\n",
49
- ].join)
50
- end
51
-
52
- it 'reads letters within range' do
53
- prompt.input << 'E'
54
- prompt.input.rewind
55
-
56
- answer = prompt.ask("Your favourite vitamin? (A-K)") do |q|
57
- q.in('A-K')
58
- end
59
-
60
- expect(answer).to eq('E')
61
- expect(prompt.output.string).to eq([
62
- "Your favourite vitamin? (A-K) ",
63
- "\e[2K\e[1GYour favourite vitamin? (A-K) E",
64
- "\e[1A\e[2K\e[1G",
65
- "Your favourite vitamin? (A-K) \e[32mE\e[0m\n"
66
- ].join)
67
- end
68
-
69
- it "provides default error message when wrong input" do
70
- prompt.input << "A\n2\n"
71
- prompt.input.rewind
72
-
73
- answer = prompt.ask("How spicy on scale? (1-5)", in: '1-5')
74
-
75
- expect(answer).to eq('2')
76
- expect(prompt.output.string).to eq([
77
- "How spicy on scale? (1-5) ",
78
- "\e[2K\e[1GHow spicy on scale? (1-5) A",
79
- "\e[2K\e[1GHow spicy on scale? (1-5) A\n",
80
- "\e[31m>>\e[0m Value A must be within the range 1..5\e[1A",
81
- "\e[2K\e[1G",
82
- "How spicy on scale? (1-5) ",
83
- "\e[2K\e[1GHow spicy on scale? (1-5) 2",
84
- "\e[2K\e[1GHow spicy on scale? (1-5) 2\n",
85
- "\e[2K\e[1G",
86
- "\e[1A\e[2K\e[1G",
87
- "How spicy on scale? (1-5) \e[32m2\e[0m\n"
88
- ].join)
89
- end
90
-
91
- it "overwrites default error message when wrong input" do
92
- prompt.input << "A\n2\n"
93
- prompt.input.rewind
94
-
95
- answer = prompt.ask("How spicy on scale? (1-5)") do |q|
96
- q.in '1-5'
97
- q.messages[:range?] = 'Ohh dear what is this %{value} doing in %{in}?'
98
- end
99
-
100
- expect(answer).to eq('2')
101
- expect(prompt.output.string).to eq([
102
- "How spicy on scale? (1-5) ",
103
- "\e[2K\e[1GHow spicy on scale? (1-5) A",
104
- "\e[2K\e[1GHow spicy on scale? (1-5) A\n",
105
- "\e[31m>>\e[0m Ohh dear what is this A doing in 1..5?\e[1A",
106
- "\e[2K\e[1G",
107
- "How spicy on scale? (1-5) ",
108
- "\e[2K\e[1GHow spicy on scale? (1-5) 2",
109
- "\e[2K\e[1GHow spicy on scale? (1-5) 2\n",
110
- "\e[2K\e[1G",
111
- "\e[1A\e[2K\e[1G",
112
- "How spicy on scale? (1-5) \e[32m2\e[0m\n"
113
- ].join)
114
- end
115
- end