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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -6
  3. data/CHANGELOG.md +40 -3
  4. data/Gemfile +0 -1
  5. data/README.md +246 -65
  6. data/examples/ask.rb +7 -0
  7. data/examples/echo.rb +7 -0
  8. data/examples/in.rb +7 -0
  9. data/examples/mask.rb +9 -0
  10. data/examples/multi_select.rb +8 -0
  11. data/examples/select.rb +8 -0
  12. data/examples/validation.rb +9 -0
  13. data/examples/yes_no.rb +7 -0
  14. data/lib/tty-prompt.rb +6 -4
  15. data/lib/tty/prompt.rb +100 -25
  16. data/lib/tty/prompt/choice.rb +1 -1
  17. data/lib/tty/prompt/converter_dsl.rb +19 -0
  18. data/lib/tty/prompt/converter_registry.rb +56 -0
  19. data/lib/tty/prompt/converters.rb +77 -0
  20. data/lib/tty/prompt/evaluator.rb +29 -0
  21. data/lib/tty/prompt/list.rb +38 -36
  22. data/lib/tty/prompt/mask_question.rb +85 -0
  23. data/lib/tty/prompt/multi_list.rb +21 -32
  24. data/lib/tty/prompt/question.rb +184 -162
  25. data/lib/tty/prompt/question/checks.rb +85 -0
  26. data/lib/tty/prompt/question/modifier.rb +4 -5
  27. data/lib/tty/prompt/question/validation.rb +29 -35
  28. data/lib/tty/prompt/reader.rb +98 -52
  29. data/lib/tty/prompt/reader/codes.rb +63 -0
  30. data/lib/tty/prompt/reader/key_event.rb +67 -0
  31. data/lib/tty/prompt/reader/mode.rb +66 -0
  32. data/lib/tty/prompt/reader/mode/echo.rb +43 -0
  33. data/lib/tty/prompt/reader/mode/raw.rb +43 -0
  34. data/lib/tty/prompt/result.rb +42 -0
  35. data/lib/tty/prompt/statement.rb +9 -14
  36. data/lib/tty/prompt/suggestion.rb +4 -2
  37. data/lib/tty/prompt/symbols.rb +13 -0
  38. data/lib/tty/prompt/test.rb +3 -2
  39. data/lib/tty/prompt/utils.rb +1 -1
  40. data/lib/tty/prompt/version.rb +1 -1
  41. data/spec/unit/ask_spec.rb +31 -48
  42. data/spec/unit/choice/eql_spec.rb +0 -2
  43. data/spec/unit/choice/from_spec.rb +0 -2
  44. data/spec/unit/choices/add_spec.rb +0 -2
  45. data/spec/unit/choices/each_spec.rb +0 -2
  46. data/spec/unit/choices/new_spec.rb +0 -2
  47. data/spec/unit/choices/pluck_spec.rb +0 -2
  48. data/spec/unit/converters/convert_bool_spec.rb +58 -0
  49. data/spec/unit/{response/read_char_spec.rb → converters/convert_char_spec.rb} +2 -4
  50. data/spec/unit/converters/convert_custom_spec.rb +14 -0
  51. data/spec/unit/converters/convert_date_spec.rb +25 -0
  52. data/spec/unit/converters/convert_file_spec.rb +14 -0
  53. data/spec/unit/{response/read_number_spec.rb → converters/convert_number_spec.rb} +5 -7
  54. data/spec/unit/converters/convert_path_spec.rb +15 -0
  55. data/spec/unit/{response/read_range_spec.rb → converters/convert_range_spec.rb} +3 -5
  56. data/spec/unit/converters/convert_regex_spec.rb +12 -0
  57. data/spec/unit/converters/convert_string_spec.rb +21 -0
  58. data/spec/unit/distance/distance_spec.rb +0 -2
  59. data/spec/unit/error_spec.rb +0 -6
  60. data/spec/unit/evaluator_spec.rb +67 -0
  61. data/spec/unit/keypress_spec.rb +19 -0
  62. data/spec/unit/mask_spec.rb +95 -0
  63. data/spec/unit/multi_select_spec.rb +36 -24
  64. data/spec/unit/multiline_spec.rb +19 -0
  65. data/spec/unit/new_spec.rb +18 -0
  66. data/spec/unit/ok_spec.rb +10 -0
  67. data/spec/unit/question/default_spec.rb +17 -4
  68. data/spec/unit/question/echo_spec.rb +31 -0
  69. data/spec/unit/question/in_spec.rb +48 -16
  70. data/spec/unit/question/initialize_spec.rb +2 -9
  71. data/spec/unit/question/modifier/apply_to_spec.rb +9 -16
  72. data/spec/unit/question/modifier/letter_case_spec.rb +0 -2
  73. data/spec/unit/question/modifier/whitespace_spec.rb +12 -20
  74. data/spec/unit/question/modify_spec.rb +3 -7
  75. data/spec/unit/question/required_spec.rb +20 -14
  76. data/spec/unit/question/validate_spec.rb +20 -19
  77. data/spec/unit/question/validation/call_spec.rb +15 -6
  78. data/spec/unit/question/validation/coerce_spec.rb +17 -11
  79. data/spec/unit/reader/publish_keypress_event_spec.rb +81 -0
  80. data/spec/unit/reader/read_keypress_spec.rb +22 -0
  81. data/spec/unit/reader/read_line_spec.rb +31 -0
  82. data/spec/unit/reader/read_multiline_spec.rb +37 -0
  83. data/spec/unit/result_spec.rb +40 -0
  84. data/spec/unit/say_spec.rb +18 -23
  85. data/spec/unit/select_spec.rb +37 -32
  86. data/spec/unit/statement/initialize_spec.rb +4 -4
  87. data/spec/unit/suggest_spec.rb +0 -2
  88. data/spec/unit/warn_spec.rb +0 -5
  89. data/spec/unit/yes_no_spec.rb +70 -0
  90. data/tty-prompt.gemspec +7 -4
  91. metadata +123 -40
  92. data/lib/tty/prompt/codes.rb +0 -32
  93. data/lib/tty/prompt/cursor.rb +0 -131
  94. data/lib/tty/prompt/error.rb +0 -26
  95. data/lib/tty/prompt/mode.rb +0 -64
  96. data/lib/tty/prompt/mode/echo.rb +0 -41
  97. data/lib/tty/prompt/mode/raw.rb +0 -41
  98. data/lib/tty/prompt/response.rb +0 -247
  99. data/lib/tty/prompt/response_delegation.rb +0 -42
  100. data/spec/unit/cursor/new_spec.rb +0 -74
  101. data/spec/unit/question/character_spec.rb +0 -13
  102. data/spec/unit/reader/getc_spec.rb +0 -42
  103. data/spec/unit/response/read_bool_spec.rb +0 -58
  104. data/spec/unit/response/read_date_spec.rb +0 -16
  105. data/spec/unit/response/read_email_spec.rb +0 -45
  106. data/spec/unit/response/read_multiple_spec.rb +0 -21
  107. data/spec/unit/response/read_spec.rb +0 -69
  108. data/spec/unit/response/read_string_spec.rb +0 -14
