live

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 6 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 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