termline

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func TerminalSize

func TerminalSize(w io.Writer) (int, bool)

TerminalSize is the default SizeFunc: it probes *os.File writers.

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 New

func New(out io.Writer) *Line

New returns a Line drawing to out.

func (*Line) Columns

func (l *Line) Columns() int

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

func (l *Line) Draw(frame string)

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) Finish

func (l *Line) Finish()

Finish ends the line after the last frame.

func (*Line) IsTerminal

func (l *Line) IsTerminal() bool

IsTerminal reports whether the writer has a cursor to rewind.

type SizeFunc

type SizeFunc func(w io.Writer) (width int, isTerminal bool)

SizeFunc reports a writer's width in columns and whether it is a terminal at all. A zero width with true means a terminal of unknown size.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL