deck

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 22 Imported by: ? 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 deck is the bubbletea runtime for viewkit.

Invariant: tea lives ONLY in this package — viewkit core (glyph/theme/layout/panels/…) must not import bubbletea. Apps and plugins implement View and register via RegisterView; Model (alias Host) owns stack navigation + chrome.

Process-global singletons (install before Run):

  • theme.Use / theme.Cur — active palette
  • keys.Use / keys.Cur — active key scheme
  • theme.Register / keys.Register / RegisterView — contribution registries

See INTERFACE.md for the Model + singleton contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComponentIDs

func ComponentIDs() []string

ComponentIDs returns registered component ids sorted.

func Confirm

func Confirm(title, message, yesLabel, noLabel string) (bool, error)

Confirm runs a yes/no tea prompt and returns whether the user confirmed.

func Prompt added in v0.1.9

func Prompt(spec PromptSpec) (vals map[string]any, ok bool, err error)

Prompt runs spec as a standalone tea program and returns the entered values. ok is false when the user cancelled.

func RegisterComponent

func RegisterComponent(id string, ctor func() Component)

RegisterComponent associates id with a component constructor.

func RegisterView

func RegisterView(id string, ctor func() View)

RegisterView associates id with a view constructor.

func Run

func Run(root View, opts ...Option) error

Run starts the tea program with alt screen.

func ViewIDs

func ViewIDs() []string

ViewIDs returns registered view ids sorted.

Types

type Chrome

type Chrome struct {
	Brand      string
	BrandGlyph string
	Subtitle   string
	ClockGlyph string
}

Chrome configures brand/header appearance. Apps inject product branding; viewkit/deck never hard-codes app names.

type Component

type Component interface {
	Render(width, height int) string
}

Component is a reusable UI fragment registered by id. Components are not full Views — they paint a region when asked.

func LookupComponent

func LookupComponent(id string) (Component, bool)

LookupComponent returns a fresh Component for id.

type Content

type Content interface {
	// Render returns the painted body for the given width (may ignore width).
	Render(width int) string
}

Content is domain-agnostic job/panel body text. Apps adapt their types (e.g. domain section trees) into Content before crossing into deck.

type ContentFunc

type ContentFunc func(width int) string

ContentFunc adapts a function to Content.

func (ContentFunc) Render

func (f ContentFunc) Render(width int) string

Render implements Content.

type Editor added in v0.1.6

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

Editor is a two-pane View: an editable form above a scrollable result list. When the terminal is too short it collapses the results, then the form, to a one-line summary rather than overflowing.

func NewEditor added in v0.1.6

func NewEditor(doc EditorDoc, km EditorKeys, seed map[string]any) *Editor

NewEditor builds an Editor over doc. seed pre-fills the form and is carried across rebuilds when doc.Sync reports true.

func (*Editor) Body added in v0.1.6

func (e *Editor) Body(width, height int) string

func (*Editor) Confirming added in v0.1.6

func (e *Editor) Confirming() bool

Confirming reports whether the delete dialog is open.

func (*Editor) Context added in v0.1.6

func (e *Editor) Context() [][2]string

func (*Editor) Form added in v0.1.6

func (e *Editor) Form() *forms.Form

Form exposes the live form so hosts can read entered values.

func (*Editor) Hints added in v0.1.6

func (e *Editor) Hints() [][2]string

func (*Editor) Init added in v0.1.6

func (e *Editor) Init() tea.Cmd

func (*Editor) Notice added in v0.1.6

func (e *Editor) Notice() []string

Notice is the current contents of the validation panel.

func (*Editor) OnResults added in v0.1.6

func (e *Editor) OnResults() bool

OnResults reports whether focus is on the results pane rather than the form.

func (*Editor) Remembered added in v0.1.13

func (e *Editor) Remembered() map[string]any

