highline 1.6.19 → 1.6.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c93d5d6310a71c9a3fba8e6c625ca28736e8fd20
4
- data.tar.gz: 407f7bfd150c5bb79e82ed5bc1d1f9b61669de06
5
- SHA512:
6
- metadata.gz: 970bcd09397745bc4c6f31bee83044f157277401b4be57e7465e9568dff609e795e631bfae69c157f3f06cd4b032d45807547eb04ddcfbaa2598397d9a36f34c
7
- data.tar.gz: cb48512d7dcad2ecd6185c1c56cdb06bc25c377bc3a9b879d352a70fc6e1056160e9ceb1a9bfa18a1ba00f38ffac4d2c3dc76a0e543554fa04a5e9992761498b
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: a61adde22a7c1f3dee0c4bd0a140551c7c2d0d5c
4
+ data.tar.gz: f0ff2a065f96473524fcd21b76dd63e6d7317e1a
5
+ !binary "U0hBNTEy":
6
+ metadata.gz: f7f546676de00891dece575d25b550459665f679161e2571d3218f355a16df9de929da9643b092948f17abd9764297846e2ac973d61b5d81d34933b9aef04ae4
7
+ data.tar.gz: b8a676035168b49bdff06d2f272b37818289461a2d27b371ad32b2516f1c1c616cfe916ac09b833470c17652cb9e6d1701e60b6eb37dfdce97eaacfbb67a7808
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.20
6
+
7
+ * Fixed a bug with FFI::NCurses integration (by agentdave).
8
+ * Improved StringExtensions performance (by John Leach).
9
+ * Various JRuby fixes (by presidentbeef).
10
+
5
11
  == 1.6.19
6
12
 
7
13
  * Fixed `terminal_size()` with jline2 (by presidentbeef).
@@ -15,7 +15,11 @@ after, and let it do all the work.
15
15
 
16
16
  == Documentation
17
17
 
18
- See HighLine and HighLine::Question for documentation.
18
+ See HighLine and HighLine::Question for documentation.
19
+
20
+ Start hacking in your code with HighLine with:
21
+
22
+ require 'highline/import'
19
23
 
20
24
  == Examples
21
25
 
@@ -11,7 +11,7 @@ end
11
11
 
12
12
  puts "Ok, you did it."
13
13
 
14
- pass = ask("Enter your password: ") do |q|
14
+ pass = ask("<%= @key %>: ") do |q|
15
15
  q.echo = '*'
16
16
  q.verify_match = true
