tui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tui is the shared foundation for Spaniel's terminal UIs (Bubble Tea + Lipgloss). All TUI-mode subcommands pull their colors, spacing, and small reusable widgets from this package so the look stays consistent.

The palette mirrors the frontend "Drift" theme (sky/sand/slate) — see frontend/src/index.css and the project_design_system memory.

Index

Constants

This section is empty.

Variables

View Source
var (
	Ink    = lipgloss.NewStyle().Foreground(colorInk)
	Muted  = lipgloss.NewStyle().Foreground(colorInk2)
	Faint  = lipgloss.NewStyle().Foreground(colorInk3)
	Accent = lipgloss.NewStyle().Foreground(colorAccent)
	Ok     = lipgloss.NewStyle().Foreground(colorOk)
	Warn   = lipgloss.NewStyle().Foreground(colorWarn)
	Danger = lipgloss.NewStyle().Foreground(colorDanger)

	// Bold accent for things like header titles and active-tab labels.
	Title = lipgloss.NewStyle().Foreground(colorAccent).Bold(true)
	// Header bar across the top of every screen — bottom border in --line.
	Header = lipgloss.NewStyle().
			Foreground(colorInk).
			Bold(true).
			BorderStyle(lipgloss.NormalBorder()).
			BorderBottom(true).
			BorderForeground(colorLine).
			Padding(0, 1)
	// Footer with help/keys — top border, muted ink.
	Footer = lipgloss.NewStyle().
			Foreground(colorInk2).
			BorderStyle(lipgloss.NormalBorder()).
			BorderTop(true).
			BorderForeground(colorLine).
			Padding(0, 1)
	// KeyHint matches the inline `<kbd>` chips on the web side.
	KeyHint = lipgloss.NewStyle().
			Foreground(colorInk).
			Background(colorSurface2).
			Padding(0, 1)
	// Badge — small inline tag (severity, status, kind).
	Badge = lipgloss.NewStyle().Padding(0, 1).Bold(true)

	// Panel — bordered box for side panes (trace attributes, doctor detail).
	Panel = lipgloss.NewStyle().
			BorderStyle(lipgloss.RoundedBorder()).
			BorderForeground(colorLine).
			Padding(0, 1)

	// SelectedRow — used by tables/lists to highlight focus.
	SelectedRow = lipgloss.NewStyle().
				Foreground(colorInk).
				Background(colorSurface2).
				Bold(true)

	// Toast — error/warning overlays.
	Toast = lipgloss.NewStyle().
			Foreground(colorDanger).
			BorderStyle(lipgloss.RoundedBorder()).
			BorderForeground(colorDanger).
			Padding(0, 1)
)

Style registry. These are package-level vars so callers can do `tui.Danger.Render("x")` without setup. Lipgloss styles are copy-on-write — embedding one and chaining `.Bold(true)` etc. is cheap.

View Source
var Keys = struct {
	Quit     key.Binding
	Help     key.Binding
	Up       key.Binding
	Down     key.Binding
	Left     key.Binding
	Right    key.Binding
	PageUp   key.Binding
	PageDown key.Binding
	Home     key.Binding
	End      key.Binding
	Enter    key.Binding
	Filter   key.Binding
	Pause    key.Binding
	Follow   key.Binding
	Copy     key.Binding
	Clear    key.Binding
	Tab      key.Binding
	ShiftTab key.Binding
	Rerun    key.Binding
}{
	Quit:     key.NewBinding(key.WithKeys("q", "ctrl+c"), key.WithHelp("q", "quit")),
	Help:     key.NewBinding(key.WithKeys("?"), key.WithHelp("?", "help")),
	Up:       key.NewBinding(key.WithKeys("up", "k"), key.WithHelp("↑/k", "up")),
	Down:     key.NewBinding(key.WithKeys("down", "j"), key.WithHelp("↓/j", "down")),
	Left:     key.NewBinding(key.WithKeys("left", "h"), key.WithHelp("←/h", "left")),
	Right:    key.NewBinding(key.WithKeys("right", "l"), key.WithHelp("→/l", "right")),
	PageUp:   key.NewBinding(key.WithKeys("pgup", "b"), key.WithHelp("pgup", "page up")),
	PageDown: key.NewBinding(key.WithKeys("pgdown", "f", " "), key.WithHelp("pgdn", "page down")),
	Home:     key.NewBinding(key.WithKeys("home", "g"), key.WithHelp("g", "top")),
	End:      key.NewBinding(key.WithKeys("end", "G"), key.WithHelp("G", "bottom")),
	Enter:    key.NewBinding(key.WithKeys("enter"), key.WithHelp("enter", "select")),
	Filter:   key.NewBinding(key.WithKeys("/"), key.WithHelp("/", "filter")),
	Pause:    key.NewBinding(key.WithKeys("p"), key.WithHelp("p", "pause")),
	Follow:   key.NewBinding(key.WithKeys("F"), key.WithHelp("F", "follow")),
	Copy:     key.NewBinding(key.WithKeys("y"), key.WithHelp("y", "copy")),
	Clear:    key.NewBinding(key.WithKeys("c"), key.WithHelp("c", "clear")),
	Tab:      key.NewBinding(key.WithKeys("tab"), key.WithHelp("tab", "next pane")),
	ShiftTab: key.NewBinding(key.WithKeys("shift+tab"), key.WithHelp("⇧tab", "prev pane")),
	Rerun:    key.NewBinding(key.WithKeys("r"), key.WithHelp("r", "rerun")),
}

Keys is the shared key.Binding set used across every TUI screen. Defining them centrally means the footer help text and the actual handlers can't drift — every screen renders the same hint for the same action.

Functions

func FooterHelp

func FooterHelp(bindings []key.Binding, width int) string

FooterHelp renders a one-line footer showing a subset of bound keys. Pass only the bindings that are actually active right now so the user's eyes don't have to filter noise.

func HeaderBar

func HeaderBar(title string, pills []string, width int) string

HeaderBar renders the top chrome for a TUI screen.

title    — bolded screen name (e.g. "spaniel watch")
pills    — small badges shown to the right of the title (active filters,
           connection status). Empty strings are skipped.
width    — total terminal width; the bar fills it.

func JoinVertical

func JoinVertical(parts ...string) string

JoinVertical is a thin shim over lipgloss.JoinVertical that picks Left alignment — the right default for top-down stacked screens.

func SeverityStyle

func SeverityStyle(sev int) lipgloss.Style

SeverityStyle returns the right style for an OTel severity number. Mirrors the colorization in the old printf path so logs/spans look consistent across all views.

func StatusStyle

func StatusStyle(code int) lipgloss.Style

StatusStyle picks a style based on an OTel span status code. 2 = ERROR, anything else = OK.

Types

This section is empty.

Jump to

Keyboard shortcuts

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