Remembered returns every value the Editor is carrying, including those of fields a later rebuild stopped rendering. Live form values win over remembered ones. A document whose field set shrinks reads this rather than Form().Values() when it must not silently discard what is still held.

func (*Editor) Running added in v0.1.6

func (e *Editor) Running() bool

Running reports whether a run is in flight.

func (*Editor) Selected added in v0.1.6

func (e *Editor) Selected() (list.Item, bool)

Selected returns the highlighted result row, if any.

func (*Editor) SelectedOf added in v0.1.6

func (e *Editor) SelectedOf(key string) int

SelectedOf returns the chosen option index of the select field under key, or -1 when no such field exists.

func (*Editor) SetStatus added in v0.1.6

func (e *Editor) SetStatus(msg string)

SetStatus sets the error line shown beneath the form.

func (*Editor) Status added in v0.1.6

func (e *Editor) Status() string

Status is the error line shown beneath the form, or "" when clear.

func (*Editor) SyncFields added in v0.1.6

func (e *Editor) SyncFields()

SyncFields rebuilds the form from the document, preserving entered values, when the document reports that its field set is value-dependent.

func (*Editor) Title added in v0.1.6

func (e *Editor) Title() string

func (*Editor) Update added in v0.1.6

func (e *Editor) Update(a *Model, msg tea.Msg) tea.Cmd

func (*Editor) Value added in v0.1.6

func (e *Editor) Value(key string) string

Value returns the trimmed text currently entered under key.

type EditorDoc added in v0.1.6

type EditorDoc interface {
	// Kind names the document type for messages, e.g. "query".
	Kind() string
	// Title heads the form panel.
	Title() string
	// Context supplies the chrome context pairs.
	Context() [][2]string
	// SavedName is the persisted name, or "" when never saved. Delete and
	// the delete hint are suppressed while it is empty.
	SavedName() string
	// Fields builds the form, seeded from previously entered values.
	Fields(prev map[string]any) []forms.Field
	// Sync reports whether editing a field should rebuild the whole form,
	// for documents whose field set depends on earlier answers.
	Sync() bool
	// Summary is the one-line description shown when the form is collapsed.
	Summary() string
	// PreviewLines renders the document for the yaml-style preview panel.
	PreviewLines() []string
	// ValidateLines checks the document and returns display lines for the
	// validation panel. A non-nil error means the document could not be
	// built at all, and is surfaced as the status line instead.
	ValidateLines() ([]string, error)
	// Run executes the document. The returned loader runs off the UI
	// goroutine, so it must not touch the doc.
	Run() (label string, load func() Results, err error)
	// Persist saves the document and returns a confirmation summary.
	Persist() (summary string, err error)
	// Remove deletes the saved document and returns a summary.
	Remove() string
}

EditorDoc is the document an Editor edits. Implementations own all domain concerns — parsing, validation, persistence — and hand the Editor only strings, form fields and Results.

type EditorKeys added in v0.1.6

type EditorKeys struct {
	// Map resolves keys while the form or results pane has focus.
	Map *keys.Map
	// Confirm resolves keys while the delete dialog is open.
	Confirm *keys.Map

	Run      keys.Action
	Save     keys.Action
	Validate keys.Action
	Preview  keys.Action
	Delete   keys.Action
	Focus    keys.Action

	// Copy and Write drive EditorOutput. Leave them empty for documents that
	// produce no text.
	Copy  keys.Action
	Write keys.Action
}

EditorKeys binds an Editor's commands to a host application's key scheme. Actions are supplied by the caller because command vocabularies are app-specific; only Cancel and the navigation actions come from viewkit.

type EditorOutput added in v0.1.11

type EditorOutput interface {
	// CopyOutput puts the last run's text on the clipboard.
	CopyOutput() (summary string, err error)
	// WriteOutput persists the last run's text and names where it landed.
	WriteOutput() (summary string, err error)
}

EditorOutput is an optional EditorDoc extension for documents whose run produces text worth taking away — a rendered report, a generated file. An Editor offers Copy and Write only when its doc implements this and the host bound the matching keys, so documents without an output are unaffected.

