module

TermBuf::SizeDetector

Stability: internal

Works out how big the terminal is, trying each source in turn and taking the first that answers.

The ioctl comes first because it is exact, free, and needs no cooperation from the terminal. Everything after it is a fallback for the cases where there is no controlling terminal to ask — a pipe, a pty without a size set, a terminal reached across a connection that did not forward one.

Constants

TIOCGWINSZ = 21523_u64

Instance methods

detect(fd : Int32 | Nil = nil, env : Hash(String, String) = ENV.to_h) : ScreenSize

In order: the kernel, the environment, then the shell utilities.

Source
from_commands

stty and tput, which reach the same ioctl by another route. Worth trying because they may find a controlling terminal this process cannot see through its own descriptors.

Source
from_env(env : Hash(String, String)) : ScreenSize | Nil

COLUMNS and LINES, which a shell exports and which can be set by hand when nothing else knows.

Source
from_ioctl(fd : Int32 | Nil = nil) : ScreenSize | Nil

TIOCGWINSZ on the given descriptor, or on stdout, stdin, and stderr in turn when none is named. A process with its output redirected often still has a terminal on one of the others.

Source