highline 1.2.7 → 1.2.8

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 CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Below is a complete listing of changes for each revision of HighLine.
4
4
 
5
+ == 1.2.8
6
+
7
+ * Fixed backspacing past the prompt and interrupting a prompt bugs.
8
+ (patch by Jeremy Hinegardner)
9
+
5
10
  == 1.2.7
6
11
 
7
12
  * Fixed the stty indent bug.
@@ -29,7 +29,7 @@ require "abbrev"
29
29
  #
30
30
  class HighLine
31
31
  # The version of the installed library.
32
- VERSION = "1.2.7".freeze
32
+ VERSION = "1.2.8".freeze
33
33
 
34
34
  # An internal HighLine error. User code does not need to trap this.
35
35
  class QuestionError < StandardError
@@ -614,21 +614,31 @@ class HighLine
614
614
  raw_no_echo_mode if stty = CHARACTER_MODE == "stty"
615
615
 
616
616
  line = ""
617
+ backspace_limit = 0
617
618
  begin
619
+
618
620
  while character = (stty ? @input.getc : get_character(@input))
619
621
  # honor backspace and delete
620
622
  if character == 127 or character == 8
621
623
  line.slice!(-1, 1)
624
+ backspace_limit -= 1
622
625
  else
623
626
  line << character.chr
627
+ backspace_limit += 1
624
628
  end
625
629
  # looking for carriage return (decimal 13) or
626
630
  # newline (decimal 10) in raw input
627
631
  break if character == 13 or character == 10 or
628
632
  (@question.limit and line.size == @question.limit)
629
633
  if @question.echo != false
630
- if character == 127 or character == 8
631
- @output.print("\b#{ERASE_CHAR}")
634
+ if character == 127 or character == 8
635
+ # only backspace if we have characters on the line to
636
+ # eliminate, otherwise we'll tromp over the prompt
637
+ if backspace_limit >= 0 then
638
+ @output.print("\b#{ERASE_CHAR}")
639
+ else
640
+ # do nothing
641
+ end
632
642
  else
633
643
  @output.print(@question.echo)
634
644
  end
@@ -103,7 +103,7 @@ class HighLine
103
103
  #
104
104
  def raw_no_echo_mode
105
105
  @state = `stty -g`
106
- system "stty raw -echo cbreak"
106
+ system "stty raw -echo cbreak isig"
107
107
  end
108
108
 
109
109
  #
@@ -132,6 +132,16 @@ class TestHighLine < Test::Unit::TestCase
132
132
  assert_equal(2, answer)
133
133
  assert_equal("Select an option (1, 2 or 3): *\n", @output.string)
134
134
  end
135
+
136
+ def test_backspace_does_not_enter_prompt
137
+ @input << "\b\b"
138
+ @input.rewind
139
+ answer = @terminal.ask("Please enter your password: ") do |q|
140
+ q.echo = "*"
141
+ end
142
+ assert_equal("", answer)
143
+ assert_equal("Please enter your password: \n",@output.string)
144
+ end
135
145
 
136
146
  def test_character_reading
137
147
  # WARNING: This method does NOT cover Unix and Windows savvy testing!
@@ -143,7 +153,7 @@ class TestHighLine < Test::Unit::TestCase
143
153
  end
144
154
  assert_equal(1, answer)
145
155
  end
146
-
156
+
147
157
  def test_color
148
158
  @terminal.say("This should be <%= BLUE %>blue<%= CLEAR %>!")
149
159
  assert_equal("This should be \e[34mblue\e[0m!\n", @output.string)
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.1
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: highline
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.2.7
7
- date: 2007-01-31 00:00:00 -06:00
6
+ version: 1.2.8
7
+ date: 2007-06-20 00:00:00 -05:00
8
8
  summary: HighLine is a high-level command-line IO library.
9
9
  require_paths:
10
10
  - lib
@@ -39,12 +39,12 @@ files:
39
39
  - examples/password.rb
40
40
  - examples/trapping_eof.rb
41
41
  - examples/using_readline.rb
42
- - lib/highline.rb
43
42
  - lib/highline/color_scheme.rb
44
43
  - lib/highline/import.rb
45
44
  - lib/highline/menu.rb
46
45
  - lib/highline/question.rb
47
46
  - lib/highline/system_extensions.rb
47
+ - lib/highline.rb
48
48
  - test/tc_color_scheme.rb
49
49
  - test/tc_highline.rb
50
50
  - test/tc_import.rb