class

Scroll::Renderer

Inherits Reference < Object

Draws the tail window as a fixed-height region on the terminal, repainting it in place each frame. The region is reserved once by scrolling (which pushes any existing screen content up into scrollback rather than overwriting it), and thereafter every frame is a single up-move, N cleared-and-rewritten rows, and a move back to the top. No newline is ever emitted after the last row, so the terminal never scrolls again and the region cannot drift or clobber history. Lines are sanitized and truncated to one short of the terminal width (never touching the last column, which can trigger auto-wrap). The raw stream on STDOUT is never touched by any of this. With --progress the bottom row of the region belongs to the progress line, and can be repainted on its own.

Constants

CLEAR_EOL = "\e[K"
HIDE_CURSOR = "\e[?25l"
SHOW_CURSOR = "\e[?25h"

Constructors

new(io : IO, lines : Int32, sanitize : Bool = true, progress : Bool = false, size : Tuple(Int32, Int32) | Nil = nil)

progress reserves the bottom row of the region for the progress line. size overrides the terminal size query (rows, cols); it exists so specs can drive the renderer against an IO::Memory, which has no fd.

Source

Class methods

restore(io : IO) : Nil

Restore the cursor unconditionally; safe to call from an at_exit hook when no renderer instance is available.

Source

Instance methods

draw(lines : Array(String), progress : String | Nil = nil) : Nil

Repaint the region. The cursor is assumed to rest at column 0 of the first region row, and is left there again when done.

Source
draw_progress(text : String) : Nil

Repaint only the progress row. Ticks where no new line arrived still move the rates, the ETA, and a scrolling name, and repainting one row instead of the whole region keeps that cheap.

Source
finish

Move the cursor below the region and show it, so a following shell prompt (or the shell after Ctrl-C) appears after the display rather than on top of it or wherever the cursor happened to rest. Idempotent and safe from an at_exit / signal handler: it runs at most once and swallows a dead terminal.

Source
start

Hide the cursor and record the ceiling for the region height. The region is not reserved up front: it grows one row at a time as lines arrive, so a short stream never opens more rows than it has lines.

Source
width

Columns a row may use: one short of the terminal width, since writing the last column can trigger auto-wrap.

Source