diff options
author | James Edward Gray II <james@grayproductions.net> | 2015-10-09 14:29:47 -0500 |
---|---|---|
committer | James Edward Gray II <james@grayproductions.net> | 2015-10-09 14:29:47 -0500 |
commit | addfbaf7d1f0a3c72875c3ddee76af4330b32675 (patch) | |
tree | ceb10c568c4af76350b8ba6984306e72dd279077 | |
parent | 482d641922d1213c0884ee286689611ca76751ec (diff) | |
parent | 5f4a9c713c279291dab47cde5e3e00dd7e097102 (diff) | |
download | highline-addfbaf7d1f0a3c72875c3ddee76af4330b32675.tar.gz |
Merge pull request #170 from abinoam/fix_say_type_errorv1.7.8
Add tests for #168 #169 and fix another edge case
-rw-r--r-- | Changelog.md | 3 | ||||
-rwxr-xr-x | lib/highline.rb | 4 | ||||
-rw-r--r-- | lib/highline/version.rb | 2 | ||||
-rwxr-xr-x | test/tc_highline.rb | 42 |
4 files changed, 48 insertions, 3 deletions
diff --git a/Changelog.md b/Changelog.md index 4b35780..99c95d8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,9 @@ Below is a complete listing of changes for each revision of HighLine. +### 1.7.8 / 2015-10-09 +* Fix some issues when paginating. (Nick Carboni (@carbonin) and Abinoam P. Marques Jr. (@abinoam), #168, PRs #169 #170) + ### 1.7.7 / 2015-09-22 * Make HighLine::Question coerce its question argument into a String. (@97-109-107 and Abinoam P. Marques Jr. (@abinoam), #159, PR #160) diff --git a/lib/highline.rb b/lib/highline.rb index 561d2b5..8dcc14b 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -989,12 +989,12 @@ class HighLine # instead. This is to support any special handling for the final sequence. # def page_print( output ) - lines = output.scan(/[^\n]*\n?/) + lines = output.lines.to_a while lines.size > @page_at @output.puts lines.slice!(0...@page_at).join @output.puts # Return last line if user wants to abort paging - return (["...\n"] + [lines.last]).join unless continue_paging? + return "...\n#{lines.last}" unless continue_paging? end return lines.join end diff --git a/lib/highline/version.rb b/lib/highline/version.rb index 796065d..a65e2d7 100644 --- a/lib/highline/version.rb +++ b/lib/highline/version.rb @@ -1,4 +1,4 @@ class HighLine # The version of the installed library. - VERSION = "1.7.7".freeze + VERSION = "1.7.8".freeze end diff --git a/test/tc_highline.rb b/test/tc_highline.rb index cdda30a..4b32a69 100755 --- a/test/tc_highline.rb +++ b/test/tc_highline.rb @@ -977,6 +977,48 @@ class TestHighLine < Test::Unit::TestCase (45..50).map { |n| "This is line #{n}.\n"}.join, @output.string ) end + + def test_statement_lines_count_equal_to_page_at_shouldnt_paginate + @terminal.page_at = 6 + + @input << "\n" + @input.rewind + + list = "a\nb\nc\nd\ne\nf\n" + + @terminal.say(list) + assert_equal(list, @output.string) + end + + def test_statement_with_one_line_bigger_than_page_at_should_paginate + @terminal.page_at = 6 + + @input << "\n" + @input.rewind + + list = "a\nb\nc\nd\ne\nf\ng\n" + + paginated = + "a\nb\nc\nd\ne\nf\n" \ + "\n-- press enter/return to continue or q to stop -- \n\n" \ + "g\n" + + @terminal.say(list) + assert_equal(paginated, @output.string) + end + + def test_quiting_paging_shouldnt_raise + # See https://github.com/JEG2/highline/issues/168 + + @terminal.page_at = 6 + + @input << "q" + @input.rewind + + list = "a\nb\nc\nd\ne\nf\n" + + assert_nothing_raised { @terminal.say(list) } + end def test_range_requirements @input << "112\n-541\n28\n" |