type FormKeys added in v0.1.6

type FormKeys struct {
	// Map resolves keys while the form has focus. A nil Map falls back to the
	// active scheme's editor bindings (navigation, confirm, cancel, erase,
	// paging), resolved fresh on every key so a later keys.Use still applies.
	Map *keys.Map
	// Save is the action that triggers OnSubmit. Leave it empty for a form
	// with no save command (submit then only happens through OnKey).
	Save keys.Action
}

FormKeys binds a FormView's commands to a host application's key scheme. Only cancel comes from viewkit's vocabulary (keys.Cancel, resolved through Map); the save action is supplied by the caller because command vocabularies are app-specific — an app may name it "app.save" and bind it to ctrl+s, or name it something else entirely. This mirrors EditorKeys.

type FormSpec added in v0.1.6

type FormSpec struct {
	// Fields build the form, in display order.
	Fields []forms.Field
	// Keys binds cancel and save.
	Keys FormKeys

	// Title heads the breadcrumb trail. TitleFunc wins when both are set,
	// for views whose title depends on state ("new role" vs "edit role").
	Title string
	// TitleFunc computes the title on every read.
	TitleFunc func() string
	// PanelTitle heads the rendered form panel. Defaults to the view title,
	// which is what most forms want; set it when the panel wants a longer
	// caption than the breadcrumb.
	PanelTitle string

	// Context supplies chrome context cues. ContextFunc wins when both are
	// set; use it when the cues can change while the form is open.
	Context [][2]string
	// ContextFunc computes context cues on every read.
	ContextFunc func() [][2]string
	// Hints overrides the footer legend. When nil, the legend is derived from
	// Keys: field movement, value change, and the save binding.
	Hints [][2]string

	// OnSubmit runs on the save action with the form's current values. It
	// receives the Model so it can Pop back and Push a result view. A nil
	// OnSubmit makes save a no-op.
	OnSubmit func(a *Model, vals map[string]any) tea.Cmd
	// OnKey sees every key before the form does. Return handled=true to
	// suppress all default handling — including cancel, save and text entry —
	// which is how a view adds its own commands (delete, preview) on top of
	// the shared form behaviour.
	OnKey func(a *Model, key tea.KeyMsg) (cmd tea.Cmd, handled bool)
	// OnMsg sees every message before anything else, keys included. Views
	// whose save runs as a tea.Cmd use it to catch the completion message and
	// either Pop or Status the error.
	OnMsg func(a *Model, msg tea.Msg) (cmd tea.Cmd, handled bool)
}

FormSpec configures a FormView. Every field beyond Fields is optional, and most views set only two or three of them; a struct keeps those call sites readable and lets the type grow a knob without breaking anyone, which a ten-argument constructor could not.

type FormView added in v0.1.6

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

FormView is a single-panel form View: the boilerplate sibling of Menu, Message and Scroll. It owns the form, key routing (cancel pops, save calls back, everything else is navigation or text entry) and an error line under the panel. Domain concerns stay in the spec's callbacks.

func NewFormView added in v0.1.6

func NewFormView(spec FormSpec) *FormView

NewFormView builds a form View from spec.

func (*FormView) Body added in v0.1.6

func (v *FormView) Body(width, _ int) string

Body renders the form panel, with the status line appended when set.

func (*FormView) Context added in v0.1.6

func (v *FormView) Context() [][2]string

Context reports the chrome context cues.

func (*FormView) Form added in v0.1.6

func (v *FormView) Form() *forms.Form

Form exposes the live form so hosts can read or seed entered values.

func (*FormView) Hints added in v0.1.6

func (v *FormView) Hints() [][2]string

Hints reports the footer legend: the spec's override, else one derived from the bound keys so the legend cannot advertise a binding the view ignores.

func (*FormView) Init added in v0.1.6

