rye 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/CHANGES.txt +6 -0
  2. data/README.rdoc +5 -7
  3. data/bin/rye +3 -3
  4. data/lib/rye.rb +1 -1
  5. data/lib/rye/box.rb +1 -1
  6. data/rye.gemspec +31 -1
  7. data/vendor/highline-1.5.1/CHANGELOG +222 -0
  8. data/vendor/highline-1.5.1/INSTALL +35 -0
  9. data/vendor/highline-1.5.1/LICENSE +7 -0
  10. data/vendor/highline-1.5.1/README +63 -0
  11. data/vendor/highline-1.5.1/Rakefile +82 -0
  12. data/vendor/highline-1.5.1/TODO +6 -0
  13. data/vendor/highline-1.5.1/examples/ansi_colors.rb +38 -0
  14. data/vendor/highline-1.5.1/examples/asking_for_arrays.rb +18 -0
  15. data/vendor/highline-1.5.1/examples/basic_usage.rb +75 -0
  16. data/vendor/highline-1.5.1/examples/color_scheme.rb +32 -0
  17. data/vendor/highline-1.5.1/examples/limit.rb +12 -0
  18. data/vendor/highline-1.5.1/examples/menus.rb +65 -0
  19. data/vendor/highline-1.5.1/examples/overwrite.rb +19 -0
  20. data/vendor/highline-1.5.1/examples/page_and_wrap.rb +322 -0
  21. data/vendor/highline-1.5.1/examples/password.rb +7 -0
  22. data/vendor/highline-1.5.1/examples/trapping_eof.rb +22 -0
  23. data/vendor/highline-1.5.1/examples/using_readline.rb +17 -0
  24. data/vendor/highline-1.5.1/lib/highline.rb +758 -0
  25. data/vendor/highline-1.5.1/lib/highline/color_scheme.rb +120 -0
  26. data/vendor/highline-1.5.1/lib/highline/compatibility.rb +17 -0
  27. data/vendor/highline-1.5.1/lib/highline/import.rb +43 -0
  28. data/vendor/highline-1.5.1/lib/highline/menu.rb +395 -0
  29. data/vendor/highline-1.5.1/lib/highline/question.rb +463 -0
  30. data/vendor/highline-1.5.1/lib/highline/system_extensions.rb +193 -0
  31. data/vendor/highline-1.5.1/setup.rb +1360 -0
  32. data/vendor/highline-1.5.1/test/tc_color_scheme.rb +56 -0
  33. data/vendor/highline-1.5.1/test/tc_highline.rb +823 -0
  34. data/vendor/highline-1.5.1/test/tc_import.rb +54 -0
  35. data/vendor/highline-1.5.1/test/tc_menu.rb +429 -0
  36. data/vendor/highline-1.5.1/test/ts_all.rb +15 -0
  37. metadata +31 -1
