module

Scroll::Terminal

Queries the size of the terminal attached to a file descriptor via TIOCGWINSZ, falling back to the LINES/COLUMNS environment variables and then to a conventional 24x80.

Constants

FALLBACK_COLS = 80
FALLBACK_ROWS = 24
PROGRESS_TERMINALS = ["kitty", "ghostty", "iterm"] of ::String

Terminals known to show OSC 9;4 progress. XTVERSION answers with the name, e.g. "\eP>|ghostty 1.2.0\e\".

TIOCGWINSZ = 21523_u64
VERSION_QUERY = "\e[>q"
VERSION_TIMEOUT = 100.milliseconds
VTIME = 5

Class methods

reports_progress?(response : String | Nil) : Bool

Whether response names a terminal that drives its own progress indicator. Anything else — no answer, or a terminal that is not on the list — means the sequence is not worth sending.

Source
size(fd : Int32 = STDERR.fd) : Tuple(Int32, Int32)

Returns {rows, columns} for the terminal on fd. The display lives on STDERR, so that is the stream whose size matters — never STDOUT, which is usually redirected in a pipeline.

Source
version_response(timeout : Time::Span = VERSION_TIMEOUT) : String | Nil

Ask the controlling terminal to name itself, returning its answer or nil when it does not answer within timeout — which is the usual case, since a terminal that does not know the query stays silent.

The query goes to /dev/tty rather than STDIN, which belongs to the stream being copied, and is skipped outside the foreground process group: reading the terminal from the background raises SIGTTIN, which would stop the run.

Source