func (v *FormView) Init() tea.Cmd

Init satisfies View; a form has nothing to load.

func (*FormView) Status added in v0.1.6

func (v *FormView) Status(msg string)

Status sets the error line shown beneath the form; "" clears it.

func (*FormView) Title added in v0.1.6

func (v *FormView) Title() string

Title reports the breadcrumb title.

func (*FormView) Update added in v0.1.6

func (v *FormView) Update(a *Model, msg tea.Msg) tea.Cmd

Update routes a message: OnMsg first, then OnKey, then cancel / save / form navigation, and finally text entry for unbound runes.

func (*FormView) Values added in v0.1.6

func (v *FormView) Values() map[string]any

Values returns the form's current values, the same map OnSubmit receives.

type HomeShell

type HomeShell struct {

	// BoxTitle is the menu TitledBox title. Empty (default) omits the title.
	BoxTitle string
	// SideLabel is shown above the side list when SideFetch is set.
	SideLabel string
	// SideLabelFn, when set, supplies the side label on every read instead of
	// SideLabel — the shape a long-lived shell needs when the side pane's
	// subject can change beneath it. Returning "" hides the side pane.
	SideLabelFn func() string
	// SideHint is the tab-target label when menu-focused (default "side").
	SideHint string
	// SideFetch loads opaque side content once (nil disables the side pane).
	SideFetch func() any
	// SideBind maps fetched data → rows using current width.
	SideBind func(width int, fetched any) []list.Item
	// SideLoading shown while SideFetch has not completed.
	SideLoading string
	// ReloadHint is the footer label for the reload key (default "reload").
	ReloadHint string

	// IsAction maps a key string to a keys.Action, fully replacing the active
	// scheme map (keys.Cur); map PageUp/PageDown and FocusNext to keep paging
	// and pane switching.
	IsAction func(string) (keys.Action, bool)
	// OnOpen overrides browser.Open when a side item Key is opened.
	OnOpen   func(url string) error
	OnSelect func(h *Model, key string) tea.Cmd
	// contains filtered or unexported fields
}

HomeShell is a dual-pane View: navigable menu + optional side Item list. SideFetch/SideBind keep domain types out of deck (caller maps → list.Item).

func NewHomeShell

func NewHomeShell(title string, ctx [][2]string, items []MenuItem, sideLabel string) *HomeShell

NewHomeShell builds a HomeShell. sideLabel empty + SideFetch nil → menu-only. BoxTitle defaults empty (no menu titled-box title); set after construction if desired.

func (*HomeShell) Body

func (h *HomeShell) Body(width, height int) string

func (*HomeShell) Context

func (h *HomeShell) Context() [][2]string

func (*HomeShell) FocusSide

func (h *HomeShell) FocusSide() bool

FocusSide reports whether the side pane has keyboard focus (for tests/adapters).

func (*HomeShell) Hints

func (h *HomeShell) Hints() [][2]string

func (*HomeShell) Init

func (h *HomeShell) Init() tea.Cmd

func (*HomeShell) Reload added in v0.1.11

func (h *HomeShell) Reload() tea.Cmd

Reload drops fetched side content and re-runs SideFetch, showing SideLoading until the new data lands. No-op when there is nothing to fetch.

func (*HomeShell) Title

func (h *HomeShell) Title() string

func (*HomeShell) Update

func (h *HomeShell) Update(host *Model, msg tea.Msg) tea.Cmd

type Host

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

Host is the tea model: stack navigation + chrome. Prefer the Model alias in new code; Host remains for compatibility.

func (*Host) Height

func (h *Host) Height() int

Height returns the current terminal height.

func (*Host) Init

func (h *Host) Init() tea.Cmd

func (*Host) Pop

func (h *Host) Pop() tea.Cmd

Pop leaves the current view (quits on root).

func (*Host) Push

func (h *Host) Push(v View) tea.Cmd

Push navigates to v.

func (*Host) RefreshStatus added in v0.1.3

