deck

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 23 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 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 ComponentKeys added in v0.2.0

func ComponentKeys() []string

ComponentKeys 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 ViewKeys added in v0.2.0

func ViewKeys() []string

ViewKeys 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 NamedComponent added in v0.2.0

func NamedComponent(id string) (Component, bool)

NamedComponent 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

Body implements View. When both panes exceed the height budget it collapses the unfocused pane — then both — to one-line summaries, and it overlays the delete-confirm dialog when that is open.

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() []keys.Hint

Context implements View, delegating to the document.

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() []keys.Hint

Hints implements View. The legend follows the current mode: delete confirmation, results pane, suggestion completion, or plain form editing.

func (*Editor) Init added in v0.1.6

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

Init implements View; an Editor needs no startup command.

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

Title implements View, delegating to the document.

func (*Editor) Update added in v0.1.6

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

Update implements View. Keys go to the delete-confirm dialog when it is open, otherwise to the focused pane (form or results); it also handles resize, run completion (editorRanMsg) and ReloadMsg re-runs.

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() []keys.Hint
	// 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 []keys.Hint
	// ContextFunc computes context cues on every read.
	ContextFunc func() []keys.Hint
	// Hints overrides the footer legend. When nil, the legend is derived from
	// Keys: field movement, value change, and the save binding.
	Hints []keys.Hint

	// 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() []keys.Hint

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() []keys.Hint

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 {
	// 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(spec HomeShellSpec) *HomeShell

NewHomeShell builds a HomeShell from spec.

func (*HomeShell) Body

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

Body implements View: the menu box, then the side list sized to the remaining height when a side pane is configured.

func (*HomeShell) Context

func (h *HomeShell) Context() []keys.Hint

Context implements View.

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() []keys.Hint

Hints implements View; the legend follows which pane has focus.

func (*HomeShell) Init

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

Init implements View, starting the side fetch when a side pane is configured.

func (*HomeShell) Reload added in v0.1.11

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

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

func (*HomeShell) Title

func (h *HomeShell) Title() string

Title implements View.

func (*HomeShell) Update

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

Update implements View, handling resize, side-load completion, ReloadMsg and keys for whichever pane has focus.

type HomeShellSpec added in v0.2.0

type HomeShellSpec struct {
	// Title heads the breadcrumb trail.
	Title string
	// Ctx supplies chrome context cues.
	Ctx []keys.Hint
	// Items are the menu rows.
	Items []MenuItem

	// 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 (default "░▒▓ loading…").
	SideLoading string
	// ReloadHint is the footer label for the reload key (default "reload").
	ReloadHint string

	// IsAction maps a key string to a keys.Action. It is consulted first; keys
	// it does not claim fall back to the active scheme map (keys.Cur), so
	// paging and pane switching keep working without re-mapping them.
	IsAction func(string) (keys.Action, bool)
	// OnOpen overrides browser.Open when a side item Key is opened.
	OnOpen func(url string) error
	// OnSelect handles Confirm on the highlighted side row. The full item is
	// passed so its Payload (and Key) are available without a side table.
	OnSelect func(h *Model, it list.Item) tea.Cmd
}

HomeShellSpec configures a HomeShell, following the FormSpec pattern: every field beyond Title and Items is optional. SideLabel empty + SideFetch nil → menu-only shell.

type ItemList

type ItemList struct {

	// Fetch loads opaque content once. Exported so hosts can wrap or replace
	// the loader after construction (e.g. tests counting fetches).
	Fetch func() any
	// OnOpen overrides browser.Open when an item Key is opened.
	OnOpen func(url string) error
	// OnSelect handles Confirm on the highlighted row.
	OnSelect func(h *Model, it list.Item) tea.Cmd
	// 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(spec ItemListSpec) *ItemList

NewItemList builds an ItemList from spec.

func (*ItemList) Body

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

Body implements View, rendering the loading text until Fetch lands.

func (*ItemList) Context

func (r *ItemList) Context() []keys.Hint

Context implements View.

func (*ItemList) Hints

func (r *ItemList) Hints() []keys.Hint

Hints implements View; the legend adapts to OnSelect and Fetch being set.

func (*ItemList) Init

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

Init implements View, kicking off Fetch — or reporting an immediate empty load when there is nothing to fetch.

func (*ItemList) Reload added in v0.1.11

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

Reload drops fetched content and re-runs Fetch, showing the loading text 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

Title implements View.

func (*ItemList) Update

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

Update implements View, handling resize, load completion, ReloadMsg and navigation keys.

type ItemListSpec added in v0.2.0

type ItemListSpec struct {
	// Title heads the breadcrumb trail.
	Title string
	// Ctx supplies chrome context cues.
	Ctx []keys.Hint

	// Fetch loads opaque content once on Init (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

	// IsCancel reports whether a key string should pop the view.
	IsCancel func(string) bool
	// IsAction maps a key string to a keys.Action. It is consulted first; keys
	// it does not claim fall back to the active scheme map (keys.Cur), so
	// paging and navigation keep working without re-mapping them.
	IsAction func(string) (keys.Action, bool)
	// OnOpen overrides browser.Open when an item Key is opened.
	OnOpen func(url string) error
	// OnSelect handles Confirm on the highlighted row. The full item is passed
	// so its Payload (and Key) are available without a side table.
	OnSelect func(h *Model, it list.Item) tea.Cmd
	// LoadingText shown before load completes (default "░▒▓ loading…").
	LoadingText string
	// ReloadHint is the footer label for the reload key (default "reload").
	ReloadHint string
}

ItemListSpec configures an ItemList, following the FormSpec pattern: every field beyond Title is optional, and a struct keeps the call sites readable while letting the type grow a knob without breaking anyone.

type Job added in v0.1.5

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

Job is one unit of work. Run 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 []keys.Hint, items ...MenuItem) *Menu

NewMenu builds a Menu view.

func (m *Menu) Body(width, height int) string

Body implements View, rendering the rows in a titled box.

func (m *Menu) Context() []keys.Hint

Context implements View.

func (m *Menu) Hints() []keys.Hint

Hints implements View.

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

Init implements View; a Menu needs no startup command.

func (m *Menu) Title() string

Title implements View.

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

Update implements View: Up/Down move the cursor, Confirm runs the row's OnSelect, Cancel pops.

type MenuItem struct {
	Label string
	Desc  string
	Icon  string
	Hue   int
	// OnSelect runs when the row is confirmed.
	OnSelect 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 NewError added in v0.2.0

func NewError(title string, err error, ctx []keys.Hint) *Message

NewError builds a Message that renders err in the theme's failure style — the standard error screen, so hosts stop hand-rolling Cant.Render(err).

func NewMessage

func NewMessage(title, body string, ctx []keys.Hint) *Message

NewMessage builds a Message view.

func (*Message) Body

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

Body implements View, rendering the text in a titled box.

func (*Message) Context

func (m *Message) Context() []keys.Hint

Context implements View.

func (*Message) Hints

func (m *Message) Hints() []keys.Hint

Hints implements View; a Message adds no legend entries of its own.

func (*Message) Init

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

Init implements View; a Message needs no startup command.

func (*Message) Title

func (m *Message) Title() string

Title implements View.

func (*Message) Update

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

Update implements View: Cancel or Confirm dismisses the message.

type Model

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

Model is the tea root: the stateful Bubble Tea program root for deck, owning the navigable view stack, injectable chrome, and the 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.

func New

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

New builds a Model with root view.

func (*Model) Height added in v0.2.0

func (h *Model) Height() int

Height returns the current terminal height.

func (*Model) Init added in v0.2.0

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

Init implements tea.Model: it starts the clock tick, the root view's Init, the status fetch when installed, and any WithInitCmd commands.

func (*Model) Pop added in v0.2.0

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

Pop leaves the current view (quits on root).

func (*Model) Push added in v0.2.0

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

Push navigates to v.

func (*Model) RefreshStatus added in v0.2.0

func (h *Model) 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 (*Model) SetStatus added in v0.2.0

func (h *Model) SetStatus(info StatusInfo)

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

func (*Model) Top added in v0.2.0

func (h *Model) Top() View

Top returns the current view.

func (*Model) Update added in v0.2.0

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

Update implements tea.Model. Chrome concerns — resize, clock, status, quit keys and installed hooks — are handled here; everything else routes to the top view, except an ownedMsg, which goes to its recipient even when that view is no longer on top.

func (*Model) View added in v0.2.0

func (h *Model) View() string

View implements tea.Model, framing the top view's Body between header and footer chrome (or a placeholder until the first resize arrives).

func (*Model) Width added in v0.2.0

func (h *Model) Width() int

Width returns the current terminal width.

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.

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

WithoutClock hides the header clock and disables its per-second tick.

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 {
	// 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(spec ScrollSpec) *Scroll

NewScroll builds a Scroll view from spec.

func (*Scroll) Body

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

Body implements View, resizing the viewport to the frame before rendering so the scroll offset stays within the content.

func (*Scroll) Context

func (c *Scroll) Context() []keys.Hint

Context implements View.

func (*Scroll) Hints

func (c *Scroll) Hints() []keys.Hint

Hints implements View: scrolling legend plus any spec-supplied hints.

func (*Scroll) Init

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

Init implements View, kicking off Load when one was supplied.

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

Title implements View.

func (*Scroll) Update

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

Update implements View: navigation keys scroll the viewport, Reload re-runs Load, Cancel (or an IsCancel match) pops the view.

type ScrollBody added in v0.2.0

type ScrollBody struct {
	layout.ScrollState
	// contains filtered or unexported fields
}

ScrollBody owns the scroll offset and row math that hand-rolled scrolling Views repeat: embed it, route navigation keys through Handle, and render through View with the height that View.Body receives (the deck passes the usable body height, so no chrome constants are needed).

func (v *myView) Body(width, height int) string {
	return v.scroll.View(render(width), height)
}

func (*ScrollBody) Handle added in v0.2.0

func (s *ScrollBody) Handle(act keys.Action) bool

Handle applies a navigation action to the scroll offset — Up/Down move one line, PageUp/PageDown move one window — and reports whether act was a scroll action. Row math comes from the last View call.

func (*ScrollBody) Total added in v0.2.0

func (s *ScrollBody) Total() int

Total returns the line count of the last body given to View.

func (*ScrollBody) View added in v0.2.0

func (s *ScrollBody) View(body string, height int) string

View windows body to height rows at the current offset and records the totals Handle needs. height is the usable body height View.Body receives.

type ScrollSpec added in v0.2.0

type ScrollSpec struct {
	// Title heads the breadcrumb trail.
	Title string
	// Ctx supplies chrome context cues.
	Ctx []keys.Hint
	// Hints are appended to the footer legend after the built-in ones.
	Hints []keys.Hint
	// Load produces the scrollable text; invoked once on Init.
	Load func() string
	// 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
}

ScrollSpec configures a Scroll, following the FormSpec pattern: every field beyond Title and Load is optional.

type ServiceStatus

type ServiceStatus struct {
	ID       string
	Name     string
	Detail   string
	Severity glyph.Severity
	Glyph    string
	Color    lipgloss.TerminalColor
}

ServiceStatus is one right-strip status chip. Severity drives the default glyph and color; Glyph and Color, when set, override that resolution. ID is an optional stable identifier apps can use to filter or configure chips.

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 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 names the view in the breadcrumb trail.
	Title() string
	// Init returns the command to run when the view is first shown.
	Init() tea.Cmd
	// Update handles one message. m is the hosting Model, for Push/Pop
	// and size; the returned command is run by the tea loop.
	Update(m *Model, msg tea.Msg) tea.Cmd
	// Body renders the view's content into the given width and height
	// (the area left between header and footer chrome).
	Body(width, height int) string
	// Hints lists key legend entries for the footer.
	Hints() []keys.Hint
	// Context lists key/label cues for the header context strip.
	Context() []keys.Hint
}

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 NamedView added in v0.2.0

func NamedView(id string) (View, bool)

NamedView returns a fresh View for id.

func WithExtraHints added in v0.1.6

func WithExtraHints(inner View, extra []keys.Hint) 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() []keys.Hint) 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: Collect is the headless driver, RunInteractive the tea progressive UI driver.

func (Work) Collect added in v0.2.0

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

Collect runs the jobs concurrently via errgroup and returns bodies in order, with no UI — the headless driver.

func (Work) RunInteractive added in v0.2.0

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

RunInteractive 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