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
- Variables
- func NewStore(s *spec.Spec, sd *spec.Store, path string) store.Store
- func StoreExt(k spec.StoreKind) string
- func Unpack(msg tea.Msg) (cmds []tea.Cmd, ordered, ok bool)
- type Advance
- type Element
- type Model
- func (m *Model) CrashLog() string
- func (m *Model) Crashed() bool
- func (m *Model) Dirty() int
- func (m *Model) Elements() []Element
- func (m *Model) Focused() string
- func (m *Model) Frame() string
- func (m *Model) Hit(x, y int) string
- func (m *Model) Init() (cmd tea.Cmd)
- func (m *Model) Quit() tea.Cmd
- func (m *Model) Size() (int, int)
- func (m *Model) Status() string
- func (m *Model) Update(msg tea.Msg) (model tea.Model, cmd tea.Cmd)
- func (m *Model) View() (v tea.View)
- func (m *Model) WaitCommands(d time.Duration) bool
- type Options
- type QuitRequest
- type Theme
- type TickRequest
- type View
- type ViewClick
- type ViewFocus
- type ViewOutput
- type ViewRegion
Constants ¶
const ( MinWidth = 24 MinHeight = 6 )
Minimum is the smallest size the panel draws itself in; below it, one line asks for more room.
Variables ¶
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 ¶
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.
Types ¶
type Advance ¶
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 (*Model) CrashLog ¶
CrashLog is where the crash was written, or "" when the panel has not crashed or the log could not be written.
func (*Model) Crashed ¶
Crashed reports whether the panel caught a panic and shows its crash screen.
func (*Model) Quit ¶
Quit ends the panel from outside, as a signal handler does: running commands are cancelled and Bubble Tea is told to stop.
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.
type TickRequest ¶
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 ¶
View is a section drawn and driven by Go code; the panel package adapts its public View to this one.
type ViewClick ¶
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 ¶
ViewRegion is a clickable part of a view's line, in cells.