func (h *Host) RefreshStatus() tea.Cmd

RefreshStatus reloads the status strip via the installed StatusFunc. Same path as the periodic refresh ticker; no-op when WithStatus was not set.

func (*Host) SetStatus

func (h *Host) SetStatus(info StatusInfo)

SetStatus applies chrome status immediately (tests / non-async hosts).

func (*Host) Top

func (h *Host) Top() View

Top returns the current view.

func (*Host) Update

func (h *Host) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Host) View

func (h *Host) View() string

func (*Host) Width

func (h *Host) Width() int

Width returns the current terminal width.

type ItemList

type ItemList struct {

	// Fetch loads opaque content once (optional if Bind alone is enough).
	Fetch func() any
	// Bind turns fetched data into list rows. Called on each refresh after load.
	Bind func(width int, fetched any) []list.Item

	// ChromeReserve is subtracted from window height for title/status chrome.
	ChromeReserve int
	// IsCancel reports whether a key string should pop the view.
	IsCancel func(string) bool
	// IsAction maps a key string to a keys.Action, fully replacing the active
	// scheme map (keys.Cur); map PageUp/PageDown too to keep paging.
	IsAction func(string) (keys.Action, bool)
	// OnOpen overrides browser.Open when an item Key is opened.
	OnOpen   func(url string) error
	OnSelect func(h *Model, key string) tea.Cmd
	// LoadingText shown before load completes.
	LoadingText string
	// ReloadHint is the footer label for the reload key (default "reload").
	ReloadHint string
	// contains filtered or unexported fields
}

ItemList is a lazy-loaded selectable list View. Fetch runs once on Init; Bind maps fetched data → rows using the current width so callers can width-wrap without importing domain types into deck.

func NewItemList

func NewItemList(title string, ctx [][2]string, fetch func() any, bind func(width int, fetched any) []list.Item) *ItemList

NewItemList builds an ItemList with Fetch+Bind.

func (*ItemList) Body

func (r *ItemList) Body(width, height int) string

func (*ItemList) Context

func (r *ItemList) Context() [][2]string

func (*ItemList) Hints

func (r *ItemList) Hints() [][2]string

func (*ItemList) Init

func (r *ItemList) Init() tea.Cmd

func (*ItemList) Reload added in v0.1.11

func (r *ItemList) Reload() tea.Cmd

Reload drops fetched content and re-runs Fetch, showing LoadingText until the new data lands. No-op when there is nothing to fetch.

func (*ItemList) Selected added in v0.1.11

func (r *ItemList) Selected() (list.Item, bool)

Selected returns the highlighted row, if any. Hosts that decorate an ItemList with their own row commands need it to know what the command applies to.

func (*ItemList) Title

func (r *ItemList) Title() string

func (*ItemList) Update

func (r *ItemList) Update(h *Model, msg tea.Msg) tea.Cmd

type Job added in v0.1.5

type Job struct {
	Label string
	Do    func(ctx context.Context) (Content, error)
}

Job is one unit of work. Do must be safe for concurrent execution; return Content (never domain types).

type KeyHook

type KeyHook func(m *Model, key tea.KeyMsg) (cmd tea.Cmd, handled bool)

KeyHook handles a key before the top view. Return handled=true to skip view Update (and optionally a Cmd such as Push).

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

Menu is a simple navigable list View.

func NewMenu

func NewMenu(title string, ctx [][2]string, items ...MenuItem) *Menu

NewMenu builds a Menu view.

func (m *Menu) Body(width, height int) string
func (m *Menu) Context() [][2]string
func (m *Menu) Hints() [][2]string
func (m *Menu) Init() tea.Cmd
func (m *Menu) Title() string
func (m *Menu) Update(h *Model, msg tea.Msg) tea.Cmd
type MenuItem struct {
	Label string
	Desc  string
	Icon  string
	Hue   int
	Do    func(m *Model) tea.Cmd
}

