summaryrefslogtreecommitdiff
path: root/lib/highline/paginator.rb
diff options
context:
space:
mode:
authorAbinoam Praxedes Marques Jr <abinoam@gmail.com>2015-03-14 19:17:14 -0300
committerAbinoam Praxedes Marques Jr <abinoam@gmail.com>2015-04-29 23:43:26 -0300
commitb7cc31b3648b91de02d91f87cff405e561f5d080 (patch)
treeeb74dbcff617ea237e12401656760ed7e92b80d2 /lib/highline/paginator.rb
parentd79ddd1507c2c5ec6021636dc1fcb1a0c7050443 (diff)
downloadhighline-b7cc31b3648b91de02d91f87cff405e561f5d080.tar.gz
Make Paginator and Statemnt talk
Diffstat (limited to 'lib/highline/paginator.rb')
-rw-r--r--lib/highline/paginator.rb21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/highline/paginator.rb b/lib/highline/paginator.rb
index 5ce236d..3c296a3 100644
--- a/lib/highline/paginator.rb
+++ b/lib/highline/paginator.rb
@@ -1,5 +1,12 @@
+require 'highline'
+
class HighLine
- module Paginator
+ class Paginator
+ attr_reader :highline
+
+ def initialize(highline)
+ @highline = highline
+ end
#
# Page print a series of at most _page_at_ lines for _output_. After each
@@ -9,13 +16,13 @@ class HighLine
# Note that the final page of _output_ is *not* printed, but returned
# instead. This is to support any special handling for the final sequence.
#
- def page_print( output )
- lines = output.scan(/[^\n]*\n?/)
+ def page_print(text)
+ lines = text.scan(/[^\n]*\n?/)
while lines.size > highline.page_at
- highline_output.puts lines.slice!(0...highline.page_at).join
- highline_output.puts
+ highline.puts lines.slice!(0...highline.page_at).join
+ highline.puts
# Return last line if user wants to abort paging
- return (["...\n"] + lines.slice(-2,1)).join unless highline.send(:continue_paging?)
+ return (["...\n"] + lines.slice(-2,1)).join unless continue_paging?
end
return lines.join
end
@@ -25,7 +32,7 @@ class HighLine
# cancel the paging process.
#
def continue_paging?
- command = HighLine.new(@input, @output).ask(
+ command = HighLine.new(highline.input, highline.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.