@@ -1,62 +1,57 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  RSpec.describe TTY::Prompt, '#say' do
6
- let(:color) { Pastel.new(enabled: true) }
7
4
 
8
5
  subject(:prompt) { TTY::TestPrompt.new }
9
6
 
10
- before { allow(Pastel).to receive(:new).and_return(color) }
11
-
12
7
  it 'prints an empty message' do
13
- prompt.say ""
14
- expect(prompt.output.string).to eql ""
8
+ prompt.say('')
9
+ expect(prompt.output.string).to eq('')
15
10
  end
16
11
 
17
12
  context 'with new line' do
18
13
  it 'prints a message with newline' do
19
- prompt.say "Hell yeah!\n"
20
- expect(prompt.output.string).to eql "Hell yeah!\n"
14
+ prompt.say("Hell yeah!\n")
15
+ expect(prompt.output.string).to eq("Hell yeah!\n")
21
16
  end
22
17
 
23
18
  it 'prints a message with implicit newline' do
24
- prompt.say "Hell yeah!\n"
25
- expect(prompt.output.string).to eql "Hell yeah!\n"
19
+ prompt.say("Hell yeah!\n")
20
+ expect(prompt.output.string).to eq("Hell yeah!\n")
26
21
  end
27
22
 
28
23
  it 'prints a message with newline within text' do
