tty-prompt 0.18.1 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +95 -0
  3. data/README.md +598 -256
  4. data/lib/tty-prompt.rb +1 -2
  5. data/lib/tty/prompt.rb +192 -144
  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 +9 -10
  9. data/lib/tty/prompt/choices.rb +30 -12
  10. data/lib/tty/prompt/confirm_question.rb +42 -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 +81 -26
  16. data/lib/tty/prompt/errors.rb +31 -0
  17. data/lib/tty/prompt/evaluator.rb +2 -2
  18. data/lib/tty/prompt/expander.rb +45 -15
  19. data/lib/tty/prompt/keypress.rb +33 -36
  20. data/lib/tty/prompt/list.rb +198 -63
  21. data/lib/tty/prompt/mask_question.rb +11 -8
  22. data/lib/tty/prompt/multi_list.rb +131 -28
  23. data/lib/tty/prompt/multiline.rb +9 -7
  24. data/lib/tty/prompt/paginator.rb +38 -26
  25. data/lib/tty/prompt/question.rb +92 -37
  26. data/lib/tty/prompt/question/checks.rb +20 -2
  27. data/lib/tty/prompt/question/modifier.rb +4 -2
  28. data/lib/tty/prompt/question/validation.rb +3 -3
  29. data/lib/tty/prompt/selected_choices.rb +77 -0
  30. data/lib/tty/prompt/slider.rb +125 -30
  31. data/lib/tty/prompt/statement.rb +3 -3
  32. data/lib/tty/prompt/suggestion.rb +7 -6
  33. data/lib/tty/prompt/symbols.rb +58 -34
  34. data/lib/tty/prompt/test.rb +36 -0
  35. data/lib/tty/prompt/timer.rb +75 -0
  36. data/lib/tty/prompt/utils.rb +1 -3
  37. data/lib/tty/prompt/version.rb +1 -1
  38. metadata +29 -227
  39. data/Rakefile +0 -8
  40. data/examples/ask.rb +0 -7
  41. data/examples/ask_valid.rb +0 -12
  42. data/examples/collect.rb +0 -21
  43. data/examples/echo.rb +0 -11
  44. data/examples/enum_select.rb +0 -7
  45. data/examples/enum_select_disabled.rb +0 -16
  46. data/examples/enum_select_paged.rb +0 -9
  47. data/examples/enum_select_wrapped.rb +0 -15
  48. data/examples/expand.rb +0 -29
  49. data/examples/in.rb +0 -9
  50. data/examples/inputs.rb +0 -10
  51. data/examples/key_events.rb +0 -15
  52. data/examples/keypress.rb +0 -9
  53. data/examples/mask.rb +0 -13
  54. data/examples/multi_select.rb +0 -8
  55. data/examples/multi_select_disabled.rb +0 -17
  56. data/examples/multi_select_paged.rb +0 -9
  57. data/examples/multi_select_wrapped.rb +0 -15
  58. data/examples/multiline.rb +0 -9
  59. data/examples/pause.rb +0 -9
  60. data/examples/select.rb +0 -24
  61. data/examples/select_disabled.rb +0 -18
  62. data/examples/select_enum.rb +0 -8
  63. data/examples/select_filtered.rb +0 -11
  64. data/examples/select_paginated.rb +0 -11
  65. data/examples/select_wrapped.rb +0 -15
  66. data/examples/slider.rb +0 -6
  67. data/examples/validation.rb +0 -9
  68. data/examples/yes_no.rb +0 -7
  69. data/lib/tty/prompt/messages.rb +0 -49
  70. data/lib/tty/prompt/timeout.rb +0 -78
  71. data/lib/tty/test_prompt.rb +0 -20
  72. data/spec/spec_helper.rb +0 -45
  73. data/spec/unit/ask_spec.rb +0 -132
  74. data/spec/unit/choice/eql_spec.rb +0 -22
  75. data/spec/unit/choice/from_spec.rb +0 -96
  76. data/spec/unit/choices/add_spec.rb +0 -12
  77. data/spec/unit/choices/each_spec.rb +0 -13
  78. data/spec/unit/choices/find_by_spec.rb +0 -10
  79. data/spec/unit/choices/new_spec.rb +0 -10
  80. data/spec/unit/choices/pluck_spec.rb +0 -9
  81. data/spec/unit/collect_spec.rb +0 -96
  82. data/spec/unit/converters/convert_bool_spec.rb +0 -58
  83. data/spec/unit/converters/convert_char_spec.rb +0 -11
  84. data/spec/unit/converters/convert_custom_spec.rb +0 -14
  85. data/spec/unit/converters/convert_date_spec.rb +0 -34
  86. data/spec/unit/converters/convert_file_spec.rb +0 -18
  87. data/spec/unit/converters/convert_number_spec.rb +0 -39
  88. data/spec/unit/converters/convert_path_spec.rb +0 -15
  89. data/spec/unit/converters/convert_range_spec.rb +0 -22
  90. data/spec/unit/converters/convert_regex_spec.rb +0 -12
  91. data/spec/unit/converters/convert_string_spec.rb +0 -21
  92. data/spec/unit/converters/on_error_spec.rb +0 -9
  93. data/spec/unit/distance/distance_spec.rb +0 -73
  94. data/spec/unit/enum_paginator_spec.rb +0 -75
  95. data/spec/unit/enum_select_spec.rb +0 -446
  96. data/spec/unit/error_spec.rb +0 -20
  97. data/spec/unit/evaluator_spec.rb +0 -67
  98. data/spec/unit/expand_spec.rb +0 -198
  99. data/spec/unit/keypress_spec.rb +0 -72
  100. data/spec/unit/mask_spec.rb +0 -132
  101. data/spec/unit/multi_select_spec.rb +0 -511
  102. data/spec/unit/multiline_spec.rb +0 -77
  103. data/spec/unit/new_spec.rb +0 -20
  104. data/spec/unit/ok_spec.rb +0 -10
  105. data/spec/unit/paginator_spec.rb +0 -73
  106. data/spec/unit/question/checks_spec.rb +0 -97
  107. data/spec/unit/question/default_spec.rb +0 -31
  108. data/spec/unit/question/echo_spec.rb +0 -38
  109. data/spec/unit/question/in_spec.rb +0 -115
  110. data/spec/unit/question/initialize_spec.rb +0 -12
  111. data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
  112. data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
  113. data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
  114. data/spec/unit/question/modify_spec.rb +0 -41
  115. data/spec/unit/question/required_spec.rb +0 -92
  116. data/spec/unit/question/validate_spec.rb +0 -115
  117. data/spec/unit/question/validation/call_spec.rb +0 -31
  118. data/spec/unit/question/validation/coerce_spec.rb +0 -30
  119. data/spec/unit/result_spec.rb +0 -40
  120. data/spec/unit/say_spec.rb +0 -67
  121. data/spec/unit/select_spec.rb +0 -660
  122. data/spec/unit/slider_spec.rb +0 -100
  123. data/spec/unit/statement/initialize_spec.rb +0 -15
  124. data/spec/unit/subscribe_spec.rb +0 -22
  125. data/spec/unit/suggest_spec.rb +0 -28
  126. data/spec/unit/warn_spec.rb +0 -21
  127. data/spec/unit/yes_no_spec.rb +0 -251
  128. data/tasks/console.rake +0 -11
  129. data/tasks/coverage.rake +0 -11
  130. data/tasks/spec.rake +0 -29
  131. data/tty-prompt.gemspec +0 -33