MenuItem is one row in a Menu.

type Message

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

Message is a dismissible text View.

func NewMessage

func NewMessage(title, body string, ctx [][2]string) *Message

NewMessage builds a Message view.

func (*Message) Body

func (m *Message) Body(width, _ int) string

func (*Message) Context

func (m *Message) Context() [][2]string

func (*Message) Hints

func (m *Message) Hints() [][2]string

func (*Message) Init

func (m *Message) Init() tea.Cmd

func (*Message) Title

func (m *Message) Title() string

func (*Message) Update

func (m *Message) Update(h *Model, msg tea.Msg) tea.Cmd

type Model

type Model = Host

Model is the stateful Bubble Tea program root for deck: navigable view stack, injectable chrome, and async status strip. It implements tea.Model (Init / Update / View).

Contract:

  • One Model owns one tea.Program for a deck session.
  • Views receive *Model in Update so they can Push/Pop and read size.
  • Domain state lives in View implementations (or app kits), not in Model.

Host is a compatibility alias; prefer Model in new code and docs.

func New

func New(root View, opts ...Option) *Model

New builds a Model with root view.

type MsgHook added in v0.1.4

type MsgHook func(m *Model, msg tea.Msg) (cmd tea.Cmd, handled bool)

MsgHook handles a non-key message before the top view. Return handled=true to skip view Update (e.g. debounced role-lifecycle settle).

type Option

type Option func(*Model)

Option configures Model (Host alias).

func WithChrome

func WithChrome(c Chrome) Option

WithChrome sets brand chrome.

func WithInitCmd added in v0.1.11

func WithInitCmd(cmd tea.Cmd) Option

WithInitCmd adds a command to run when the program starts, alongside the root view's own Init. Use it to start a watcher that outlives navigation: a tick armed here and re-armed from a MsgHook keeps running whatever is on the stack, whereas one armed by a view stops as soon as that view is pushed over.

Repeated calls accumulate.

func WithKeyHook

func WithKeyHook(fn KeyHook) Option

WithKeyHook installs a global key interceptor (e.g. app hotkeys).

func WithKeyMapQuit

func WithKeyMapQuit() Option

WithKeyMapQuit installs a quit matcher from keys.Cur() Quit binding. This is also the default; the option remains for explicit call sites.

func WithMsgHook added in v0.1.4

func WithMsgHook(fn MsgHook) Option

WithMsgHook installs a global message interceptor (e.g. debounce settle).

func WithQuitCheck

func WithQuitCheck(fn func(string) bool) Option

WithQuitCheck overrides quit key matcher. An opaque matcher cannot be rendered, so pair it with WithQuitHint to keep the footer legend truthful.

func WithQuitHint added in v0.1.5

func WithQuitHint(glyph string) Option

WithQuitHint overrides the quit glyph in the footer legend. Defaults to the active scheme's Quit binding.

func WithStatus

func WithStatus(fn StatusFunc) Option

WithStatus installs an async status loader for the footer strip.

func WithoutClock added in v0.1.13

func WithoutClock() Option

type PromptSpec added in v0.1.9

type PromptSpec struct {
	// Title heads the rendered panel.
	Title string
	// Fields builds the form, seeded from previously entered values. It is
	// called again after every Sync, exactly like EditorDoc.Fields.
	Fields func(prev map[string]any) []forms.Field
	// Sync reports whether the last edit changed a value the field set
	// depends on, and so whether to rebuild. A nil Sync never rebuilds.
	Sync func(vals map[string]any) bool
	// Seed pre-fills the form.
	Seed map[string]any
	// Save is the action that submits. It defaults to keys.Confirm when left
	// empty; hosts with a save binding of their own pass it here.
	Save keys.Action
	// Keys resolves keys. A nil Map falls back to the active scheme's editor
	// bindings, like FormView.
	Keys *keys.Map
}

