class Pry::Pager::PageTracker
`PageTracker` tracks output to determine whether it's likely to take up a whole page. This doesn't need to be super precise, but we can use it for `SimplePager` and to avoid invoking the system pager unnecessarily.
One simplifying assumption is that we don't need `#page?` to return `true` on the basis of an incomplete line. Long lines should be counted as multiple lines, but we don't have to transition from `false` to `true` until we see a newline.
Public Class Methods
new(rows, cols)
click to toggle source
# File lib/pry/pager.rb, line 214 def initialize(rows, cols) @rows = rows @cols = cols reset end
Public Instance Methods
page?()
click to toggle source
# File lib/pry/pager.rb, line 231 def page? @row >= @rows end
record(str)
click to toggle source
# File lib/pry/pager.rb, line 220 def record(str) str.lines.each do |line| if line.end_with? "\n" @row += ((@col + line_length(line) - 1) / @cols) + 1 @col = 0 else @col += line_length(line) end end end
reset()
click to toggle source
# File lib/pry/pager.rb, line 235 def reset @row = 0 @col = 0 end
Private Instance Methods
line_length(line)
click to toggle source
Approximation of the printable length of a given line, without the newline and without ANSI color codes.
# File lib/pry/pager.rb, line 244 def line_length(line) line.chomp.gsub(/\e\[[\d;]*m/, '').length end