Documentation
¶
Overview ¶
Package termline redraws one status line in place on a terminal.
A progress line that pads itself to the terminal width and rewinds with a bare "\r" breaks as soon as the terminal shrinks: macOS terminals reflow the full-width row into two physical rows, "\r" rewinds only the last of them, and the head of the old frame is left orphaned above every later redraw.
Line avoids that by never padding: each frame is written, the rest of the screen below the cursor is erased, and the cursor is parked at column 0. A reflowing terminal keeps a parked cursor with the start of the row's content, so the next frame overwrites the head of the old one and the erase removes any wrapped remainder. Frames are also kept one column short of the width so they never reach the wrap column. Both the installer and the model downloader draw through this type; a richer view can replace it later.
Index ¶
Constants ¶
const DefaultColumns = 80
DefaultColumns is used when the output is not a measurable terminal and COLUMNS is unset. 80 is the conservative choice: a frame narrower than the real terminal redraws correctly, a wider one wraps.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Line ¶
type Line struct {
// Size probes the writer's width and terminal-ness for every frame, so
// resizes are followed. Tests override it; it defaults to TerminalSize.
Size SizeFunc
// contains filtered or unexported fields
}
Line draws successive frames of one status line to a writer.
func (*Line) Columns ¶
Columns reports the width to render at: the real terminal size, then an explicit COLUMNS, then DefaultColumns. It is re-read for every frame.
func (*Line) Draw ¶
Draw redraws the line as frame. On a terminal the frame is truncated to Columns()-1 visible cells (with an ellipsis), written after a carriage return, followed by an erase to the end of the screen, and the cursor is parked at column 0. On a non-terminal only the carriage return and the text are written, so a log shows the frame on its own line; callers gate how often they draw there.
func (*Line) IsTerminal ¶
IsTerminal reports whether the writer has a cursor to rewind.