PromptSpec configures a one-shot form prompt. It is the Editor's shape minus everything a command-line caller has no use for — no results pane, no preview, no persistence — so a CLI command can collect the same fields, with the same suggestions, without entering the deck.

type ReloadMsg added in v0.1.11

type ReloadMsg struct{}

ReloadMsg asks the active view to discard what it fetched and fetch again. Views that load lazily honour it; the rest ignore it, so it is safe to emit from a global key hook without knowing what is on top of the stack.

type Results added in v0.1.6

type Results interface {
	// Items renders the result set as list rows sized to f.
	Items(f layout.Frame) []list.Item
	// Count reports how many underlying records the rows represent.
	Count() int
}

Results is the lower pane of an Editor: whatever a run produced.

type Scroll

type Scroll struct {

	// ChromeReserve is subtracted from window height for title/status chrome.
	ChromeReserve int
	// IsCancel reports whether a key string should pop the view.
	IsCancel func(string) bool
	// ReloadHint is the footer label for the reload key (default "reload").
	ReloadHint string
	// contains filtered or unexported fields
}

Scroll is a lazy-loaded scrollable text view (bubbles viewport). Hosted only in the deck module so tea stays out of viewkit core.

func NewScroll

func NewScroll(title string, ctx, hints [][2]string, load func() string) *Scroll

NewScroll builds a Scroll view. load is invoked once on Init.

func (*Scroll) Body

func (c *Scroll) Body(width, height int) string

func (*Scroll) Context

func (c *Scroll) Context() [][2]string

func (*Scroll) Hints

func (c *Scroll) Hints() [][2]string

func (*Scroll) Init

func (c *Scroll) Init() tea.Cmd

func (*Scroll) Reload added in v0.1.11

func (c *Scroll) Reload() tea.Cmd

Reload discards the rendered body and re-runs load, showing the loading placeholder until the new text lands. No-op when there is nothing to load.

func (*Scroll) Title

func (c *Scroll) Title() string

func (*Scroll) Update

func (c *Scroll) Update(h *Model, msg tea.Msg) tea.Cmd

type ScrollContent

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

ScrollContent is a lazy-loaded scrollable text View.

func NewScrollContent

func NewScrollContent(title string, ctx, hints [][2]string, load func() string) *ScrollContent

NewScrollContent builds a content view that loads asynchronously.

func (*ScrollContent) Body

func (c *ScrollContent) Body(width, height int) string

func (*ScrollContent) Context

func (c *ScrollContent) Context() [][2]string

func (*ScrollContent) Hints

func (c *ScrollContent) Hints() [][2]string

func (*ScrollContent) Init

func (c *ScrollContent) Init() tea.Cmd

func (*ScrollContent) Title

func (c *ScrollContent) Title() string

func (*ScrollContent) Update

func (c *ScrollContent) Update(h *Model, msg tea.Msg) tea.Cmd

type ServiceStatus

type ServiceStatus struct {
	Name   string
	Detail string
	Level  StatusLevel
	Glyph  string
	Color  lipgloss.TerminalColor
}

ServiceStatus is one right-strip status chip.

type StatusFunc

type StatusFunc func(context.Context) StatusInfo

StatusFunc loads status asynchronously for the chrome strip.

type StatusInfo

type StatusInfo struct {
	Identity string
	Services []ServiceStatus
}

StatusInfo is optional chrome identity + service chips.

type StatusLevel

type StatusLevel int

StatusLevel aliases theme severity for status chips.

type Text

type Text string

Text is a Content adapter for pre-rendered strings.

func (Text) Render

func (t Text) Render(int) string

Render implements Content.

type Toaster added in v0.1.6

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

Toaster owns a view's notification lifecycle: a TTL queue, the once-a-second prune tick, and the overlay that floats the current notification over a rendered body. Embed one in a View and forward Update / Body to it.

Expiry does not depend on the tick arriving. Body prunes against the clock before it reads the queue, so a tick lost while another view was on top (see toastPruneMsg) delays nothing the user can see; the tick exists to repaint on time, not to be the only thing that expires a toast.