@@ -1,100 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt, '#slider' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- let(:symbols) { TTY::Prompt::Symbols.symbols }
8
-
9
- it "specifies ranges & step" do
10
- prompt.input << "\r"
11
- prompt.input.rewind
12
- expect(prompt.slider('What size?', min: 32, max: 54, step: 2)).to eq(44)
13
- expect(prompt.output.string).to eq([
14
- "\e[?25lWhat size? ",
15
- symbols[:line] * 6,
16
- "\e[32m#{symbols[:handle]}\e[0m",
17
- "#{symbols[:line] * 5} 44",
18
- "\n\e[90m(Use arrow keys, press Enter to select)\e[0m",
19
- "\e[2K\e[1G\e[1A\e[2K\e[1G",
20
- "What size? \e[32m44\e[0m\n\e[?25h"
21
- ].join)
22
- end
23
-
24
- it "specifies default value" do
25
- prompt.input << "\r"
26
- prompt.input.rewind
27
- expect(prompt.slider('What size?', min: 32, max: 54, step: 2, default: 38)).to eq(38)
28
- expect(prompt.output.string).to eq([
29
- "\e[?25lWhat size? ",
30
- symbols[:line] * 3,
31
- "\e[32m#{symbols[:handle]}\e[0m",
32
- "#{symbols[:line] * 8} 38",
33
- "\n\e[90m(Use arrow keys, press Enter to select)\e[0m",
34
- "\e[2K\e[1G\e[1A\e[2K\e[1G",
35
- "What size? \e[32m38\e[0m\n\e[?25h"
36
- ].join)
37
- end
38
-
39
- it "specifies range through DSL" do
40
- prompt.input << "\r"
41
- prompt.input.rewind
42
- value = prompt.slider('What size?') do |range|
43
- range.default 6
44
- range.min 0
45
- range.max 20
46
- range.step 2
47
- range.format "|:slider| %d%%"
48
- end
49
- expect(value).to eq(6)
50
- expect(prompt.output.string).to eq([
51
- "\e[?25lWhat size? ",
52
- symbols[:pipe] + symbols[:line] * 3,
53
- "\e[32m#{symbols[:handle]}\e[0m",
54
- "#{symbols[:line] * 7 + symbols[:pipe]} 6%",
55
- "\n\e[90m(Use arrow keys, press Enter to select)\e[0m",
56
- "\e[2K\e[1G\e[1A\e[2K\e[1G",
57
- "What size? \e[32m6\e[0m\n\e[?25h"
58
- ].join)
59
- end
60
-
61
- it "changes display colors" do
62
- prompt.input << "\r"
63
- prompt.input.rewind
64
- options = {active_color: :red, help_color: :cyan}
65
- expect(prompt.slider('What size?', options)).to eq(5)
66
- expect(prompt.output.string).to eq([
67
- "\e[?25lWhat size? ",
68
- symbols[:line] * 5,
69
- "\e[31m#{symbols[:handle]}\e[0m",
70
- "#{symbols[:line] * 5} 5",
71
- "\n\e[36m(Use arrow keys, press Enter to select)\e[0m",
72
- "\e[2K\e[1G\e[1A\e[2K\e[1G",
73
- "What size? \e[31m5\e[0m\n\e[?25h"
74
- ].join)
75
- end
76
-
77
- it "doesn't allow values outside of range" do
78
- prompt.input << "l\r"
79
- prompt.input.rewind
80
- prompt.on(:keypress) do |event|
81
- if event.value = 'l'
82
- prompt.trigger(:keyright)
83
- end
84
- end
85
- res = prompt.slider('What size?', min: 0, max: 10, step: 1, default: 10)
86
- expect(res).to eq(10)
87
- expect(prompt.output.string).to eq([
88
- "\e[?25lWhat size? ",
89
- symbols[:line] * 10,
90
- "\e[32m#{symbols[:handle]}\e[0m 10",
91
- "\n\e[90m(Use arrow keys, press Enter to select)\e[0m",
92
- "\e[2K\e[1G\e[1A\e[2K\e[1G",
93
- "What size? ",
94
- symbols[:line] * 10,
95
- "\e[32m#{symbols[:handle]}\e[0m 10",
96
- "\e[2K\e[1G",
97
- "What size? \e[32m10\e[0m\n\e[?25h"
98
- ].join)
99
- end
100
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Statement, '#new' do
4
- it "forces newline after the prompt message" do
5
- prompt = TTY::TestPrompt.new
6
- statement = described_class.new(prompt)
7
- expect(statement.newline).to eq(true)
8
- end
9
-
10
- it "displays prompt message in color" do
11
- prompt = TTY::TestPrompt.new
12
- statement = described_class.new(prompt)
13
- expect(statement.color).to eq(false)
14
- end
15
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt, '#subscribe' do
4
- it "subscribes to key events only for the current prompt" do
5
- prompt = TTY::TestPrompt.new
6
- uuid = '14c3b412-e0c5-4ff5-9cd8-25ec3f18c702'
7
- prompt.input << "3\n#{uuid}\n"
8
- prompt.input.rewind
9
- keys = []
10
-
11
- prompt.on(:keypress) do |event|
12
- keys << :enter if event.key.name == :enter
13
- end
14
-
15
- letter = prompt.enum_select('Select something', ('A'..'Z').to_a)
16
- id = prompt.ask('Request ID?')
17
-
18
- expect(letter).to eq('C')
19
- expect(id).to eq(uuid)
20
- expect(keys).to eq([:enter, :enter])
21
- end
22
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt, '#suggest' do
4
- let(:possible) { %w(status stage stash commit branch blame) }
5
-
6
- subject(:prompt) { TTY::TestPrompt.new }
7
-
8
- it 'suggests few matches' do
9
- prompt.suggest('sta', possible)
10
- expect(prompt.output.string).
11
- to eql("Did you mean one of these?\n stage\n stash\n")
12
- end
13
-
14
- it 'suggests a single match for one character' do
15
- prompt.suggest('b', possible)
16
- expect(prompt.output.string).to eql("Did you mean this?\n blame\n")
17
- end
18
-
19
- it 'suggests a single match for two characters' do
20
- prompt.suggest('co', possible)
21
- expect(prompt.output.string).to eql("Did you mean this?\n commit\n")
22
- end
23
-
24
- it 'suggests with different text and indentation' do
25
- prompt.suggest('b', possible, indent: 4, single_text: 'Perhaps you meant?')
26
- expect(prompt.output.string).to eql("Perhaps you meant?\n blame\n")
27
- end
28
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt, '#warn' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it 'displays one message' do
8
- prompt.warn "Careful young apprentice!"
9
- expect(prompt.output.string).to eql "\e[33mCareful young apprentice!\e[0m\n"
10
- end
11
-
12
- it 'displays many messages' do
13
- prompt.warn "Careful there!", "It's dangerous!"
14
- expect(prompt.output.string).to eql "\e[33mCareful there!\e[0m\n\e[33mIt's dangerous!\e[0m\n"
15
- end
16
-
17
- it 'displays message with option' do
18
- prompt.warn "Careful young apprentice!", newline: false
19
- expect(prompt.output.string).to eql "\e[33mCareful young apprentice!\e[0m"
20
- end
21
- end
@@ -1,251 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt, 'confirmation' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- context '#yes?' do
8
- it 'agrees with question' 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[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m y",
15
- "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m ye",
16
- "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m yes",
17
- "\e[1A\e[2K\e[1G",
18
- "Are you a human? \e[32mYes\e[0m\n"
19
- ].join)
20
- end
21
-
22
- it 'disagrees with question' do
23
- prompt.input << 'no'
24
- prompt.input.rewind
25
- expect(prompt.yes?("Are you a human?")).to eq(false)
26
- expect(prompt.output.string).to eq([
27
- "Are you a human? \e[90m(Y/n)\e[0m ",
28
- "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m n",
29
- "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m no",
30
- "\e[1A\e[2K\e[1G",
31
- "Are you a human? \e[32mno\e[0m\n"
32
- ].join)
33
- end
34
-
35
- it 'assumes default true' do
36
- prompt.input << "\r"
37
- prompt.input.rewind
38
- expect(prompt.yes?("Are you a human?")).to eq(true)
39
- expect(prompt.output.string).to eq([
40
- "Are you a human? \e[90m(Y/n)\e[0m ",
41
- "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m \n",
42
- "\e[1A\e[2K\e[1G",
43
- "Are you a human? \e[32mYes\e[0m\n"
44
- ].join)
45
- end
46
-
47
- it 'changes default' do
48
- prompt.input << "\n"
49
- prompt.input.rewind
50
- expect(prompt.yes?("Are you a human?", default: false)).to eq(false)
51
- expect(prompt.output.string).to eq([
52
- "Are you a human? \e[90m(y/N)\e[0m ",
53
- "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m \n",
54
- "\e[1A\e[2K\e[1G",
55
- "Are you a human? \e[32mNo\e[0m\n"
56
- ].join)
57
- end
58
-
59
- it "defaults suffix and converter" do
60
- prompt.input << "Nope\n"
61
- prompt.input.rewind
62
- result = prompt.yes?("Are you a human?") do |q|
63
- q.positive 'Yup'
64
- q.negative 'nope'
65
- end
66
- expect(result).to eq(false)
67
- expect(prompt.output.string).to eq([
68
- "Are you a human? \e[90m(Yup/nope)\e[0m ",
69
- "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m N",
70
- "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m No",
71
- "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nop",
72
- "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nope",
73
- "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nope\n",
74
- "\e[1A\e[2K\e[1G",
75
- "Are you a human? \e[32mnope\e[0m\n"
76
- ].join)
77
- end
78
-
79
- it "defaults positive and negative" do
80
- prompt.input << "Nope\n"
81
- prompt.input.rewind
82
- result = prompt.yes?("Are you a human?") do |q|
83
- q.suffix 'Yup/nope'
84
- end
85
- expect(result).to eq(false)
86
- expect(prompt.output.string).to eq([
87
- "Are you a human? \e[90m(Yup/nope)\e[0m ",
88
- "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m N",
89
- "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m No",
90
- "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nop",
91
- "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nope",
92
- "\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nope\n",
93
- "\e[1A\e[2K\e[1G",
94
- "Are you a human? \e[32mnope\e[0m\n"
95
- ].join)
96
- end
97
-
98
- it "accepts regex conflicting characters as suffix" do
99
- prompt.input << "]\n"
100
- prompt.input.rewind
101
- result = prompt.yes?("Are you a human? [ as yes and ] as no") do |q|
102
- q.suffix "[/]"
103
- end
104
- expect(result).to eq(false)
105
- expect(prompt.output.string).to eq([
106
- "Are you a human? [ as yes and ] as no \e[90m([/])\e[0m ",
107
- "\e[2K\e[1GAre you a human? [ as yes and ] as no \e[90m([/])\e[0m ]",
108
- "\e[2K\e[1GAre you a human? [ as yes and ] as no \e[90m([/])\e[0m ]\n",
109
- "\e[1A\e[2K\e[1G",
110
- "Are you a human? [ as yes and ] as no \e[32m]\e[0m\n"
111
- ].join)
112
- end
113
-
114
- it "customizes question through options" do
115
- prompt.input << "\r"
116
- prompt.input.rewind
117
- result = prompt.yes?("Are you a human?", suffix: 'Agree/Disagree',
118
- positive: 'Agree', negative: 'Disagree')
119
- expect(result).to eq(true)
120
- expect(prompt.output.string).to eq([
121
- "Are you a human? \e[90m(Agree/Disagree)\e[0m ",
122
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m \n",
123
- "\e[1A\e[2K\e[1G",
124
- "Are you a human? \e[32mAgree\e[0m\n"
125
- ].join)
126
- end
127
-
128
- it "customizes question through DSL" do
129
- prompt.input << "disagree\r"
130
- prompt.input.rewind
131
- conversion = proc { |input| !input.match(/^agree$/i).nil? }
132
- result = prompt.yes?("Are you a human?") do |q|
133
- q.suffix 'Agree/Disagree'
134
- q.positive 'Agree'
135
- q.negative 'Disagree'
136
- q.convert conversion
137
- end
138
- expect(result).to eq(false)
139
- expect(prompt.output.string).to eq([
140
- "Are you a human? \e[90m(Agree/Disagree)\e[0m ",
141
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m d",
142
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m di",
143
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m dis",
144
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disa",
145
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disag",
146
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagr",
147
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagre",
148
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagree",
149
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagree\n",
150
- "\e[1A\e[2K\e[1G",
151
- "Are you a human? \e[32mDisagree\e[0m\n"
152
- ].join)
153
- end
154
- end
155
-
156
- context '#no?' do
157
- it 'agrees with question' do
158
- prompt.input << 'no'
159
- prompt.input.rewind
160
- expect(prompt.no?("Are you a human?")).to eq(true)
161
- expect(prompt.output.string).to eq([
162
- "Are you a human? \e[90m(y/N)\e[0m ",
163
- "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m n",
164
- "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m no",
165
- "\e[1A\e[2K\e[1G",
166
- "Are you a human? \e[32mNo\e[0m\n"
167
- ].join)
168
- end
169
-
170
- it 'disagrees with question' do
171
- prompt.input << 'yes'
172
- prompt.input.rewind
173
- expect(prompt.no?("Are you a human?")).to eq(false)
174
- expect(prompt.output.string).to eq([
175
- "Are you a human? \e[90m(y/N)\e[0m ",
176
- "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m y",
177
- "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m ye",
178
- "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m yes",
179
- "\e[1A\e[2K\e[1G",
180
- "Are you a human? \e[32myes\e[0m\n"
181
- ].join)
182
- end
183
-
184
- it 'assumes default false' do
185
- prompt.input << "\r"
186
- prompt.input.rewind
187
- expect(prompt.no?("Are you a human?")).to eq(true)
188
- expect(prompt.output.string).to eq([
189
- "Are you a human? \e[90m(y/N)\e[0m ",
190
- "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m \n",
191
- "\e[1A\e[2K\e[1G",
192
- "Are you a human? \e[32mNo\e[0m\n"
193
- ].join)
194
- end
195
-
196
- it 'changes default' do
197
- prompt.input << "\r"
198
- prompt.input.rewind
199
- expect(prompt.no?("Are you a human?", default: true)).to eq(false)
200
- expect(prompt.output.string).to eq([
201
- "Are you a human? \e[90m(Y/n)\e[0m ",
202
- "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m \n",
203
- "\e[1A\e[2K\e[1G",
204
- "Are you a human? \e[32mYes\e[0m\n"
205
- ].join)
206
- end
207
-
208
- it "defaults suffix and converter" do
209
- prompt.input << "Yup\n"
210
- prompt.input.rewind
211
- result = prompt.no?("Are you a human?") do |q|
212
- q.positive 'yup'
213
- q.negative 'Nope'
214
- end
215
- expect(result).to eq(false)
216
- expect(prompt.output.string).to eq([
217
- "Are you a human? \e[90m(yup/Nope)\e[0m ",
218
- "\e[2K\e[1GAre you a human? \e[90m(yup/Nope)\e[0m Y",
219
- "\e[2K\e[1GAre you a human? \e[90m(yup/Nope)\e[0m Yu",
220
- "\e[2K\e[1GAre you a human? \e[90m(yup/Nope)\e[0m Yup",
221
- "\e[2K\e[1GAre you a human? \e[90m(yup/Nope)\e[0m Yup\n",
222
- "\e[1A\e[2K\e[1G",
223
- "Are you a human? \e[32myup\e[0m\n"
224
- ].join)
225
- end
226
-
227
- it "customizes question through DSL" do
228
- prompt.input << "agree\r"
229
- prompt.input.rewind
230
- conversion = proc { |input| !input.match(/^agree$/i).nil? }
231
- result = prompt.no?("Are you a human?") do |q|
232
- q.suffix 'Agree/Disagree'
233
- q.positive 'Agree'
234
- q.negative 'Disagree'
235
- q.convert conversion
236
- end
237
- expect(result).to eq(false)
238
- expect(prompt.output.string).to eq([
239
- "Are you a human? \e[90m(Agree/Disagree)\e[0m ",
240
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m a",
241
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m ag",
242
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agr",
243
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agre",
244
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agree",
245
- "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agree\n",
246
- "\e[1A\e[2K\e[1G",
247
- "Are you a human? \e[32mAgree\e[0m\n"
248
- ].join)
249
- end
250
- end
251
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Load gem inside irb console'
4
- task :console do
5
- require 'irb'
6
- require 'irb/completion'
7
- require File.join(__FILE__, '../../lib/tty-prompt')
8
- ARGV.clear
9
- IRB.start
10
- end
11
- task c: %w[ console ]