29
- prompt.say "Hell\n yeah!"
30
- expect(prompt.output.string).to eql "Hell\n yeah!\n"
24
+ prompt.say("Hell\n yeah!")
25
+ expect(prompt.output.string).to eq("Hell\n yeah!\n")
31
26
  end
32
27
 
33
28
  it 'prints a message with newline within text and blank space' do
34
- prompt.say "Hell\n yeah! "
35
- expect(prompt.output.string).to eql "Hell\n yeah! "
29
+ prompt.say("Hell\n yeah! ")
30
+ expect(prompt.output.string).to eq("Hell\n yeah! ")
36
31
  end
37
32
 
38
33
  it 'prints a message without newline' do
39
- prompt.say "Hell yeah!", newline: false
40
- expect(prompt.output.string).to eql "Hell yeah!"
34
+ prompt.say("Hell yeah!", newline: false)
35
+ expect(prompt.output.string).to eq("Hell yeah!")
41
36
  end
42
37
  end
43
38
 
44
39
  context 'with tab or space' do
45
40
  it 'prints ' do
46
- prompt.say "Hell yeah!\t"
47
- expect(prompt.output.string).to eql "Hell yeah!\t"
41
+ prompt.say("Hell yeah!\t")
42
+ expect(prompt.output.string).to eq("Hell yeah!\t")
48
43
  end
49
44
  end
50
45
 
51
46
  context 'with color' do
52
47
  it 'prints message with ansi color' do
53
- prompt.say "Hell yeah!", color: :green
54
- expect(prompt.output.string).to eql "\e[32mHell yeah!\e[0m\n"
48
+ prompt.say('Hell yeah!', color: :green)
49
+ expect(prompt.output.string).to eq("\e[32mHell yeah!\e[0m\n")
55
50
  end
56
51
 
57
52
  it 'prints message with ansi color without newline' do
58
- prompt.say "Hell yeah! ", color: :green
59
- expect(prompt.output.string).to eql "\e[32mHell yeah! \e[0m"
53
+ prompt.say('Hell yeah! ', color: :green)
54
+ expect(prompt.output.string).to eq("\e[32mHell yeah! \e[0m")
60
55
  end
61
56
  end
62
57
  end
@@ -3,12 +3,10 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe TTY::Prompt, '#select' do
6
- let(:color) { Pastel.new(enabled: true) }
7
6
 
8
- before { allow(Pastel).to receive(:new).and_return(color) }
7
+ subject(:prompt) { TTY::TestPrompt.new }
9
8
 
10
9
  it "selects by default first option" do
11
- prompt = TTY::TestPrompt.new
12
10
  choices = %w(Large Medium Small)
13
11
  prompt.input << "\r"
14
12
  prompt.input.rewind
@@ -17,14 +15,13 @@ RSpec.describe TTY::Prompt, '#select' do
17
15
  "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
18
16
  "\e[32m‣ Large\e[0m\n",
19
17
  " Medium\n",
20
- " Small\n",
21
- "\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
18
+ " Small",
19
+ "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
22
20
  "What size? \e[32mLarge\e[0m\n\e[?25h"
23
21
  ].join)
24
22
  end
25
23
 
26
24
  it "sets choice name and value" do
27
- prompt = TTY::TestPrompt.new
28
25
  choices = {large: 1, medium: 2, small: 3}
29
26
  prompt.input << " "
30
27
  prompt.input.rewind
@@ -33,14 +30,13 @@ RSpec.describe TTY::Prompt, '#select' do
33
30
  "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
34
31
  "\e[32m‣ large\e[0m\n",
35
32
  " medium\n",
36
- " small\n",
37
- "\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
33
+ " small",
34
+ "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
38
35
  "What size? \e[32mlarge\e[0m\n\e[?25h"
39
36
  ].join)
40
37
  end
41
38
 
42
39
  it "sets choice name through DSL" do
43
- prompt = TTY::TestPrompt.new
44
40
  prompt.input << " "
