tui

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package tui draws the scan's live progress: a sticky segmented bar at the bottom of the terminal, with log lines scrolling above it and each stage promoted into the scrollback with its elapsed time as it finishes.

It reads internal/progress and is imported only by cmd/godzilla, which is what keeps golang.org/x/term out of every frontend's build.

The display is erase-and-redraw, not a DECSTBM scroll region. A scroll region is terminal STATE: a process that dies without resetting it leaves the user's shell broken. Here every frame is (erase, draw), so the worst an abnormal exit can leave behind is a half-drawn line — the same thing a killed scan leaves today.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Color

func Color(f *os.File) bool

Color reports whether ANSI colour should be written to f. It is the same decision the display makes, asked about a different stream: the findings go to STDOUT, which may well be a file or a pipe while the bar's stderr is a terminal, and a colour code in a redirected report is corruption.

func Enabled

func Enabled(quiet bool) bool

Enabled reports whether the interactive display should run.

It keys off STDERR, not stdout: the display draws on stderr so that stdout — the coverage line and the findings, which tooling parses — stays byte for byte what it is today even while the bar is on screen.

-quiet wins over everything, including the force-on env var. `godzilla scan -quiet` is contracted to emit literally nothing, and a display that could override that would break the gate's only silent mode.

func Width

func Width(f *os.File) int

Width is the usable width of f, or 0 when it is not a terminal. Callers that lay text out — the findings report on stdout — need this for a stream the bar is not drawing on.

Types

type Options

type Options struct {
	Out     io.Writer         // nil means os.Stderr
	Size    func() (w, h int) // nil means the real terminal size
	Now     func() time.Time  // nil means time.Now
	Tick    time.Duration     // 0 means 100ms
	Capture bool              // route os.Stderr through the display
	// Expect names stages that will run but that no scan stage implies, so the
	// bar can carry them in its denominator before they register.
	Expect []string
}

Options configures a UI. The zero value is the production one: stderr, the real terminal size, the real clock. The fields exist so the whole display can be exercised with no terminal at all.

type UI

type UI struct {
	// contains filtered or unexported fields
}

UI is a running display. Every method is safe to call on a nil *UI, so the command can hold one variable and not branch at each use.

func Start

func Start(opts Options) *UI

Start begins drawing. It owns two goroutines: the frame ticker, which is the ONLY thing that ever writes to the terminal, and (under Capture) the pipe reader, which only appends to a buffer. That single-writer property is what makes a sticky bar correct at all.

func (*UI) Abort

func (u *UI) Abort()

Abort marks the run as having stopped early, so the closing frame says "stopped" instead of completing. A progress bar that races to 100% on a crash is a lie.

func (*UI) OnStop

func (u *UI) OnStop(fn func())

OnStop registers a function to run when the display stops — the hook the command uses to disarm the stage ledger it armed for this window.

func (*UI) Stdout

func (u *UI) Stdout() io.Writer

Stdout is where the command writes its own stdout output while the display is up: the line is held until the next frame, which erases the bar, writes it to the REAL stdout and redraws. On a nil UI — the display is off — it is plain os.Stdout, so the caller does not branch.

func (*UI) Stop

func (u *UI) Stop()

Stop erases the bar, restores stderr, flushes everything captured and joins its goroutines. Idempotent and nil-safe, so the command can both defer it for the panic path and call it where normal output resumes.

Jump to

Keyboard shortcuts

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