tui

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const CompactHeaderThreshold = 15

CompactHeaderThreshold is the terminal height below which the header collapses to a single line.

View Source
const TickInterval = 250 * time.Millisecond

TickInterval is the base tick rate for the TUI event loop.

Variables

View Source
var (
	ColorCyan      = lipgloss.Color("#00d4ff")
	ColorPurple    = lipgloss.Color("#8b5cf6")
	ColorOrange    = lipgloss.Color("#f97316")
	ColorField     = lipgloss.Color("#0099cc")
	ColorError     = ColorPurple // lipgloss.Color("#ef4444") - this one is too similar to the orange
	ColorHighlight = lipgloss.Color("#1e2d3d")
)

Theme colors

Functions

func Debug

func Debug(format string, args ...any)

Debug prints a right-aligned bold purple "debug" followed by a message to stdout.

func Error

func Error(format string, args ...any)

Error prints a right-aligned bold orange "error" followed by a message to stderr.

func LineStyle

func LineStyle(highlighted bool) (lipgloss.Style, string)

LineStyle returns a base lipgloss style and cursor marker for a list row. When highlighted is true, the base style includes a highlight background and the marker is a colored arrow; otherwise the marker is two spaces.

func PrintHeader

func PrintHeader()

PrintHeader prints a branding header (wordmark + tagline) to stdout. It detects terminal size and uses the compact layout on short terminals.

func RenderBanner

func RenderBanner(width, height int) string

RenderBanner produces a branding-only header string (wordmark + tagline, no session info). It uses the compact layout when height < CompactHeaderThreshold.

func RenderHeader

func RenderHeader(info *HeaderInfo, width int, height int) string

RenderHeader produces the styled monitor header with wordmark, tagline, session info, and diagonal line field.

func RenderNameWithGradient added in v0.2.0

func RenderNameWithGradient() string

func Status

func Status(verb string, format string, args ...any)

Status prints a right-aligned bold cyan verb followed by a message to stdout.

Types

type Cursor

type Cursor struct {
	Pos       int // highlighted item index
	Offset    int // scroll offset (first visible item)
	VpHeight  int // visible rows
	ItemCount int // total items
}

Cursor provides scrollable list navigation. Screens that need a navigable list embed this struct and call HandleKey in their Update method.

func (*Cursor) AtEnd

func (c *Cursor) AtEnd() bool

AtEnd reports whether the cursor is on the last item.

func (*Cursor) EnsureVisible

func (c *Cursor) EnsureVisible()

EnsureVisible adjusts Offset so Pos is within the visible window.

func (*Cursor) FooterKeys

func (c *Cursor) FooterKeys() []FooterKey

FooterKeys returns the standard navigation keybinding hints.

func (*Cursor) HandleKey

func (c *Cursor) HandleKey(msg tea.KeyPressMsg) bool

HandleKey processes navigation keys (j/k/G/g/arrows/pgdn/pgup). Returns true if the key was handled.

type FooterKey

type FooterKey struct {
	Key  string // display text for the key, e.g. "a"
	Desc string // description, e.g. "allow"
}

FooterKey describes a single keybinding hint shown in the footer.

type HeaderInfo

type HeaderInfo struct {
	ProjectDir string
	SessionID  string
}

func (HeaderInfo) ProjectDirWithHome

func (info HeaderInfo) ProjectDirWithHome() string

ProjectDirWithHome replaces the home directory path in the project dir with "$HOME" to shorten the value.

type Screen

type Screen interface {
	// Update handles input and custom messages. Returning a different Screen
	// switches the active screen. The Window pointer provides access to shared
	// state (dimensions, flash, error).
	Update(msg tea.Msg, w *Window) (Screen, tea.Cmd)

	// View renders the content area between header and footer.
	View(w *Window) string

	// FooterKeys returns context-sensitive keybinding hints for the right
	// side of the footer. These are prepended before the base keys.
	FooterKeys(w *Window) []FooterKey

	// FooterStatus returns an optional left-side indicator for the footer
	// (e.g. tailing animation, progress). Return "" for no indicator.
	FooterStatus(w *Window) string
}

Screen is implemented by each TUI screen (monitor, session selector, etc.).

type TickMsg

type TickMsg struct{}

TickMsg is sent on every tick interval. Screens receive it after Window increments the frame counter and expires flash messages.

type Window

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

Window is the top-level tea.Model. It owns the shared frame (header, footer, sizing, tick, flash/error) and delegates content to the active Screen.

func NewWindow

func NewWindow(header *HeaderInfo, screen Screen) *Window

func (*Window) ClearError

func (w *Window) ClearError()

func (*Window) Err

func (w *Window) Err() error

func (*Window) Flash

func (w *Window) Flash() string

func (*Window) Height

func (w *Window) Height() int

func (*Window) Init

func (w *Window) Init() tea.Cmd

func (*Window) IntervalElapsed

func (w *Window) IntervalElapsed(interval time.Duration) bool

IntervalElapsed returns true if the given interval has elapsed since the last tick.

func (*Window) SetError

func (w *Window) SetError(err error)

func (*Window) SetFlash

func (w *Window) SetFlash(msg string)

Mutators for screens to update shared state.

func (*Window) SetHeader

func (w *Window) SetHeader(info *HeaderInfo)

func (*Window) TickFrame

func (w *Window) TickFrame() int

func (*Window) Update

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

func (*Window) View

func (w *Window) View() tea.View

func (*Window) VpHeight

func (w *Window) VpHeight() int

func (*Window) Width

func (w *Window) Width() int

Accessors for screens to read shared state.

Jump to

Keyboard shortcuts

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