highline 1.6.12 → 1.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +6 -0
- data/examples/ansi_colors.rb +1 -1
- data/examples/asking_for_arrays.rb +1 -1
- data/examples/basic_usage.rb +1 -1
- data/examples/menus.rb +1 -1
- data/examples/overwrite.rb +1 -1
- data/examples/page_and_wrap.rb +1 -1
- data/examples/password.rb +1 -1
- data/examples/repeat_entry.rb +21 -0
- data/examples/trapping_eof.rb +1 -1
- data/examples/using_readline.rb +1 -1
- data/lib/highline.rb +56 -34
- data/lib/highline/color_scheme.rb +0 -2
- data/lib/highline/import.rb +0 -2
- data/lib/highline/menu.rb +2 -2
- data/lib/highline/question.rb +13 -6
- data/lib/highline/simulate.rb +0 -2
- data/lib/highline/style.rb +0 -2
- data/lib/highline/system_extensions.rb +0 -2
- data/test/string_methods.rb +0 -2
- data/test/tc_color_scheme.rb +0 -2
- data/test/tc_highline.rb +74 -9
- data/test/tc_import.rb +0 -2
- data/test/tc_menu.rb +0 -2
- data/test/tc_string_extension.rb +0 -2
- data/test/tc_string_highline.rb +0 -2
- data/test/tc_style.rb +0 -2
- data/test/ts_all.rb +0 -2
- metadata +3 -2
data/CHANGELOG
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Below is a complete listing of changes for each revision of HighLine.
|
|
4
4
|
|
|
5
|
+
== 1.6.13
|
|
6
|
+
|
|
7
|
+
* Removed unneeded Shebang lines (by Scott Gonyea).
|
|
8
|
+
* Protect the String passed to Question.new from modification (by michael).
|
|
9
|
+
* Added a retype-to-verify setting (by michael).
|
|
10
|
+
|
|
5
11
|
== 1.6.12
|
|
6
12
|
|
|
7
13
|
* Silenced warnings (by James McEwan).
|
data/examples/ansi_colors.rb
CHANGED
data/examples/basic_usage.rb
CHANGED
data/examples/menus.rb
CHANGED
data/examples/overwrite.rb
CHANGED
data/examples/page_and_wrap.rb
CHANGED
data/examples/password.rb
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "rubygems"
|
|
4
|
+
require "highline/import"
|
|
5
|
+
|
|
6
|
+
tounge_twister = ask("... try saying that three times fast") do |q|
|
|
7
|
+
q.gather = 3
|
|
8
|
+
q.verify_match = true
|
|
9
|
+
q.responses[:mismatch] = "Nope, those don't match. Try again."
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
puts "Ok, you did it."
|
|
13
|
+
|
|
14
|
+
pass = ask("Enter your password: ") do |q|
|
|
15
|
+
q.echo = '*'
|
|
16
|
+
q.verify_match = true
|
|
17
|
+
q.gather = {"Enter a password" => '',
|
|
18
|
+
"Please type it again for verification" => ''}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
puts "Your password is now #{pass}!"
|
data/examples/trapping_eof.rb
CHANGED
data/examples/using_readline.rb
CHANGED
data/lib/highline.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
|
2
|
-
|
|
3
1
|
# highline.rb
|
|
4
2
|
#
|
|
5
3
|
# Created by James Edward Gray II on 2005-04-26.
|
|
@@ -30,7 +28,7 @@ require "highline/style"
|
|
|
30
28
|
#
|
|
31
29
|
class HighLine
|
|
32
30
|
# The version of the installed library.
|
|
33
|
-
VERSION = "1.6.
|
|
31
|
+
VERSION = "1.6.13".freeze
|
|
34
32
|
|
|
35
33
|
# An internal HighLine error. User code does not need to trap this.
|
|
36
34
|
class QuestionError < StandardError
|
|
@@ -691,44 +689,68 @@ class HighLine
|
|
|
691
689
|
# Raises EOFError if input is exhausted.
|
|
692
690
|
#
|
|
693
691
|
def gather( )
|
|
694
|
-
@gather = @question.gather
|
|
695
|
-
@answers = [ ]
|
|
696
692
|
original_question = @question
|
|
697
|
-
|
|
693
|
+
original_question_string = @question.question
|
|
694
|
+
original_gather = @question.gather
|
|
695
|
+
|
|
696
|
+
verify_match = @question.verify_match
|
|
698
697
|
@question.gather = false
|
|
699
|
-
|
|
700
|
-
case @gather
|
|
701
|
-
when Integer
|
|
702
|
-
@answers << ask(@question)
|
|
703
|
-
@gather -= 1
|
|
704
698
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
699
|
+
begin # when verify_match is set this loop will repeat until unique_answers == 1
|
|
700
|
+
@answers = [ ]
|
|
701
|
+
@gather = original_gather
|
|
702
|
+
original_question.question = original_question_string
|
|
703
|
+
|
|
704
|
+
case @gather
|
|
705
|
+
when Integer
|
|
706
|
+
@answers << ask(@question)
|
|
707
|
+
@gather -= 1
|
|
708
|
+
|
|
709
|
+
original_question.question = ""
|
|
710
|
+
until @gather.zero?
|
|
711
|
+
@question = original_question
|
|
712
|
+
@answers << ask(@question)
|
|
713
|
+
@gather -= 1
|
|
714
|
+
end
|
|
715
|
+
when ::String, Regexp
|
|
716
|
+
@answers << ask(@question)
|
|
713
717
|
|
|
714
|
-
|
|
715
|
-
|
|
718
|
+
original_question.question = ""
|
|
719
|
+
until (@gather.is_a?(::String) and @answers.last.to_s == @gather) or
|
|
716
720
|
(@gather.is_a?(Regexp) and @answers.last.to_s =~ @gather)
|
|
717
|
-
|
|
718
|
-
|
|
721
|
+
@question = original_question
|
|
722
|
+
@answers << ask(@question)
|
|
723
|
+
end
|
|
724
|
+
|
|
725
|
+
@answers.pop
|
|
726
|
+
when Hash
|
|
727
|
+
@answers = { }
|
|
728
|
+
@gather.keys.sort.each do |key|
|
|
729
|
+
@question = original_question
|
|
730
|
+
@key = key
|
|
731
|
+
@answers[key] = ask(@question)
|
|
732
|
+
end
|
|
719
733
|
end
|
|
720
|
-
|
|
721
|
-
@answers.
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
@key = key
|
|
727
|
-
@answers[key] = ask(@question)
|
|
734
|
+
|
|
735
|
+
if verify_match && (unique_answers(@answers).size > 1)
|
|
736
|
+
@question = original_question
|
|
737
|
+
explain_error(:mismatch)
|
|
738
|
+
else
|
|
739
|
+
verify_match = false
|
|
728
740
|
end
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
741
|
+
|
|
742
|
+
end while verify_match
|
|
743
|
+
|
|
744
|
+
original_question.verify_match ? @answer : @answers
|
|
745
|
+
end
|
|
746
|
+
|
|
747
|
+
#
|
|
748
|
+
# A helper method used by HighLine::Question.verify_match
|
|
749
|
+
# for finding whether a list of answers match or differ
|
|
750
|
+
# from each other.
|
|
751
|
+
#
|
|
752
|
+
def unique_answers(list = @answers)
|
|
753
|
+
(list.respond_to?(:values) ? list.values : list).uniq
|
|
732
754
|
end
|
|
733
755
|
|
|
734
756
|
#
|
data/lib/highline/import.rb
CHANGED
data/lib/highline/menu.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
|
2
|
-
|
|
3
1
|
# menu.rb
|
|
4
2
|
#
|
|
5
3
|
# Created by Gregory Thomas Brown on 2005-05-10.
|
|
@@ -389,6 +387,8 @@ class HighLine
|
|
|
389
387
|
:not_in_range =>
|
|
390
388
|
"Your answer isn't within the expected range " +
|
|
391
389
|
"(#{expected_range}).",
|
|
390
|
+
:mismatch =>
|
|
391
|
+
"Your entries didn't match.",
|
|
392
392
|
:not_valid =>
|
|
393
393
|
"Your answer isn't valid (must match " +
|
|
394
394
|
"#{@validate.inspect})."
|
data/lib/highline/question.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
|
2
|
-
|
|
3
1
|
# question.rb
|
|
4
2
|
#
|
|
5
3
|
# Created by James Edward Gray II on 2005-04-26.
|
|
@@ -33,9 +31,9 @@ class HighLine
|
|
|
33
31
|
#
|
|
34
32
|
def initialize( question, answer_type )
|
|
35
33
|
# initialize instance data
|
|
36
|
-
@question = question
|
|
34
|
+
@question = question.dup
|
|
37
35
|
@answer_type = answer_type
|
|
38
|
-
|
|
36
|
+
|
|
39
37
|
@character = nil
|
|
40
38
|
@limit = nil
|
|
41
39
|
@echo = true
|
|
@@ -49,19 +47,20 @@ class HighLine
|
|
|
49
47
|
@in = nil
|
|
50
48
|
@confirm = nil
|
|
51
49
|
@gather = false
|
|
50
|
+
@verify_match = false
|
|
52
51
|
@first_answer = nil
|
|
53
52
|
@directory = Pathname.new(File.expand_path(File.dirname($0)))
|
|
54
53
|
@glob = "*"
|
|
55
54
|
@responses = Hash.new
|
|
56
55
|
@overwrite = false
|
|
57
|
-
|
|
56
|
+
|
|
58
57
|
# allow block to override settings
|
|
59
58
|
yield self if block_given?
|
|
60
59
|
|
|
61
60
|
# finalize responses based on settings
|
|
62
61
|
build_responses
|
|
63
62
|
end
|
|
64
|
-
|
|
63
|
+
|
|
65
64
|
# The ERb template of the question to be asked.
|
|
66
65
|
attr_accessor :question
|
|
67
66
|
# The type that will be used to convert this answer.
|
|
@@ -152,6 +151,12 @@ class HighLine
|
|
|
152
151
|
#
|
|
153
152
|
attr_accessor :gather
|
|
154
153
|
#
|
|
154
|
+
# When set to +true+ multiple entries will be collected according to
|
|
155
|
+
# the setting for _gather_, except they will be required to match
|
|
156
|
+
# each other. Multiple identical entries will return a single answer.
|
|
157
|
+
#
|
|
158
|
+
attr_accessor :verify_match
|
|
159
|
+
#
|
|
155
160
|
# When set to a non *nil* value, this will be tried as an answer to the
|
|
156
161
|
# question. If this answer passes validations, it will become the result
|
|
157
162
|
# without the user ever being prompted. Otherwise this value is discarded,
|
|
@@ -236,6 +241,8 @@ class HighLine
|
|
|
236
241
|
:not_in_range =>
|
|
237
242
|
"Your answer isn't within the expected range " +
|
|
238
243
|
"(#{expected_range}).",
|
|
244
|
+
:mismatch =>
|
|
245
|
+
"Your entries didn't match.",
|
|
239
246
|
:not_valid =>
|
|
240
247
|
"Your answer isn't valid (must match " +
|
|
241
248
|
"#{@validate.inspect})." }.merge(@responses)
|
data/lib/highline/simulate.rb
CHANGED
data/lib/highline/style.rb
CHANGED
data/test/string_methods.rb
CHANGED
data/test/tc_color_scheme.rb
CHANGED
data/test/tc_highline.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
|
2
|
-
|
|
3
1
|
# tc_highline.rb
|
|
4
2
|
#
|
|
5
3
|
# Created by James Edward Gray II on 2005-04-26.
|
|
@@ -310,7 +308,19 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
310
308
|
assert_equal( "Are you sexually active? |No Comment| ",
|
|
311
309
|
@output.string )
|
|
312
310
|
end
|
|
313
|
-
|
|
311
|
+
|
|
312
|
+
def test_string_preservation
|
|
313
|
+
@input << "Maybe\nYes\n"
|
|
314
|
+
@input.rewind
|
|
315
|
+
|
|
316
|
+
my_string = "Is that your final answer? "
|
|
317
|
+
|
|
318
|
+
@terminal.ask(my_string) { |q| q.default = "Possibly" }
|
|
319
|
+
@terminal.ask(my_string) { |q| q.default = "Maybe" }
|
|
320
|
+
|
|
321
|
+
assert_equal("Is that your final answer? ", my_string)
|
|
322
|
+
end
|
|
323
|
+
|
|
314
324
|
def test_empty
|
|
315
325
|
@input << "\n"
|
|
316
326
|
@input.rewind
|
|
@@ -346,8 +356,6 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
346
356
|
q.glob = "*.rb"
|
|
347
357
|
end
|
|
348
358
|
assert_instance_of(File, file)
|
|
349
|
-
assert_equal("#!/usr/local/bin/ruby -w\n", file.gets)
|
|
350
|
-
assert_equal("\n", file.gets)
|
|
351
359
|
assert_equal("# tc_highline.rb\n", file.gets)
|
|
352
360
|
file.close
|
|
353
361
|
|
|
@@ -398,15 +406,72 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
398
406
|
answers )
|
|
399
407
|
assert_equal("Age: Father's Age: Wife's Age: ", @output.string)
|
|
400
408
|
end
|
|
401
|
-
|
|
402
|
-
def
|
|
409
|
+
|
|
410
|
+
def test_typing_verification
|
|
411
|
+
@input << "all work and no play makes jack a dull boy\n" * 3
|
|
412
|
+
@input.rewind
|
|
413
|
+
|
|
414
|
+
answer = @terminal.ask("How's work? ") do |q|
|
|
415
|
+
q.gather = 3
|
|
416
|
+
q.verify_match = true
|
|
417
|
+
end
|
|
418
|
+
assert_equal("all work and no play makes jack a dull boy", answer)
|
|
419
|
+
|
|
420
|
+
@input.truncate(@input.rewind)
|
|
421
|
+
@input << "all play and no work makes jack a mere toy\n"
|
|
422
|
+
@input << "all work and no play makes jack a dull boy\n" * 5
|
|
423
|
+
@input.rewind
|
|
424
|
+
@output.truncate(@output.rewind)
|
|
425
|
+
|
|
426
|
+
answer = @terminal.ask("How are things going? ") do |q|
|
|
427
|
+
q.gather = 3
|
|
428
|
+
q.verify_match = true
|
|
429
|
+
q.responses[:mismatch] = 'Typing mismatch!'
|
|
430
|
+
q.responses[:ask_on_error] = ''
|
|
431
|
+
end
|
|
432
|
+
assert_equal("all work and no play makes jack a dull boy", answer)
|
|
433
|
+
|
|
434
|
+
# now try using a hash for gather
|
|
435
|
+
|
|
436
|
+
@input.truncate(@input.rewind)
|
|
437
|
+
@input << "Password\nPassword\n"
|
|
438
|
+
@input.rewind
|
|
439
|
+
@output.truncate(@output.rewind)
|
|
440
|
+
|
|
441
|
+
answer = @terminal.ask("<%= @key %>: ") do |q|
|
|
442
|
+
q.verify_match = true
|
|
443
|
+
q.gather = {"Enter a password" => '', "Please type it again" => ''}
|
|
444
|
+
end
|
|
445
|
+
assert_equal("Password", answer)
|
|
446
|
+
|
|
447
|
+
@input.truncate(@input.rewind)
|
|
448
|
+
@input << "Password\nMistake\nPassword\nPassword\n"
|
|
449
|
+
@input.rewind
|
|
450
|
+
@output.truncate(@output.rewind)
|
|
451
|
+
|
|
452
|
+
answer = @terminal.ask("<%= @key %>: ") do |q|
|
|
453
|
+
q.verify_match = true
|
|
454
|
+
q.responses[:mismatch] = 'Typing mismatch!'
|
|
455
|
+
q.responses[:ask_on_error] = ''
|
|
456
|
+
q.gather = {"Enter a password" => '', "Please type it again" => ''}
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
assert_equal("Password", answer)
|
|
460
|
+
assert_equal( "Enter a password: " +
|
|
461
|
+
"Please type it again: " +
|
|
462
|
+
"Typing mismatch!\n" +
|
|
463
|
+
"Enter a password: " +
|
|
464
|
+
"Please type it again: ", @output.string )
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
def test_lists
|
|
403
468
|
digits = %w{Zero One Two Three Four Five Six Seven Eight Nine}
|
|
404
469
|
erb_digits = digits.dup
|
|
405
470
|
erb_digits[erb_digits.index("Five")] = "<%= color('Five', :blue) %%>"
|
|
406
|
-
|
|
471
|
+
|
|
407
472
|
@terminal.say("<%= list(#{digits.inspect}) %>")
|
|
408
473
|
assert_equal(digits.map { |d| "#{d}\n" }.join, @output.string)
|
|
409
|
-
|
|
474
|
+
|
|
410
475
|
@output.truncate(@output.rewind)
|
|
411
476
|
|
|
412
477
|
@terminal.say("<%= list(#{digits.inspect}, :inline) %>")
|
data/test/tc_import.rb
CHANGED
data/test/tc_menu.rb
CHANGED
data/test/tc_string_extension.rb
CHANGED
data/test/tc_string_highline.rb
CHANGED
data/test/tc_style.rb
CHANGED
data/test/ts_all.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: highline
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.6.
|
|
4
|
+
version: 1.6.13
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-06-15 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: ! 'A high-level IO library that provides validation, type conversion,
|
|
15
15
|
and more for
|
|
@@ -50,6 +50,7 @@ files:
|
|
|
50
50
|
- examples/overwrite.rb
|
|
51
51
|
- examples/page_and_wrap.rb
|
|
52
52
|
- examples/password.rb
|
|
53
|
+
- examples/repeat_entry.rb
|
|
53
54
|
- examples/trapping_eof.rb
|
|
54
55
|
- examples/using_readline.rb
|
|
55
56
|
- highline.gemspec
|