ui

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 22 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 ui is the panel itself: a Bubble Tea model that draws a spec's sections, answers the keyboard and the mouse, edits fields, saves stores and runs actions.

Index

Constants

View Source
const (
	MinWidth  = 24
	MinHeight = 6
)

Minimum is the smallest size the panel draws itself in; below it, one line asks for more room.

Variables

View Source
var ClockEpoch = time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)

ClockEpoch is the time a parked clock starts at.

Functions

func NewStore

func NewStore(s *spec.Spec, sd *spec.Store, path string) store.Store

NewStore is the store a spec's store definition describes, on the file at path. Everything that builds a panel's stores (the panel, paneltest, observe --sandbox) goes through it, so they cannot differ.

func StoreExt

func StoreExt(k spec.StoreKind) string

StoreExt is the file extension a store kind's files have, for copies.

func Unpack

func Unpack(msg tea.Msg) (cmds []tea.Cmd, ordered, ok bool)

Unpack returns the commands inside a tea.Batch or tea.Sequence result, and whether they must run in order. Bubble Tea's sequence message is not exported, so it is recognised by its shape.

Types

type Advance

type Advance struct{ D time.Duration }

Advance moves the parked clock of a panel with Options.NoTimers forward by D, delivering in order every parked tick that falls due, including ticks re-armed on the way.

type Element

type Element struct {
	ID      string `json:"id"`
	Kind    string `json:"kind"`
	Label   string `json:"label"`
	X       int    `json:"x"`
	Y       int    `json:"y"`
	W       int    `json:"w"`
	H       int    `json:"h"`
	Focused bool   `json:"focused,omitempty"`
}

Element is one clickable thing on screen, as observe reports it.

type Model

type Model struct {

	// ExitCode is set when the panel quits: 0, or 1 after a crash.
	ExitCode int
	// contains filtered or unexported fields
}

Model is the panel. It is used through a pointer.

func New

func New(opts Options) *Model

New builds a panel. It does no I/O; Init starts loading.

func (*Model) CrashLog

func (m *Model) CrashLog() string

CrashLog is where the crash was written, or "" when the panel has not crashed or the log could not be written.

func (*Model) Crashed

func (m *Model) Crashed() bool

Crashed reports whether the panel caught a panic and shows its crash screen.

func (*Model) Dirty

func (m *Model) Dirty() int

Dirty reports how many edits are unsaved.

func (*Model) Elements

func (m *Model) Elements() []Element

Elements are the clickable elements of the last frame.

func (*Model) Focused

func (m *Model) Focused() string

Focused returns the id of the focused element.

func (*Model) Frame

func (m *Model) Frame() string

Frame is the last frame drawn, as plain text.

func (*Model) Hit

func (m *Model) Hit(x, y int) string

Hit returns the id of the element at a cell of the last frame.

func (*Model) Init

func (m *Model) Init() (cmd tea.Cmd)

Init loads the stores and starts the lists.

func (*Model) Quit

func (m *Model) Quit() tea.Cmd

Quit ends the panel from outside, as a signal handler does: running commands are cancelled and Bubble Tea is told to stop.

func (*Model) Size

func (m *Model) Size() (int, int)

Size is the terminal size the panel last drew at.

func (*Model) Status

func (m *Model) Status() string

Status returns the status line's text, for observe and tests.

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (model tea.Model, cmd tea.Cmd)

Update implements tea.Model. A panic in it becomes the crash screen.

func (*Model) View

func (m *Model) View() (v tea.View)

View implements tea.Model. A panic while drawing becomes the crash screen.

func (*Model) WaitCommands

func (m *Model) WaitCommands(d time.Duration) bool

WaitCommands waits up to d for every command in flight to end, and reports whether they did. After Quit they are being killed: a process that exits before the kill is sent leaves them running.

type Options

type Options struct {
	Spec    *spec.Spec
	LoadErr error             // the panel cannot start (a bad spec, a missing view); it shows why
	Context map[string]string // {ctx.*} values
	Via     string            // PANEL_VIA for commands
	Runner  run.Runner        // nil runs commands for real
	Theme   *Theme            // nil for DefaultTheme
	// NoTimers parks every timer, the panel's polling and a view's
	// TickRequest alike, on a clock that moves only when an Advance message
	// says so: a frame then depends only on the input it was given.
	NoTimers bool
	// Stores overrides the store built for each spec store, by name.
	Stores map[string]store.Store
	// Views supply the sections of kind "view", by name.
	Views map[string]View
	// CrashDir is where a crash log is written; "" for the temp directory.
	CrashDir string
	// Framed means herdr already shows the panel's title, on the frame it
	// draws around a plugin's popup: the panel leaves out its own title row.
	Framed bool
	Parent context.Context //nolint:containedctx // the panel's lifetime; cancelled on quit
}

Options configure a Model.

type QuitRequest

type QuitRequest struct{}

QuitRequest asks the panel to end now, as a signal does: running commands are cancelled and nothing is asked.

type Theme

type Theme struct {
	Title       lipgloss.Style
	Section     lipgloss.Style
	Label       lipgloss.Style
	Value       lipgloss.Style
	Muted       lipgloss.Style
	Focus       lipgloss.Style // the focused element
	Selected    lipgloss.Style // the selected row of a list that is not focused
	Dirty       lipgloss.Style
	Error       lipgloss.Style
	OK          lipgloss.Style
	Rule        lipgloss.Style
	Button      lipgloss.Style
	DialogTitle lipgloss.Style
	Dialog      lipgloss.Style
}

Theme maps the panel's roles to styles. Colours are ANSI palette indices, so a panel takes on the user's terminal theme, and every role also has a non-colour mark (reverse, bold, a glyph), so meaning never rests on colour. NO_COLOR is honoured by Bubble Tea's renderer, which drops colours and keeps attributes.

func DefaultTheme

func DefaultTheme() Theme

DefaultTheme uses the ANSI 16 palette.

type TickRequest

type TickRequest struct {
	D  time.Duration
	Fn func(time.Time) tea.Msg
}

TickRequest asks for Fn's message after D. A view returns it from a command (panel.Tick builds it). The panel turns it into a timer; with Options.NoTimers it parks it instead, until a driver sends Advance.

type View

type View interface {
	Render(width int, focused bool) ViewOutput
	Update(msg tea.Msg) tea.Cmd
}

View is a section drawn and driven by Go code; the panel package adapts its public View to this one.

type ViewClick

type ViewClick struct {
	Region string
	X, Y   int
}

ViewClick tells a view that one of its regions was clicked; X and Y are the cell within the region.

type ViewFocus

type ViewFocus struct{ Focused bool }

ViewFocus tells a view that it gained or lost the keyboard focus.

type ViewOutput

type ViewOutput struct {
	Lines   []string
	Regions []ViewRegion
	Cursor  int // the line kept on screen while the view has focus
}

ViewOutput is one drawing of a view.

type ViewRegion

type ViewRegion struct {
	ID, Label string
	Line, X   int
	W         int
}

ViewRegion is a clickable part of a view's line, in cells.

Jump to

Keyboard shortcuts

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