45
41
  prompt.input.rewind
46
42
  value = prompt.select('What size?') do |menu|
@@ -53,14 +49,13 @@ RSpec.describe TTY::Prompt, '#select' do
53
49
  "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
54
50
  "\e[32m‣ Large\e[0m\n",
55
51
  " Medium\n",
56
- " Small\n",
57
- "\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
52
+ " Small",
53
+ "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
58
54
  "What size? \e[32mLarge\e[0m\n\e[?25h"
59
55
  ].join)
60
56
  end
61
57
 
62
58
  it "sets choice name & value through DSL" do
63
- prompt = TTY::TestPrompt.new
64
59
  prompt.input << " "
65
60
  prompt.input.rewind
66
61
  value = prompt.select('What size?') do |menu|
@@ -73,14 +68,13 @@ RSpec.describe TTY::Prompt, '#select' do
73
68
  "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
74
69
  "\e[32m‣ large\e[0m\n",
75
70
  " medium\n",
76
- " small\n",
77
- "\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
71
+ " small",
72
+ "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
78
73
  "What size? \e[32mlarge\e[0m\n\e[?25h"
79
74
  ].join)
80
75
  end
81
76
 
82
77
  it "sets choices and single choice through DSL" do
83
- prompt = TTY::TestPrompt.new
84
78
  prompt.input << " "
85
79
  prompt.input.rewind
86
80
  value = prompt.select('What size?') do |menu|
@@ -92,14 +86,13 @@ RSpec.describe TTY::Prompt, '#select' do
92
86
  "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
93
87
  "\e[32m‣ Large\e[0m\n",
94
88
  " Medium\n",
95
- " Small\n",
96
- "\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
89
+ " Small",
90
+ "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
97
91
  "What size? \e[32mLarge\e[0m\n\e[?25h"
98
92
  ].join)
99
93
  end
100
94
 
101
95
  it "sets choice name & value through DSL" do
102
- prompt = TTY::TestPrompt.new
103
96
  prompt.input << " "
104
97
  prompt.input.rewind
105
98
  value = prompt.select('What size?') do |menu|
@@ -114,14 +107,13 @@ RSpec.describe TTY::Prompt, '#select' do
114
107
  "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
115
108
  " large\n",
116
109
  "\e[32m‣ medium\e[0m\n",
117
- " small\n",
118
- "\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
110
+ " small",
111
+ "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
119
112
  "What size? \e[32mmedium\e[0m\n\e[?25h"
120
113
  ].join)
121
114
  end
122
115
 
123
116
  it "sets choice value to proc and executes it" do
124
- prompt = TTY::TestPrompt.new
125
117
  prompt.input << " "
126
118
  prompt.input.rewind
127
119
  value = prompt.select('What size?', default: 2) do |menu|
@@ -134,14 +126,13 @@ RSpec.describe TTY::Prompt, '#select' do
134
126
  "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
135
127
  " large\n",
136
128
  "\e[32m‣ medium\e[0m\n",
137
- " small\n",
138
- "\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
129
+ " small",
130
+ "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
139
131
  "What size? \e[32mmedium\e[0m\n\e[?25h"
140
132
  ].join)
141
133
  end
142
134
 
143
135
  it "sets default option through hash syntax" do
144
- prompt = TTY::TestPrompt.new
145
136
  choices = %w(Large Medium Small)
146
137
  prompt.input << " "
147
138
  prompt.input.rewind
@@ -150,14 +141,13 @@ RSpec.describe TTY::Prompt, '#select' do
150
141
  "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
151
142
  " Large\n",
152
143
  "\e[32m‣ Medium\e[0m\n",
153
- " Small\n",
154
- "\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
144
+ " Small",
145
+ "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
155
146
  "What size? \e[32mMedium\e[0m\n\e[?25h"
156
147
  ].join)
157
148
  end
158
149
 
159
150
  it "changes selected item color & marker" do
160
- prompt = TTY::TestPrompt.new
161
151
  choices = %w(Large Medium Small)
162
152
  prompt.input << " "
163
153
  prompt.input.rewind
