module Hirb # This class provides class methods for paging and an object which can conditionally page given a terminal size that is exceeded. class Pager class<@pager_command) else self.class.default_pager(string, :width=>@width, :height=>@height, :inspect=>inspect_mode) end end def slice!(output, inspect_mode=false) #:nodoc: effective_height = @height - 2 # takes into account pager prompt if inspect_mode sliced_output = output.slice(0, @width * effective_height) output.replace output.slice(@width * effective_height..-1) sliced_output else # could use output.scan(/[^\n]*\n?/) instead of split sliced_output = output.split("\n").slice(0, effective_height).join("\n") output.replace output.split("\n").slice(effective_height..-1).join("\n") sliced_output end end # Determines if string should be paged based on configured width and height. def activated_by?(string_to_page, inspect_mode=false) inspect_mode ? (string_to_page.size > @height * @width) : (string_to_page.count("\n") > @height) end def resize(width, height) #:nodoc: @width, @height = Hirb::View.determine_terminal_size(width, height) end end end