diff options
author | James Gray <james@grayproductions.net> | 2006-10-25 14:05:41 +0000 |
---|---|---|
committer | James Gray <james@grayproductions.net> | 2006-10-25 14:05:41 +0000 |
commit | d3adc3c98bf806a94411bbec141ac9f66895eda6 (patch) | |
tree | c2535772746da5c7bfbde2d3451a3116f2292d25 | |
parent | 5d006bc947395064a845dfc5c0ad11c92d034fdb (diff) | |
download | highline-d3adc3c98bf806a94411bbec141ac9f66895eda6.tar.gz |
Tagging the 1.2.3 release.rel_1_2_3
-rw-r--r-- | CHANGELOG | 8 | ||||
-rw-r--r-- | lib/highline.rb | 42 | ||||
-rw-r--r-- | lib/highline/question.rb | 7 | ||||
-rw-r--r-- | lib/highline/system_extensions.rb | 27 | ||||
-rw-r--r-- | test/tc_highline.rb | 4 | ||||
-rw-r--r-- | test/tc_menu.rb | 20 |
6 files changed, 90 insertions, 18 deletions
@@ -2,10 +2,18 @@ Below is a complete listing of changes for each revision of HighLine. +== 1.2.3 + +* Treat Cygwin like a Posix OS, instead of a native Windows environment. + == 1.2.2 * Minor documentation corrections. * Applied Thomas Werschleiln's patch to fix termio buffering on Solaris. +* Applied Justin Bailey's patch to allow canceling paged output. +* Fixed a documentation bug in the description of character case settings. +* Added a notice about termios in HighLine::Question#echo. +* Finally working around the infamous "fast typing" bug == 1.2.1 diff --git a/lib/highline.rb b/lib/highline.rb index 151e266..a75f55b 100644 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -28,7 +28,7 @@ require "abbrev" # class HighLine # The version of the installed library. - VERSION = "1.2.1".freeze + VERSION = "1.2.3".freeze # An internal HighLine error. User code does not need to trap this. class QuestionError < StandardError @@ -572,16 +572,23 @@ class HighLine if @question.echo == true and @question.limit.nil? get_line else + raw_no_echo_mode if stty = CHARACTER_MODE == "stty" + line = "" - while character = get_character(@input) - line << character.chr - # looking for carriage return (decimal 13) or - # newline (decimal 10) in raw input - break if character == 13 or character == 10 or - (@question.limit and line.size == @question.limit) - @output.print(@question.echo) if @question.echo != false + begin + while character = (stty ? @input.getc : get_character(@input)) + line << character.chr + # looking for carriage return (decimal 13) or + # newline (decimal 10) in raw input + break if character == 13 or character == 10 or + (@question.limit and line.size == @question.limit) + @output.print(@question.echo) if @question.echo != false + end + say("\n") + ensure + restore_mode if stty end - say("\n") + @question.change_case(@question.remove_whitespace(line)) end elsif @question.character == :getc @@ -613,12 +620,23 @@ class HighLine while lines.size > @page_at @output.puts lines.slice!(0...@page_at).join @output.puts - HighLine.new(@input, @output).ask("-- press enter/return to continue -- ") - @output.puts + # Return last line if user wants to abort paging + return (["...\n"] + lines.slice(-2,1)).join unless continue_paging? end return lines.join end - + + # + # Ask user if they wish to continue paging output. Allows them to type "q" to + # cancel the paging process. + # + def continue_paging? + command = HighLine.new(@input, @output).ask( + "-- press enter/return to continue or q to stop -- " + ) { |q| q.character = true } + command !~ /\A[qQ]\Z/ # Only continue paging if Q was not hit. + end + # # Wrap a sequence of _lines_ at _wrap_at_ characters per line. Existing # newlines will not be affected by this process, but additional newlines diff --git a/lib/highline/question.rb b/lib/highline/question.rb index 4fdb131..a566737 100644 --- a/lib/highline/question.rb +++ b/lib/highline/question.rb @@ -89,6 +89,11 @@ class HighLine # # This requires HighLine's character reader. See the _character_ # attribute for details. + # + # *Note*: When using HighLine to manage echo on Unix based systems, we + # recommend installing the termios gem. Without it, it's possible to type + # fast enough to have letters still show up (when reading character by + # character only). # attr_accessor :echo # @@ -107,7 +112,7 @@ class HighLine # attr_accessor :whitespace # - # Used to control whitespace processing for the answer to this question. + # Used to control character case processing for the answer to this question. # See HighLine::Question.change_case() for acceptable settings. # attr_accessor :case diff --git a/lib/highline/system_extensions.rb b/lib/highline/system_extensions.rb index 64198d5..6f1e335 100644 --- a/lib/highline/system_extensions.rb +++ b/lib/highline/system_extensions.rb @@ -17,6 +17,9 @@ class HighLine # dragons! # begin + # Cygwin will look like Windows, but we want to treat it like a Posix OS: + raise LoadError, "Cygwin is a Posix OS." if RUBY_PLATFORM =~ /\bcygwin\b/i + require "Win32API" # See if we're on Windows. CHARACTER_MODE = "Win32API" # For Debugging purposes only. @@ -84,15 +87,33 @@ class HighLine # *WARNING*: This method requires the external "stty" program! # def get_character( input = STDIN ) - state = `stty -g` + raw_no_echo_mode begin - system "stty raw -echo cbreak" input.getc ensure - system "stty #{state}" + restore_mode end end + + # + # Switched the input mode to raw and disables echo. + # + # *WARNING*: This method requires the external "stty" program! + # + def raw_no_echo_mode + @state = `stty -g` + system "stty raw -echo cbreak" + end + + # + # Restores a previously saved input mode. + # + # *WARNING*: This method requires the external "stty" program! + # + def restore_mode + system "stty #{@state}" + end end # A Unix savvy method to fetch the console columns, and rows. diff --git a/test/tc_highline.rb b/test/tc_highline.rb index 3a7f654..08ddb6b 100644 --- a/test/tc_highline.rb +++ b/test/tc_highline.rb @@ -450,9 +450,9 @@ class TestHighLine < Test::Unit::TestCase @terminal.say((1..50).map { |n| "This is line #{n}.\n"}.join) assert_equal( (1..22).map { |n| "This is line #{n}.\n"}.join + - "\n-- press enter/return to continue -- \n" + + "\n-- press enter/return to continue or q to stop -- \n\n" + (23..44).map { |n| "This is line #{n}.\n"}.join + - "\n-- press enter/return to continue -- \n" + + "\n-- press enter/return to continue or q to stop -- \n\n" + (45..50).map { |n| "This is line #{n}.\n"}.join, @output.string ) end diff --git a/test/tc_menu.rb b/test/tc_menu.rb index c4f833b..fee1871 100644 --- a/test/tc_menu.rb +++ b/test/tc_menu.rb @@ -406,4 +406,24 @@ class TestMenu < Test::Unit::TestCase selected = @terminal.choose(* 1..10) assert_equal(selected, 3) end + + + def test_cancel_paging + # Tests that paging can be cancelled halfway through + @terminal.page_at = 5 + # Will page twice, so stop after first page and make choice 3 + @input << "q\n3\n" + @input.rewind + + selected = @terminal.choose(* 1..10) + assert_equal(selected, 3) + + # Make sure paging message appeared + assert( @output.string.index('press enter/return to continue or q to stop'), + "Paging message did not appear." ) + + # Make sure it only appeared once + assert( @output.string !~ /q to stop.*q to stop/m, + "Paging message appeared more than once." ) + end end |