@@ -167,14 +157,13 @@ RSpec.describe TTY::Prompt, '#select' do
167
157
  "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
168
158
  "\e[34m> Large\e[0m\n",
169
159
  " Medium\n",
170
- " Small\n",
171
- "\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
160
+ " Small",
161
+ "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
172
162
  "What size? \e[34mLarge\e[0m\n\e[?25h"
173
163
  ].join)
174
164
  end
175
165
 
176
166
  it "changes help text" do
177
- prompt = TTY::TestPrompt.new
178
167
  choices = %w(Large Medium Small)
179
168
  prompt.input << " "
180
169
  prompt.input.rewind
@@ -184,9 +173,25 @@ RSpec.describe TTY::Prompt, '#select' do
184
173
  "\e[?25lWhat size? \e[90m(Bash keyboard)\e[0m\n",
185
174
  "\e[32m‣ Large\e[0m\n",
186
175
  " Medium\n",
187
- " Small\n",
188
- "\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
176
+ " Small",
177
+ "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
189
178
  "What size? \e[32mLarge\e[0m\n\e[?25h"
190
179
  ].join)
191
180
  end
181
+
182
+ it "sets prompt prefix" do
183
+ prompt = TTY::TestPrompt.new(prefix: '[?] ')
184
+ choices = %w(Large Medium Small)
185
+ prompt.input << "\r"
186
+ prompt.input.rewind
187
+ expect(prompt.select('What size?', choices)).to eq('Large')
188
+ expect(prompt.output.string).to eq([
189
+ "\e[?25l[?] What size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n",
190
+ "\e[32m‣ Large\e[0m\n",
191
+ " Medium\n",
192
+ " Small",
193
+ "\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K\e[1A\e[1000D\e[K",
194
+ "[?] What size? \e[32mLarge\e[0m\n\e[?25h"
195
+ ].join)
196
+ end
192
197
  end
@@ -1,15 +1,15 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  RSpec.describe TTY::Prompt::Statement, '#new' do
6
4
  it "forces newline after the prompt message" do
7
- statement = described_class.new
5
+ prompt = TTY::TestPrompt.new
6
+ statement = described_class.new(prompt)
8
7
  expect(statement.newline).to eq(true)
9
8
  end
10
9
 
11
10
  it "displays prompt message in color" do
12
- statement = described_class.new
11
+ prompt = TTY::TestPrompt.new
12
+ statement = described_class.new(prompt)
13
13
  expect(statement.color).to eq(false)
14
14
  end
15
15
  end
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  RSpec.describe TTY::Prompt, '#suggest' do
6
4
  let(:possible) { %w(status stage stash commit branch blame) }
7
5
 
@@ -1,14 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  RSpec.describe TTY::Prompt, '#warn' do
6
- let(:color) { Pastel.new(enabled: true) }
7
4
 
8
5
  subject(:prompt) { TTY::TestPrompt.new }
9
6
 
10
- before { allow(Pastel).to receive(:new).and_return(color) }
11
-
12
7
  it 'displays one message' do
13
8
  prompt.warn "Careful young apprentice!"
