class Pry::Pager::PageTracker

‘false` to `true` until we see a newline.
counted as multiple lines, but we don’t have to transition from
`true` on the basis of an incomplete line. Long lines should be
One simplifying assumption is that we don’t need ‘#page?` to return
unnecessarily.
use it for `SimplePager` and to avoid invoking the system pager
up a whole page. This doesn’t need to be super precise, but we can
`PageTracker` tracks output to determine whether it’s likely to take

def initialize(rows, cols)

def initialize(rows, cols)
  @rows = rows
  @cols = cols
  reset
end

def line_length(line)

newline and without ANSI color codes.
Approximation of the printable length of a given line, without the
def line_length(line)
  line.chomp.gsub(/\e\[[\d;]*m/, '').length
end

def page?

def page?
  @row >= @rows
end

def record(str)

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

def reset

def reset
  @row = 0
  @col = 0
end