deck

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 17 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 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 RunFlight

func RunFlight(ctx context.Context, tasks []Task) error

RunFlight shows a progressive tea UI while tasks run under errgroup. Quit keys follow keys.Cur() (Quit / Cancel).

func ViewIDs

func ViewIDs() []string

ViewIDs returns registered view ids sorted.

Types

type Chrome

type Chrome struct {
	Brand      string // e.g. "MUNIN"
	BrandGlyph string
	Subtitle   string // e.g. "ono-sendai deck"
	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 flight/panel body text. Apps adapt their types (e.g. munin signals.Section trees) into Content before crossing into deck.

func Execute

func Execute(ctx context.Context, tasks []Task) ([]Content, error)

Execute runs tasks concurrently via errgroup and returns bodies in order. This is the headless driver; RunFlight is the tea progressive UI driver.

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 HomeShell

type HomeShell struct {

	// SideLabel is shown above the side list when SideFetch is set.
	SideLabel 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

	// IsAction maps a key string to a keys.Action (defaults to keys.Cur menu map).
	IsAction func(string) (keys.Action, bool)
	// OnOpen overrides browser.Open when a side item Key is confirmed.
	OnOpen func(url string) error
	// 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.

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) 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) 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 (defaults to keys.Cur menu map).
	IsAction func(string) (keys.Action, bool)
	// OnOpen overrides browser.Open when an item Key is confirmed.
	OnOpen func(url string) error
	// LoadingText shown before load completes.
	LoadingText 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) Title

func (r *ItemList) Title() string

func (*ItemList) Update

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

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, _ 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 Option

type Option func(*Model)

Option configures Model (Host alias).

func WithChrome

func WithChrome(c Chrome) Option

WithChrome sets brand chrome.

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.

func WithQuitCheck

func WithQuitCheck(fn func(string) bool) Option

WithQuitCheck overrides quit key matcher.

func WithStatus

func WithStatus(fn StatusFunc) Option

WithStatus installs an async status loader for the footer strip.

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
	// 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) 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 // e.g. "@user ✓"
	Services []ServiceStatus
}

StatusInfo is optional chrome identity + service chips.

type StatusLevel

type StatusLevel int

StatusLevel aliases theme severity for status chips.

type Task

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

Task is one unit of work in a flight. Run must be safe for concurrent execution; return Content (never domain types).

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 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.

Jump to

Keyboard shortcuts

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