live

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package live provides auto-refreshing terminal displays.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveSpinner added in v1.1.0

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

func StartSpinner added in v1.1.0

func StartSpinner(text string, opts ...ActiveSpinnerOption) *ActiveSpinner

func (*ActiveSpinner) Fail added in v1.1.0

func (a *ActiveSpinner) Fail(text ...string)

func (*ActiveSpinner) Render added in v1.1.0

func (a *ActiveSpinner) Render(c *console.Console, opts console.Options) []segment.Segment

func (*ActiveSpinner) Stop added in v1.1.0

func (a *ActiveSpinner) Stop()

func (*ActiveSpinner) Succeed added in v1.1.0

func (a *ActiveSpinner) Succeed(text ...string)

func (*ActiveSpinner) Update added in v1.1.0

func (a *ActiveSpinner) Update(text string)

type ActiveSpinnerOption added in v1.1.0

type ActiveSpinnerOption func(*ActiveSpinner)

func WithSpinnerConsole added in v1.1.0

func WithSpinnerConsole(c *console.Console) ActiveSpinnerOption

func WithSpinnerName added in v1.1.0

func WithSpinnerName(name string) ActiveSpinnerOption

func WithSpinnerRefreshRate added in v1.1.0

func WithSpinnerRefreshRate(hz float64) ActiveSpinnerOption

func WithSpinnerSpeed added in v1.1.0

func WithSpinnerSpeed(speed float64) ActiveSpinnerOption

func WithSpinnerStyle added in v1.1.0

func WithSpinnerStyle(s style.Style) ActiveSpinnerOption

type Block added in v1.0.6

type Block struct {
	Title  string
	Status BlockStatus
	Lines  []string

	Elapsed  time.Duration
	ExitCode int

	// SpinnerStyle overrides the running-frame spinner style. nil = dim cyan.
	SpinnerStyle *style.Style
	// RunningStyle is the base style for the running header title. Markup in the
	// title layers on top of it (overriding only what it sets), so use this for a
	// uniform default look and markup for per-title tweaks. nil = unstyled.
	RunningStyle *style.Style
	// SucceededStyle overrides the succeeded header title style. nil = green bold.
	SucceededStyle *style.Style
	// FailedStyle overrides the failed header title style. nil = red bold.
	FailedStyle *style.Style
	// OutputStyle overrides the per-line output style. nil = dim.
	OutputStyle *style.Style
	// contains filtered or unexported fields
}

Block is a single entry in a BlockDisplay. It has a header (title + status indicator) and a ring buffer of the last maxLines output lines, which stay visible after the block finishes.

Blocks are not created directly; use BlockDisplay.Start to add one.

type BlockDisplay added in v1.0.6

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

BlockDisplay is a console.Renderable that shows a growing list of blocks in a stable terminal region via Live. Each block has a header line (spinner while running, plain title while done) followed by its last N output lines. Old blocks scroll off the top once the display height exceeds the terminal height.

Use Start to create a new block, BlockWriter to feed it output lines, and Finish to set its final status + elapsed time. A BlockDisplay is safe for concurrent use: Start/AppendLine/Finish may be called from any goroutine.

func NewBlockDisplay added in v1.0.6

func NewBlockDisplay(opts ...BlockDisplayOption) *BlockDisplay

NewBlockDisplay creates a BlockDisplay.

func (*BlockDisplay) AppendLine added in v1.0.6

func (d *BlockDisplay) AppendLine(idx int, line string)

AppendLine adds an output line to block idx, trimming the ring buffer to maxLines. Lines are dimmed when rendered.

func (*BlockDisplay) AppendLines added in v1.0.6

func (d *BlockDisplay) AppendLines(idx int, s string)

AppendLines is a convenience helper wrapping AppendLine for a multi-line string without a trailing newline.

func (*BlockDisplay) Finish added in v1.0.6

func (d *BlockDisplay) Finish(idx int, exitCode int)

Finish marks the block as Succeeded (code 0) or Failed (non-zero) and records its elapsed time. Safe to call multiple times; the first call wins.

func (*BlockDisplay) NewWriter added in v1.0.6

func (d *BlockDisplay) NewWriter(idx int) *BlockWriter

NewWriter returns an io.Writer that appends completed lines to block idx.

func (*BlockDisplay) Render added in v1.0.6

func (d *BlockDisplay) Render(c *console.Console, opts console.Options) []segment.Segment

Render implements console.Renderable.

func (*BlockDisplay) Start added in v1.0.6

func (d *BlockDisplay) Start(title string) int

Start appends a new running block for title and returns its index. Callers must not mutate the returned *Block's Lines/Status directly; use AppendLine and Finish instead.

type BlockDisplayOption added in v1.0.6

type BlockDisplayOption func(*BlockDisplay)

BlockDisplayOption configures a BlockDisplay.

func WithBlockMaxLines added in v1.0.6

func WithBlockMaxLines(n int) BlockDisplayOption