@@ -0,0 +1,54 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ # tc_import.rb
4
+ #
5
+ # Created by James Edward Gray II on 2005-04-26.
6
+ # Copyright 2005 Gray Productions. All rights reserved.
7
+ #
8
+ # This is Free Software. See LICENSE and COPYING for details.
9
+
10
+ require "test/unit"
11
+
12
+ require "highline/import"
13
+ require "stringio"
14
+
15
+ class TestImport < Test::Unit::TestCase
16
+ def test_import
17
+ assert_respond_to(self, :agree)
18
+ assert_respond_to(self, :ask)
19
+ assert_respond_to(self, :choose)
20
+ assert_respond_to(self, :say)
21
+ end
22
+
23
+ def test_or_ask
24
+ old_terminal = $terminal
25
+
26
+ input = StringIO.new
27
+ output = StringIO.new
28
+ $terminal = HighLine.new(input, output)
29
+
30
+ input << "10\n"
31
+ input.rewind
32
+
33
+ assert_equal(10, nil.or_ask("How much? ", Integer))
34
+
35
+ input.rewind
36
+
37
+ assert_equal(20, "20".or_ask("How much? ", Integer))
38
+ assert_equal(20, 20.or_ask("How much? ", Integer))
39
+
40
+ assert_equal(10, 20.or_ask("How much? ", Integer) { |q| q.in = 1..10 })
41
+ ensure
42
+ $terminal = old_terminal
43
+ end
44
+
45
+ def test_redirection
46
+ old_terminal = $terminal
47
+
48
+ $terminal = HighLine.new(nil, (output = StringIO.new))
49
+ say("Testing...")
50
+ assert_equal("Testing...\n", output.string)
51
+ ensure
52
+ $terminal = old_terminal
53
+ end
54
+ end
@@ -0,0 +1,429 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ # tc_menu.rb
4
+ #
5
+ # Created by Gregory Thomas Brown on 2005-05-10.
6
+ # Copyright 2005. All rights reserved.
7
+ #
8
+ # This is Free Software. See LICENSE and COPYING for details.
9
+
10
+ require "test/unit"
11
+
12
+ require "highline"
13
+ require "stringio"
14
+
15
+ class TestMenu < Test::Unit::TestCase
16
+ def setup
17
+ @input = StringIO.new
18
+ @output = StringIO.new
19
+ @terminal = HighLine.new(@input, @output)
20
+ end
21
+
22
+ def test_choices
23
+ @input << "2\n"
24
+ @input.rewind
25
+
26
+ output = @terminal.choose do |menu|
27
+ menu.choices("Sample1", "Sample2", "Sample3")
28
+ end
29
+ assert_equal("Sample2", output)
30
+ end
31
+
32
+ def test_flow
33
+ @input << "Sample1\n"
34
+ @input.rewind
35
+
36
+ @terminal.choose do |menu|
37
+ # Default: menu.flow = :rows
38
+
39
+ menu.choice "Sample1"
40
+ menu.choice "Sample2"
41
+ menu.choice "Sample3"
42
+ end
43
+ assert_equal("1. Sample1\n2. Sample2\n3. Sample3\n? ", @output.string)
44
+
45
+ @output.truncate(@output.rewind)
46
+ @input.rewind
47
+
48
+ @terminal.choose do |menu|
49
+ menu.flow = :columns_across
50
+
51
+ menu.choice "Sample1"
52
+ menu.choice "Sample2"
53
+ menu.choice "Sample3"
54
+ end
55
+ assert_equal("1. Sample1 2. Sample2 3. Sample3\n? ", @output.string)
56
+
57
+ @output.truncate(@output.rewind)
58
+ @input.rewind
59
+
60
+ @terminal.choose do |menu|
61
+ menu.flow = :inline
62
+ menu.index = :none
63
+
64
+ menu.choice "Sample1"
65
+ menu.choice "Sample2"
66
+ menu.choice "Sample3"
67
+ end
68
+ assert_equal("Sample1, Sample2 or Sample3? ", @output.string)
69
+ end
70
+
71
+ def test_help
72
+ @input << "help\nhelp load\nhelp rules\nhelp missing\n"
73
+ @input.rewind
74
+
75
+ 4.times do
76
+ @terminal.choose do |menu|
77
+ menu.shell = true
78
+
79
+ menu.choice(:load, "Load a file.")
80
+ menu.choice(:save, "Save data in file.")
81
+ menu.choice(:quit, "Exit program.")
82
+
83
+ menu.help("rules", "The rules of this system are as follows...")
84
+ end
85
+ end
86
+ assert_equal( "1. load\n2. save\n3. quit\n4. help\n? " +
87
+ "This command will display helpful messages about " +
88
+ "functionality, like this one. To see the help for a " +
89
+ "specific topic enter:\n" +
90
+ "\thelp [TOPIC]\n" +
91
+ "Try asking for help on any of the following:\n" +
92
+ "\nload quit rules save \n" +
93
+ "1. load\n2. save\n3. quit\n4. help\n? " +
94
+ "= load\n\n" +
95
+ "Load a file.\n" +
96
+ "1. load\n2. save\n3. quit\n4. help\n? " +
97
+ "= rules\n\n" +
98
+ "The rules of this system are as follows...\n" +
99
+ "1. load\n2. save\n3. quit\n4. help\n? " +
100
+ "= missing\n\n" +
101
+ "There's no help for that topic.\n", @output.string )
102
+ end
103
+
104
+ def test_index
105
+ @input << "Sample1\n"
106
+ @input.rewind
107
+
108
+ @terminal.choose do |menu|
109
+ # Default: menu.index = :number
110
+
111
+ menu.choice "Sample1"
112
+ menu.choice "Sample2"
113
+ menu.choice "Sample3"
114
+ end
115
+ assert_equal("1. Sample1\n2. Sample2\n3. Sample3\n? ", @output.string)
116
+
117
+ @output.truncate(@output.rewind)
118
+ @input.rewind
119
+
120
+ @terminal.choose do |menu|
121
+ menu.index = :letter
122
+ menu.index_suffix = ") "
123
+
124
+ menu.choice "Sample1"
125
+ menu.choice "Sample2"
126
+ menu.choice "Sample3"
127
+ end
128
+ assert_equal("a) Sample1\nb) Sample2\nc) Sample3\n? ", @output.string)
129
+
130
+ @output.truncate(@output.rewind)
131
+ @input.rewind
132
+
133
+ @terminal.choose do |menu|
134
+ menu.index = :none
135
+
136
+ menu.choice "Sample1"
137
+ menu.choice "Sample2"
138
+ menu.choice "Sample3"
139
+ end
140
+ assert_equal("Sample1\nSample2\nSample3\n? ", @output.string)
141
+
142
+ @output.truncate(@output.rewind)
143
+ @input.rewind
144
+
145
+ @terminal.choose do |menu|
146
+ menu.index = "*"
147
+
148
+ menu.choice "Sample1"
149
+ menu.choice "Sample2"
150
+ menu.choice "Sample3"
151
+ end
152
+ assert_equal("* Sample1\n* Sample2\n* Sample3\n? ", @output.string)
153
+ end
154
+
155
+ def test_layouts
156
+ @input << "save\n"
157
+ @input.rewind
158
+
159
+ @terminal.choose(:load, :save, :quit) # Default: layout = :list
160
+ assert_equal("1. load\n2. save\n3. quit\n? ", @output.string)
161
+
162
+ @input.rewind
163
+ @output.truncate(@output.rewind)
164
+
165
+ @terminal.choose(:load, :save, :quit) do |menu|
166
+ menu.header = "File Menu"
167
+ end
168
+ assert_equal( "File Menu:\n" +
169
+ "1. load\n2. save\n3. quit\n? ", @output.string )
170
+
171
+ @input.rewind
172
+ @output.truncate(@output.rewind)
173
+
174
+ @terminal.choose(:load, :save, :quit) do |menu|
175
+ menu.layout = :one_line
176
+ menu.header = "File Menu"
177
+ menu.prompt = "Operation? "
178
+ end
179
+ assert_equal( "File Menu: Operation? " +
180
+ "(load, save or quit) ", @output.string )
181
+
182
+ @input.rewind
183
+ @output.truncate(@output.rewind)
184
+
185
+ @terminal.choose(:load, :save, :quit) do |menu|
186
+ menu.layout = :menu_only
187
+ end
188
+ assert_equal("load, save or quit? ", @output.string)
189
+
190
+ @input.rewind
191
+ @output.truncate(@output.rewind)
192
+
193
+ @terminal.choose(:load, :save, :quit) do |menu|
194
+ menu.layout = '<%= list(@menu) %>File Menu: '
195
+ end
196
+ assert_equal("1. load\n2. save\n3. quit\nFile Menu: ", @output.string)
197
+ end
198
+
199
+ def test_list_option
200
+ @input << "l\n"
201
+ @input.rewind
202
+
203
+ @terminal.choose(:load, :save, :quit) do |menu|
204
+ menu.layout = :menu_only
205
+ menu.list_option = ", or "
206
+ end
207
+ assert_equal("load, save, or quit? ", @output.string)
208
+ end
209
+
210
+ def test_nil_on_handled
211
+ @input << "3\n3\n2\n"
212
+ @input.rewind
213
+
214
+ # Shows that by default proc results are returned.
215
+ output = @terminal.choose do |menu|
216
+ menu.choice "Sample1" do "output1" end
217
+ menu.choice "Sample2" do "output2" end
218
+ menu.choice "Sample3" do "output3" end
219
+ end
220
+ assert_equal("output3", output)
221
+
222
+ #
223
+ # Shows that they can be replaced with +nil+ by setting
224
+ # _nil_on_handled to +true+.
225
+ #
226
+ output = @terminal.choose do |menu|
227
+ menu.nil_on_handled = true
228
+ menu.choice "Sample1" do "output1" end
229
+ menu.choice "Sample2" do "output2" end
230
+ menu.choice "Sample3" do "output3" end
231
+ end
232
+ assert_equal(nil, output)
233
+
234
+ # Shows that a menu item without a proc will be returned no matter what.
235
+ output = @terminal.choose do |menu|
236
+ menu.choice "Sample1"
237
+ menu.choice "Sample2"
238
+ menu.choice "Sample3"
239
+ end
240
+ assert_equal("Sample2", output)
241
+ end
242
+
243
+ def test_passed_command
244
+ @input << "q\n"
245
+ @input.rewind
246
+
247
+ selected = nil
248
+ @terminal.choose do |menu|
249
+ menu.choices(:load, :save, :quit) { |command| selected = command }
250
+ end
251
+ assert_equal(:quit, selected)
252
+ end
253
+
254
+ def test_question_options
255
+ @input << "save\n"
256
+ @input.rewind
257
+
258
+ answer = @terminal.choose(:Load, :Save, :Quit) do |menu|
259
+ menu.case = :capitalize
260
+ end
261
+ assert_equal(:Save, answer)
262
+
263
+ @input.rewind
264
+
265
+ answer = @terminal.choose(:Load, :Save, :Quit) do |menu|
266
+ menu.case = :capitalize
267
+ menu.character = :getc
268
+ end
269
+ assert_equal(:Save, answer)
270
+ assert_equal(?a, @input.getc)
271
+ end
272
+
273
+ def test_select_by
274
+ @input << "Sample1\n2\n"
275
+ @input.rewind
276
+
277
+ selected = @terminal.choose do |menu|
278
+ menu.choice "Sample1"
279
+ menu.choice "Sample2"
280
+ menu.choice "Sample3"
281
+ end
282
+ assert_equal("Sample1", selected)
283
+
284
+ @input.rewind
285
+
286
+ selected = @terminal.choose do |menu|
287
+ menu.select_by = :index
288
+
289
+ menu.choice "Sample1"
290
+ menu.choice "Sample2"
291
+ menu.choice "Sample3"
292
+ end
293
+ assert_equal("Sample2", selected)
294
+
295
+ @input.rewind
296
+
297
+ selected = @terminal.choose do |menu|
298
+ menu.select_by = :name
299
+
300
+ menu.choice "Sample1"
301
+ menu.choice "Sample2"
302
+ menu.choice "Sample3"
303
+ end
304
+ assert_equal("Sample1", selected)
305
+ end
306
+
307
+ def test_hidden
308
+ @input << "Hidden\n4\n"
309
+ @input.rewind
310
+
311
+ selected = @terminal.choose do |menu|
312
+ menu.choice "Sample1"
313
+ menu.choice "Sample2"
314
+ menu.choice "Sample3"
315
+ menu.hidden "Hidden!"
316
+ end
317
+ assert_equal("Hidden!", selected)
318
+ assert_equal("1. Sample1\n2. Sample2\n3. Sample3\n? ", @output.string)
319
+
320
+ @input.rewind
321
+
322
+ selected = @terminal.choose do |menu|
323
+ menu.select_by = :index
324
+
325
+ menu.choice "Sample1"
326
+ menu.choice "Sample2"
327
+ menu.choice "Sample3"
328
+ menu.hidden "Hidden!"
329
+ end
330
+ assert_equal("Hidden!", selected)
331
+
332
+ @input.rewind
333
+
334
+ selected = @terminal.choose do |menu|
335
+ menu.select_by = :name
336
+
337
+ menu.choice "Sample1"
338
+ menu.choice "Sample2"
339
+ menu.choice "Sample3"
340
+ menu.hidden "Hidden!"
341
+ end
342
+ assert_equal("Hidden!", selected)
343
+
344
+ @input.rewind
345
+ end
346
+
347
+ def test_select_by_letter
348
+ @input << "b\n"
349
+ @input.rewind
350
+
351
+ selected = @terminal.choose do |menu|
352
+ menu.index = :letter
353
+ menu.choice :save
354
+ menu.choice :load
355
+ menu.choice :quit
356
+ end
357
+ assert_equal(:load, selected)
358
+ end
359
+
360
+ def test_shell
361
+ @input << "save --some-option my_file.txt\n"
362
+ @input.rewind
363
+
364
+ selected = nil
365
+ options = nil
366
+ answer = @terminal.choose do |menu|
367
+ menu.choices(:load, :quit)
368
+ menu.choice(:save) do |command, details|
369
+ selected = command
370
+ options = details
371
+
372
+ "Saved!"
373
+ end
374
+ menu.shell = true
375
+ end
376
+ assert_equal("Saved!", answer)
377
+ assert_equal(:save, selected)
378
+ assert_equal("--some-option my_file.txt", options)
379
+ end
380
+
381
+ def test_simple_menu_shortcut
382
+ @input << "3\n"
383
+ @input.rewind
384
+
385
+ selected = @terminal.choose(:save, :load, :quit)
386
+ assert_equal(:quit, selected)
387
+ end
388
+
389
+ def test_symbols
390
+ @input << "3\n"
391
+ @input.rewind
392
+
393
+ selected = @terminal.choose do |menu|
394
+ menu.choices(:save, :load, :quit)
395
+ end
396
+ assert_equal(:quit, selected)
397
+ end
398
+
399
+ def test_paged_print_infinite_loop_bug
400
+ @terminal.page_at = 5
401
+ # Will page twice, so start with two new lines
402
+ @input << "\n\n3\n"
403
+ @input.rewind
404
+
405
+ # Sadly this goes into an infinite loop without the fix to page_print
406
+ selected = @terminal.choose(* 1..10)
407
+ assert_equal(selected, 3)
408
+ end
409
+
410
+
411
+ def test_cancel_paging
412
+ # Tests that paging can be cancelled halfway through
413
+ @terminal.page_at = 5
414
+ # Will page twice, so stop after first page and make choice 3
415
+ @input << "q\n3\n"
416
+ @input.rewind
417
+
418
+ selected = @terminal.choose(* 1..10)
419
+ assert_equal(selected, 3)
420
+
421
+ # Make sure paging message appeared
422
+ assert( @output.string.index('press enter/return to continue or q to stop'),
423
+ "Paging message did not appear." )
424
+
425
+ # Make sure it only appeared once
426
+ assert( @output.string !~ /q to stop.*q to stop/m,
427
+ "Paging message appeared more than once." )
428
+ end
429
+ end