17
17
  q.gather = {"Enter a password" => '',
@@ -28,7 +28,7 @@ require "highline/style"
28
28
  #
29
29
  class HighLine
30
30
  # The version of the installed library.
31
- VERSION = "1.6.19".freeze
31
+ VERSION = "1.6.20".freeze
32
32
 
33
33
  # An internal HighLine error. User code does not need to trap this.
34
34
  class QuestionError < StandardError
@@ -255,6 +255,7 @@ class HighLine
255
255
  # Also, JRuby-1.7's ConsoleReader.readLine() needs to be passed the prompt
256
256
  # to handle line editing properly.
257
257
  say(@question) unless ((JRUBY or @question.readline) and @question.echo == true)
258
+
258
259
  begin
259
260
  @answer = @question.answer_or_default(get_response)
260
261
  unless @question.valid_answer?(@answer)
@@ -613,22 +614,10 @@ class HighLine
613
614
  # and the HighLine.color() method.
614
615
  #
615
616
  def say( statement )
616
- statement = statement.to_str
617
+ statement = format_statement(statement)
617
618
  return unless statement.length > 0
618
619
 
619
- # Allow non-ascii menu prompts in ruby > 1.9.2. ERB eval the menu statement
620
- # with the environment's default encoding(usually utf8)
621
- statement.force_encoding(Encoding.default_external) if defined?(Encoding) && Encoding.default_external
622
-
623
- template = ERB.new(statement, nil, "%")
624
- statement = template.result(binding)
625
-
626
- statement = wrap(statement) unless @wrap_at.nil?
627
- statement = page_print(statement) unless @page_at.nil?
628
-
629
- statement = statement.gsub(/\n(?!$)/,"\n#{indentation}") if @multi_indent
630
-
631
- # Don't add a newline if statement ends with whitespace, OR
620
+ # Don't add a newline if statement ends with whitespace, OR
632
621
  # if statement ends with whitespace before a color escape code.
633
622
  if /[ \t](\e\[\d+(;\d+)*m)?\Z/ =~ statement
634
623
  @output.print(indentation+statement)
@@ -672,10 +661,16 @@ class HighLine
672
661
  @indent_level += increase
673
662
  multi = @multi_indent
674
663
  @multi_indent = multiline unless multiline.nil?
675
- if block_given?
676
- yield self
677
- else
678
- say(statement)
664
+ begin
665
+ if block_given?
666
+ yield self
667
+ else
668
+ say(statement)
669
+ end
670
+ rescue
671
+ @multi_indent = multi
672
+ @indent_level -= increase
673
+ raise
679
674
  end
680
675
  @multi_indent = multi
681
676
  @indent_level -= increase
@@ -712,6 +707,25 @@ class HighLine
712
707
 
713
708
  private
714
709
 
710
+ def format_statement statement
711
+ statement = statement.dup.to_str
712
+ return statement unless statement.length > 0
713
+
714
+ # Allow non-ascii menu prompts in ruby > 1.9.2. ERB eval the menu statement
715
+ # with the environment's default encoding(usually utf8)
716
+ statement.force_encoding(Encoding.default_external) if defined?(Encoding) && Encoding.default_external
717
+
718
+ template = ERB.new(statement, nil, "%")
719
+ statement = template.result(binding)
720
+
721
+ statement = wrap(statement) unless @wrap_at.nil?
722
+ statement = page_print(statement) unless @page_at.nil?
723
+
724
+ statement = statement.gsub(/\n(?!$)/,"\n#{indentation}") if @multi_indent
725
+
726
+ statement
727
+ end
728
+
715
729
  #
716
730
  # A helper method for sending the output stream and error and repeat
717
731
  # of the question.
@@ -839,7 +853,11 @@ class HighLine
839
853
  answer
840
854
  else
841
855
  if JRUBY
842
- raw_answer = @java_console.readLine(@question.question, nil)
856
+ statement = format_statement(@question)
857
+ raw_answer = @java_console.readLine(statement, nil)
858
+
859
+ raise EOFError, "The input stream is exhausted." if raw_answer.nil? and
860
+ @@track_eof
843
861
  else
844
862
  raise EOFError, "The input stream is exhausted." if @@track_eof and
845
863
  @input.eof?
@@ -917,6 +935,10 @@ class HighLine
917
935
  @question.change_case(@question.remove_whitespace(line))
918
936
  end
919
937
  else
938
+ if JRUBY #prompt has not been shown
939
+ say @question
940
+ end
941
+
920
942
  raw_no_echo_mode
921
943
  begin
922
944
  if @question.character == :getc
@@ -31,85 +31,65 @@ class HighLine
31
31
  module StringExtensions
32
32
  def self.included(base)
33
33
  HighLine::COLORS.each do |color|
34
+ color = color.downcase
34
35
  base.class_eval <<-END
35
- if public_instance_methods.map { |m| m.to_s }.
36
- include? "#{color.downcase}"
37
- undef :#{color.downcase}
38
- end
39
- def #{color.downcase}
40
- color(:#{color.downcase})
36
+ undef :#{color} if method_defined? :#{color}
37
+ def #{color}
38
+ color(:#{color})
41
39
  end
42
40
  END
41
+
43
42
  base.class_eval <<-END
44
- if public_instance_methods.map { |m| m.to_s }.
45
- include? "on_#{color.downcase}"
46
- undef :on_#{color.downcase}
47
- end
48
- def on_#{color.downcase}
49
- on(:#{color.downcase})
43
+ undef :on_#{color} if method_defined? :on_#{color}
44
+ def on_#{color}
45
+ on(:#{color})
50
46
  end
51
47
  END
52
48
  HighLine::STYLES.each do |style|
49
+ style = style.downcase
53
50
  base.class_eval <<-END
54
- if public_instance_methods.map { |m| m.to_s }.
55
- include? "#{style.downcase}"
56
- undef :#{style.downcase}
57
- end
58
- def #{style.downcase}
59
- color(:#{style.downcase})
51
+ undef :#{style} if method_defined? :#{style}
52
+ def #{style}
53
+ color(:#{style})
60
54
  end
61
55
  END
62
56
  end
63
57
  end
64
58
 
65
59
  base.class_eval do
66
- if public_instance_methods.map { |m| m.to_s }.include? "color"
67
- undef :color
68
- end
69
- if public_instance_methods.map { |m| m.to_s }.include? "foreground"
70
- undef :foreground
71
- end
60
+ undef :color if method_defined? :color
61
+ undef :foreground if method_defined? :foreground
72
62
  def color(*args)
73
63
  self.class.new(HighLine.color(self, *args))
74
64
  end
75
65
  alias_method :foreground, :color
76
66
 
77
- if public_instance_methods.map { |m| m.to_s }.include? "on"
78
- undef :on
79
- end
67
+ undef :on if method_defined? :on
80
68
  def on(arg)
81
69
  color(('on_' + arg.to_s).to_sym)
82
70
  end
83
71
 
84
- if public_instance_methods.map { |m| m.to_s }.include? "uncolor"
85
- undef :uncolor
86
- end
72
+ undef :uncolor if method_defined? :uncolor
87
73
  def uncolor
88
74
  self.class.new(HighLine.uncolor(self))
89
75
  end
90
76
 
91
- if public_instance_methods.map { |m| m.to_s }.include? "rgb"
92
- undef :rgb
93
- end
77
+ undef :rgb if method_defined? :rgb
94
78
  def rgb(*colors)
95
79
  color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
96
80
  raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
97
81
  color("rgb_#{color_code}".to_sym)
98
82
  end
99
83
 
100
- if public_instance_methods.map { |m| m.to_s }.include? "on_rgb"
101
- undef :on_rgb
102
- end
84
+ undef :on_rgb if method_defined? :on_rgb
103
85
  def on_rgb(*colors)
104
86
  color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
105
87
  raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
106
88
  color("on_rgb_#{color_code}".to_sym)
107
89
  end
108
90
 
109
- if public_instance_methods.map { |m| m.to_s }.include? "method_missing"
110
- undef :method_missing
111
- end
112
91
  # TODO Chain existing method_missing
92
+ undef :method_missing if method_defined? :method_missing
113
93
  def method_missing(method, *args, &blk)
114
94
  if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/
115
95
  color(method)
@@ -14,10 +14,14 @@ class HighLine
14
14
  if JRUBY
15
15
  def initialize_system_extensions
16
16
  require 'java'
17
+ require 'readline'
17
18
  if JRUBY_VERSION =~ /^1.7/
18
19
  java_import 'jline.console.ConsoleReader'
19
20
 
20
- @java_console = ConsoleReader.new(@input.to_inputstream, @output.to_outputstream)
21
+ input = @input && @input.to_inputstream
22
+ output = @output && @output.to_outputstream
23
+
24
+ @java_console = ConsoleReader.new(input, output)
21
25
  @java_console.set_history_enabled(false)
22
26
  @java_console.set_bell_enabled(true)
23
27
  @java_console.set_pagination_enabled(false)
@@ -176,7 +180,7 @@ class HighLine
176
180
  size = [80, 40]
177
181
  FFI::NCurses.initscr
178
182
  begin
179
- size = FFI::NCurses.getmaxyx(stdscr).reverse
183
+ size = FFI::NCurses.getmaxyx(FFI::NCurses.stdscr).reverse
180
184
  ensure
181
185
  FFI::NCurses.endwin
182
186
  end
@@ -247,6 +247,11 @@ class TestHighLine < Test::Unit::TestCase
247
247
  assert_equal(1, answer)
248
248
  end
249
249
 
250
+ def test_frozen_statement
251
+ @terminal.say('This is a frozen statement'.freeze)
252
+ assert_equal("This is a frozen statement\n", @output.string)
253
+ end
254
+
250
255
  def test_color
251
256
  @terminal.say("This should be <%= BLUE %>blue<%= CLEAR %>!")
252
257
  assert_equal("This should be \e[34mblue\e[0m!\n", @output.string)
@@ -690,7 +695,8 @@ class TestHighLine < Test::Unit::TestCase
690
695
  end
691
696
 
692
697
  def test_mode
693
- assert(%w[Win32API termios ncurses stty].include?(HighLine::CHARACTER_MODE))
698
+ assert(%w[Win32API termios ncurses stty jline].include?(HighLine::CHARACTER_MODE),
699
+ "#{HighLine::CHARACTER_MODE} not in list")
694
700
  end
695
701
 
696
702
  class NameClass
@@ -422,7 +422,7 @@ class TestMenu < Test::Unit::TestCase
422
422
  # Tests that paging can be cancelled halfway through
423
423
  @terminal.page_at = 5
424
424
  # Will page twice, so stop after first page and make choice 3
425
- @input << "q\n3\n"
425
+ @input << "q3\n"
426
426
  @input.rewind
427
427
 
428
428
  selected = @terminal.choose(* 1..10)
metadata CHANGED
@@ -1,20 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: highline
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.19
4
+ version: 1.6.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Edward Gray II
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-13 00:00:00.000000000 Z
11
+ date: 2013-10-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: |
14
- A high-level IO library that provides validation, type conversion, and more for
13
+ description: ! 'A high-level IO library that provides validation, type conversion,
14
+ and more for
15
+
15
16
  command-line interfaces. HighLine also includes a complete menu system that can
17
+
16
18
  crank out anything from simple list selection to complete shells with just
19
+
17
20
  minutes of work.
21
+
22
+ '
18
23
  email: james@graysoftinc.com
19
24
  executables: []
20
25
  extensions: []
@@ -87,12 +92,12 @@ require_paths:
87
92
  - lib
88
93
  required_ruby_version: !ruby/object:Gem::Requirement
89
94
  requirements:
90
- - - '>='
95
+ - - ! '>='
91
96
  - !ruby/object:Gem::Version
92
97
  version: '0'
93
98
  required_rubygems_version: !ruby/object:Gem::Requirement
94
99
  requirements:
95
- - - '>='
100
+ - - ! '>='
96
101
  - !ruby/object:Gem::Version
97
102
  version: '0'
98
103
  requirements: []