WithBlockMaxLines sets the default ring-buffer size for new blocks (default 3).

func WithBlockPrefix added in v1.0.6

func WithBlockPrefix(prefix string) BlockDisplayOption

WithBlockPrefix sets the string prepended to every output line (default " " — two spaces). Use a vertical bar like "│ " for a tree-style visual border.

func WithBlockReserveSpace added in v1.0.6

func WithBlockReserveSpace(reserve bool) BlockDisplayOption

WithBlockReserveSpace, when enabled, pads each block with blank lines up to maxLines so the block height is stable from the moment it starts. Without it (the default), blocks grow organically as output arrives and never shrink.

func WithBlockSpinnerName added in v1.0.6

func WithBlockSpinnerName(name string) BlockDisplayOption

WithBlockSpinnerName sets the spinner animation used for running blocks (default "dots").

type BlockStatus added in v1.0.6

type BlockStatus int

BlockStatus tracks the lifecycle of a single block.

const (
	// BlockRunning means the block's command is in progress and the spinner animates.
	BlockRunning BlockStatus = iota
	// BlockSucceeded means the block finished successfully (exit code 0).
	BlockSucceeded
	// BlockFailed means the block's command returned a non-zero exit code.
	BlockFailed
)

type BlockWriter added in v1.0.6

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

BlockWriter is an io.Writer that buffers partial lines and flushes complete lines to BlockDisplay.AppendLine. Create one per block with BlockDisplay.NewWriter and use it as the stdout/stderr sink for a child process. It is safe for concurrent use within a single block.

func (*BlockWriter) Write added in v1.0.6

func (w *BlockWriter) Write(p []byte) (int, error)

Write implements io.Writer. It is safe for concurrent use.

type Live

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

Live provides an auto-refreshing terminal display.

func New

func New(c *console.Console, renderable console.Renderable, opts ...Option) *Live

New creates a new Live display.

func (*Live) IsStarted

func (l *Live) IsStarted() bool

IsStarted returns whether the live display is running.

func (*Live) ProcessRenderables

func (l *Live) ProcessRenderables(renderables []console.Renderable) []console.Renderable

ProcessRenderables implements console.RenderHook. This intercepts all console.Render calls while Live is active.

Note: We read console properties BEFORE acquiring l.mu to avoid deadlock. console.Render() holds c.mu when calling this method, so calling l.console.IsTerminal() while holding l.mu would try to acquire c.mu again.

func (*Live) Refresh

func (l *Live) Refresh()

Refresh forces an immediate refresh.

func (*Live) Start

func (l *Live) Start(ctx context.Context)

Start begins the live display.

func (*Live) Stop

func (l *Live) Stop()

Stop ends the live display.

func (*Live) Update

func (l *Live) Update(r console.Renderable)

Update changes the renderable being displayed.

type LiveRender

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

LiveRender tracks the rendered state and handles cursor repositioning.

func NewLiveRender

func NewLiveRender(renderable console.Renderable, overflow VerticalOverflow) *LiveRender

NewLiveRender creates a new LiveRender.

func (*LiveRender) PositionCursor

func (lr *LiveRender) PositionCursor() segment.Control

PositionCursor returns a Control that moves the cursor back to the start of the previously rendered content, erasing it in the process.

func (*LiveRender) Render

func (lr *LiveRender) Render(c *console.Console, opts console.Options) []segment.Segment

Render implements console.Renderable.

func (*LiveRender) RestoreCursor

func (lr *LiveRender) RestoreCursor() segment.Control

RestoreCursor returns a Control that moves the cursor to erase all content and returns to the original position. Used for transient mode.

func (*LiveRender) SetRenderable

func (lr *LiveRender) SetRenderable(r console.Renderable)

SetRenderable updates the renderable to display.

func (*LiveRender) Shape

func (lr *LiveRender) Shape() (width, height int)

Shape returns the last rendered shape (width, height).

type Option

type Option func(*Live)

Option configures a Live display.

func WithAutoRefresh

func WithAutoRefresh(enabled bool) Option

WithAutoRefresh enables automatic refresh at the given rate.

func WithGetRenderable

func WithGetRenderable(fn func() console.Renderable) Option

WithGetRenderable sets a callback to get the renderable on each refresh.

func WithRefreshRate

func WithRefreshRate(rate float64) Option

WithRefreshRate sets the refresh rate (default 10Hz).

func WithTransient

func WithTransient(transient bool) Option

WithTransient makes the live display disappear when stopped.

func WithVerticalOverflow

func WithVerticalOverflow(overflow VerticalOverflow) Option

WithVerticalOverflow sets how vertical overflow is handled.

type VerticalOverflow

type VerticalOverflow int

VerticalOverflow determines how vertical overflow is handled.

const (
	OverflowVisible  VerticalOverflow = iota // Show all content
	OverflowCrop                             // Crop to terminal height
	OverflowEllipsis                         // Show ellipsis for cropped content
)

Jump to

Keyboard shortcuts

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