func NewToaster added in v0.1.6

func NewToaster(capacity int, ttl time.Duration) *Toaster

NewToaster builds a Toaster holding at most capacity notifications (0 for unbounded), each shown for ttl.

func (*Toaster) Body added in v0.1.6

func (t *Toaster) Body(body string, width int) string

Body overlays the current notification on an already-rendered body, sized for the same screen width the body was rendered at. It returns body unchanged when nothing is showing.

func (*Toaster) Prune added in v0.1.6

func (t *Toaster) Prune()

Prune expires everything past its TTL. Body does this already; call it directly before reading Queue in a view that renders notifications itself.

func (*Toaster) Push added in v0.1.6

func (t *Toaster) Push(n notify.Notification) tea.Cmd

Push shows n for the Toaster's default TTL and returns the command that keeps the prune loop running. Return it from the view's Update.

func (*Toaster) PushFor added in v0.1.6

func (t *Toaster) PushFor(n notify.Notification, ttl time.Duration) tea.Cmd

PushFor shows n for ttl, overriding the Toaster's default.

func (*Toaster) Queue added in v0.1.6

func (t *Toaster) Queue() *notify.Queue

Queue exposes the underlying queue for views that render notifications themselves (a panel of recent items, say) instead of as an overlay.

func (*Toaster) SetOverlayPos added in v0.1.6

func (t *Toaster) SetOverlayPos(pos layout.OverlayPos)

SetOverlayPos moves the toast card. It defaults to top centre.

func (*Toaster) Tick added in v0.1.6

func (t *Toaster) Tick() tea.Cmd

Tick arms the prune loop and returns the command to run, or nil when a tick is already in flight or there is nothing left to expire. Views that push notifications through Push / PushFor never need to call it; a view that restores a Toaster it filled earlier (after a Pop back onto it) can.

func (*Toaster) Update added in v0.1.6

func (t *Toaster) Update(msg tea.Msg) (cmd tea.Cmd, handled bool)

Update consumes this Toaster's prune tick. It reports handled=false for every other message — including another Toaster's tick — so the view can carry on dispatching. The returned command re-arms the loop while notifications remain.

type View

type View interface {
	Title() string
	Init() tea.Cmd
	Update(m *Model, msg tea.Msg) tea.Cmd
	Body(width, height int) string
	Hints() [][2]string
	Context() [][2]string
}

View is a navigable screen hosted by Model. Apps implement domain views; the tea runtime lives only in this module (tea must not enter viewkit core).

func LookupView

func LookupView(id string) (View, bool)

LookupView returns a fresh View for id.

func WithExtraHints added in v0.1.6

func WithExtraHints(inner View, extra [][2]string) View

WithExtraHints wraps inner so the footer legend carries extra after the view's own hints. Every other method passes through untouched. inner is returned unchanged when extra is empty, so the wrapper never costs a level of indirection it does not earn.

func WithLiveContext added in v0.1.6

func WithLiveContext(inner View, fn func() [][2]string) View

WithLiveContext wraps inner so its chrome context cues are recomputed on every render rather than captured when the view was built — the shape a long-lived view needs when the cue (active role, selection, count) can change beneath it. Every other method passes through untouched. inner is returned unchanged when fn is nil.

type Work added in v0.1.5

type Work []Job

Work is a set of jobs run together: Execute is the headless driver, Run the tea progressive UI driver.

func (Work) Execute added in v0.1.5

func (w Work) Execute(ctx context.Context) ([]Content, error)

Execute runs the jobs concurrently via errgroup and returns bodies in order.

func (Work) Run added in v0.1.5

func (w Work) Run(ctx context.Context) error

Run shows a progressive tea UI while the jobs run under errgroup. Finished results print to scrollback in job order. Quit keys follow keys.Cur().

Jump to

Keyboard shortcuts

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