14
9
  expect(prompt.output.string).to eql "\e[33mCareful young apprentice!\e[0m\n"
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ RSpec.describe TTY::Prompt, '#yes?' do
4
+
5
+ subject(:prompt) { TTY::TestPrompt.new }
6
+
7
+ context 'yes?' do
8
+ it 'agrees' 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[1000D\e[K\e[1A",
15
+ "\e[1000D\e[K",
16
+ "Are you a human? \e[32myes\e[0m\n"
17
+ ].join)
18
+ end
19
+
20
+ it 'disagrees' do
21
+ prompt.input << 'no'
22
+ prompt.input.rewind
23
+ expect(prompt.yes?("Are you a human?")).to eq(false)
24
+ expect(prompt.output.string).to eq([
25
+ "Are you a human? \e[90m(Y/n)\e[0m ",
26
+ "\e[1000D\e[K\e[1A",
27
+ "\e[1000D\e[K",
28
+ "Are you a human? \e[32mno\e[0m\n"
29
+ ].join)
30
+ end
31
+
32
+ it 'assumes default true' do
33
+ prompt.input << "\r"
34
+ prompt.input.rewind
35
+ expect(prompt.yes?("Are you a human?", default: true)).to eq(true)
36
+ expect(prompt.output.string).to eq([
37
+ "Are you a human? \e[90m(Y/n)\e[0m ",
38
+ "\e[1000D\e[K\e[1A",
39
+ "\e[1000D\e[K",
40
+ "Are you a human? \e[32mtrue\e[0m\n"
41
+ ].join)
42
+ end
43
+ end
44
+
45
+ context 'no?' do
46
+ it 'disagrees' do
47
+ prompt.input << 'no'
48
+ prompt.input.rewind
49
+ expect(prompt.no?("Are you a human?")).to eq(true)
50
+ expect(prompt.output.string).to eq([
51
+ "Are you a human? \e[90m(Y/n)\e[0m ",
52
+ "\e[1000D\e[K\e[1A",
53
+ "\e[1000D\e[K",
54
+ "Are you a human? \e[32mno\e[0m\n"
55
+ ].join)
56
+ end
57
+
58
+ it 'agrees' do
59
+ prompt.input << 'yes'
60
+ prompt.input.rewind
61
+ expect(prompt.no?("Are you a human?")).to eq(false)
62
+ expect(prompt.output.string).to eq([
63
+ "Are you a human? \e[90m(Y/n)\e[0m ",
64
+ "\e[1000D\e[K\e[1A",
65
+ "\e[1000D\e[K",
66
+ "Are you a human? \e[32myes\e[0m\n"
67
+ ].join)
68
+ end
69
+ end
70
+ end
data/tty-prompt.gemspec CHANGED
@@ -18,9 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "necromancer", "~> 0.3.0"
22
- spec.add_dependency "pastel", "~> 0.5.1"
23
- spec.add_dependency "tty-platform", "~> 0.1.0"
21
+ spec.add_dependency 'necromancer', '~> 0.3.0'
22
+ spec.add_dependency 'pastel', '~> 0.5.2'
23
+ spec.add_dependency 'tty-cursor', '~> 0.2.0'
24
+ spec.add_dependency 'tty-platform', '~> 0.1.0'
25
+ spec.add_dependency 'wisper', '~> 1.6.1'
24
26
 
25
- spec.add_development_dependency "bundler", "~> 1.6"
27
+ spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
28
+ spec.add_development_dependency 'rake'
26
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-prompt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-23 00:00:00.000000000 Z
11
+ date: 2015-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: necromancer
@@ -30,14 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.1
33
+ version: 0.5.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.1
40
+ version: 0.5.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-cursor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: tty-platform
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +67,53 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: 0.1.0
55
69
  - !ruby/object:Gem::Dependency
56
- name: bundler
70
+ name: wisper
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ~>
60
74
  - !ruby/object:Gem::Version
61
- version: '1.6'
62
- type: :development
75
+ version: 1.6.1
76
+ type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - ~>
67
81
  - !ruby/object:Gem::Version
68
- version: '1.6'
82
+ version: 1.6.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.5.0
90
+ - - <
91
+ - !ruby/object:Gem::Version
92
+ version: '2.0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: 1.5.0
100
+ - - <
101
+ - !ruby/object:Gem::Version
102
+ version: '2.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
69
117
  description: A beautiful and powerful interactive command line prompt with a robust
70
118
  API for getting and validating complex inputs.
71
119
  email:
@@ -83,28 +131,41 @@ files:
83
131
  - LICENSE.txt
84
132
  - README.md
85
133
  - Rakefile
134
+ - examples/ask.rb
135
+ - examples/echo.rb
136
+ - examples/in.rb
137
+ - examples/mask.rb
138
+ - examples/multi_select.rb
139
+ - examples/select.rb
140
+ - examples/validation.rb
141
+ - examples/yes_no.rb
86
142
  - lib/tty-prompt.rb
87
143
  - lib/tty/prompt.rb
88
144
  - lib/tty/prompt/choice.rb
89
145
  - lib/tty/prompt/choices.rb
90
- - lib/tty/prompt/codes.rb
91
- - lib/tty/prompt/cursor.rb
146
+ - lib/tty/prompt/converter_dsl.rb
147
+ - lib/tty/prompt/converter_registry.rb
148
+ - lib/tty/prompt/converters.rb
92
149
  - lib/tty/prompt/distance.rb
93
- - lib/tty/prompt/error.rb
150
+ - lib/tty/prompt/evaluator.rb
94
151
  - lib/tty/prompt/history.rb
95
152
  - lib/tty/prompt/list.rb
96
- - lib/tty/prompt/mode.rb
97
- - lib/tty/prompt/mode/echo.rb
98
- - lib/tty/prompt/mode/raw.rb
153
+ - lib/tty/prompt/mask_question.rb
99
154
  - lib/tty/prompt/multi_list.rb
100
155
  - lib/tty/prompt/question.rb
156
+ - lib/tty/prompt/question/checks.rb
101
157
  - lib/tty/prompt/question/modifier.rb
102
158
  - lib/tty/prompt/question/validation.rb
103
159
  - lib/tty/prompt/reader.rb
104
- - lib/tty/prompt/response.rb
105
- - lib/tty/prompt/response_delegation.rb
160
+ - lib/tty/prompt/reader/codes.rb
161
+ - lib/tty/prompt/reader/key_event.rb
162
+ - lib/tty/prompt/reader/mode.rb
163
+ - lib/tty/prompt/reader/mode/echo.rb
164
+ - lib/tty/prompt/reader/mode/raw.rb
165
+ - lib/tty/prompt/result.rb
106
166
  - lib/tty/prompt/statement.rb
107
167
  - lib/tty/prompt/suggestion.rb
168
+ - lib/tty/prompt/symbols.rb
108
169
  - lib/tty/prompt/test.rb
109
170
  - lib/tty/prompt/utils.rb
110
171
  - lib/tty/prompt/version.rb
@@ -116,12 +177,27 @@ files:
116
177
  - spec/unit/choices/each_spec.rb
117
178
  - spec/unit/choices/new_spec.rb
118
179
  - spec/unit/choices/pluck_spec.rb
119
- - spec/unit/cursor/new_spec.rb
180
+ - spec/unit/converters/convert_bool_spec.rb
181
+ - spec/unit/converters/convert_char_spec.rb
182
+ - spec/unit/converters/convert_custom_spec.rb
183
+ - spec/unit/converters/convert_date_spec.rb
184
+ - spec/unit/converters/convert_file_spec.rb
185
+ - spec/unit/converters/convert_number_spec.rb
186
+ - spec/unit/converters/convert_path_spec.rb
187
+ - spec/unit/converters/convert_range_spec.rb
188
+ - spec/unit/converters/convert_regex_spec.rb
189
+ - spec/unit/converters/convert_string_spec.rb
120
190
  - spec/unit/distance/distance_spec.rb
121
191
  - spec/unit/error_spec.rb
192
+ - spec/unit/evaluator_spec.rb
193
+ - spec/unit/keypress_spec.rb
194
+ - spec/unit/mask_spec.rb
122
195
  - spec/unit/multi_select_spec.rb
123
- - spec/unit/question/character_spec.rb
196
+ - spec/unit/multiline_spec.rb
197
+ - spec/unit/new_spec.rb
198
+ - spec/unit/ok_spec.rb
124
199
  - spec/unit/question/default_spec.rb
200
+ - spec/unit/question/echo_spec.rb
125
201
  - spec/unit/question/in_spec.rb
126
202
  - spec/unit/question/initialize_spec.rb
127
203
  - spec/unit/question/modifier/apply_to_spec.rb
@@ -132,21 +208,17 @@ files:
132
208
  - spec/unit/question/validate_spec.rb
133
209
  - spec/unit/question/validation/call_spec.rb
134
210
  - spec/unit/question/validation/coerce_spec.rb
135
- - spec/unit/reader/getc_spec.rb
136
- - spec/unit/response/read_bool_spec.rb
137
- - spec/unit/response/read_char_spec.rb
138
- - spec/unit/response/read_date_spec.rb
139
- - spec/unit/response/read_email_spec.rb
140
- - spec/unit/response/read_multiple_spec.rb
141
- - spec/unit/response/read_number_spec.rb
142
- - spec/unit/response/read_range_spec.rb
143
- - spec/unit/response/read_spec.rb
144
- - spec/unit/response/read_string_spec.rb
211
+ - spec/unit/reader/publish_keypress_event_spec.rb
212
+ - spec/unit/reader/read_keypress_spec.rb
213
+ - spec/unit/reader/read_line_spec.rb
214
+ - spec/unit/reader/read_multiline_spec.rb
215
+ - spec/unit/result_spec.rb
145
216
  - spec/unit/say_spec.rb
146
217
  - spec/unit/select_spec.rb
147
218
  - spec/unit/statement/initialize_spec.rb
148
219
  - spec/unit/suggest_spec.rb
149
220
  - spec/unit/warn_spec.rb
221
+ - spec/unit/yes_no_spec.rb
150
222
  - tasks/console.rake
151
223
  - tasks/coverage.rake
152
224
  - tasks/spec.rake
@@ -184,12 +256,27 @@ test_files:
184
256
  - spec/unit/choices/each_spec.rb
185
257
  - spec/unit/choices/new_spec.rb
186
258
  - spec/unit/choices/pluck_spec.rb
187
- - spec/unit/cursor/new_spec.rb
259
+ - spec/unit/converters/convert_bool_spec.rb
260
+ - spec/unit/converters/convert_char_spec.rb
261
+ - spec/unit/converters/convert_custom_spec.rb
262
+ - spec/unit/converters/convert_date_spec.rb
263
+ - spec/unit/converters/convert_file_spec.rb
264
+ - spec/unit/converters/convert_number_spec.rb
265
+ - spec/unit/converters/convert_path_spec.rb
266
+ - spec/unit/converters/convert_range_spec.rb
267
+ - spec/unit/converters/convert_regex_spec.rb
268
+ - spec/unit/converters/convert_string_spec.rb
188
269
  - spec/unit/distance/distance_spec.rb
189
270
  - spec/unit/error_spec.rb
271
+ - spec/unit/evaluator_spec.rb
272
+ - spec/unit/keypress_spec.rb
273
+ - spec/unit/mask_spec.rb
190
274
  - spec/unit/multi_select_spec.rb
191
- - spec/unit/question/character_spec.rb
275
+ - spec/unit/multiline_spec.rb
276
+ - spec/unit/new_spec.rb
277
+ - spec/unit/ok_spec.rb
192
278
  - spec/unit/question/default_spec.rb
279
+ - spec/unit/question/echo_spec.rb
193
280
  - spec/unit/question/in_spec.rb
194
281
  - spec/unit/question/initialize_spec.rb
195
282
  - spec/unit/question/modifier/apply_to_spec.rb
@@ -200,19 +287,15 @@ test_files:
200
287
  - spec/unit/question/validate_spec.rb
201
288
  - spec/unit/question/validation/call_spec.rb
202
289
  - spec/unit/question/validation/coerce_spec.rb
203
- - spec/unit/reader/getc_spec.rb
204
- - spec/unit/response/read_bool_spec.rb
205
- - spec/unit/response/read_char_spec.rb
206
- - spec/unit/response/read_date_spec.rb
207
- - spec/unit/response/read_email_spec.rb
208
- - spec/unit/response/read_multiple_spec.rb
209
- - spec/unit/response/read_number_spec.rb
210
- - spec/unit/response/read_range_spec.rb
211
- - spec/unit/response/read_spec.rb
212
- - spec/unit/response/read_string_spec.rb
290
+ - spec/unit/reader/publish_keypress_event_spec.rb
291
+ - spec/unit/reader/read_keypress_spec.rb
292
+ - spec/unit/reader/read_line_spec.rb
293
+ - spec/unit/reader/read_multiline_spec.rb
294
+ - spec/unit/result_spec.rb
213
295
  - spec/unit/say_spec.rb
214
296
  - spec/unit/select_spec.rb
215
297
  - spec/unit/statement/initialize_spec.rb
216
298
  - spec/unit/suggest_spec.rb
217
299
  - spec/unit/warn_spec.rb
300
+ - spec/unit/yes_no_spec.rb
218
301
  has_rdoc: