components

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package components contains reusable TUI components.

Index

Constants

View Source
const FramesPerHop = 5

FramesPerHop is the number of animation frames in a single hop. Frame sequence: crouch(0), rise(1), peak(2), fall(3), land(4).

Variables

This section is empty.

Functions

func ApplyOverlayListStyles

func ApplyOverlayListStyles(m list.Model, st styles.Styles) list.Model

ApplyOverlayListStyles applies shared overlay foreground styling to list empty states.

func BunnyCloseCmd

func BunnyCloseCmd() tea.Cmd

BunnyCloseCmd schedules the eye-open 200 ms from now. It fires after the bunny has blinked, signalling time to reopen.

func BunnyHopIdleCmd

func BunnyHopIdleCmd() tea.Cmd

BunnyHopIdleCmd waits 10–25 seconds and then fires a hop sequence. The hop count (2 or 3) is chosen at fire time so that multiple instances started at the same wall-clock second don't all hop in sync.

func BunnyHopPauseTick

func BunnyHopPauseTick() tea.Cmd

BunnyHopPauseTick schedules a BunnyHopStepMsg after the between-hop pause. This gives the bunny a moment on the box before launching again.

func BunnyHopTick

func BunnyHopTick(d time.Duration) tea.Cmd

BunnyHopTick schedules a BunnyHopStepMsg after the given duration.

func BunnyOpenCmd

func BunnyOpenCmd() tea.Cmd

BunnyOpenCmd schedules the next blink 4 seconds from now. It fires after the bunny's eyes are already open, signalling time to blink.

func CalloutInnerWidth

func CalloutInnerWidth(st styles.Styles, width int) int

CalloutInnerWidth returns the content width available inside the callout shell.

func HopFrameDuration

func HopFrameDuration(frame int) time.Duration

HopFrameDuration returns the tick duration for each frame within a hop. Crouch/land are short (impact), rise/fall are medium, peak is longest (apex hang).

func HopFrameGap

func HopFrameGap(frame int) int

HopFrameGap returns the number of blank lines between the bunny and the box for the given frame index within a hop. This creates the vertical arc: crouch/land on the box (0 gaps), rise/fall at low height (1 gap), peak at max height (2 gaps).

func HopFrameProgress

func HopFrameProgress(frame int) float64

HopFrameProgress returns the horizontal progress (0.0–1.0) through the current individual hop for the given frame. The bunny accelerates during the first half and decelerates during the second half, mimicking a natural parabolic arc.

func NewTextArea

func NewTextArea() textarea.Model

NewTextArea returns a textarea.Model pre-configured with macOS-compatible key bindings. Use this everywhere in the TUI instead of textarea.New().

textarea's default key map omits ctrl+right and ctrl+left for word movement, while textinput's default includes them. macOSTextAreaKeyMap restores that parity so ⌥+→/← works in both component types regardless of whether the terminal sends the CSI alt+right/alt+left sequence or the ctrl+right/ctrl+left sequence.

func NewTextInput

func NewTextInput() textinput.Model

NewTextInput returns a textinput.Model ready for use. Use this everywhere in the TUI instead of textinput.New() so that input construction is centralised and any future key-binding or style changes apply uniformly without hunting call sites.

The default textinput key map already covers all standard macOS terminal editing shortcuts (⌥+Backspace → alt+backspace, ⌘+Backspace → ctrl+u, ⌥+←/→ → alt+left/right, ⌘+←/→ → ctrl+a/ctrl+e, word movement via ctrl+left/ctrl+right). No extra bindings are required for textinput.

func PaneInnerSize

func PaneInnerSize(st styles.Styles, width, height int) (int, int)

PaneInnerSize returns the content box available inside a shared pane shell.

func RenderBunny

func RenderBunny(phase int, side BunnySide) string

RenderBunny returns the 3-line ASCII bunny art for the given blink phase and corner side. The bottom line is the feet; callers should join this string above a bordered box using the matching lipgloss alignment so the foot character touches the box corner.

func RenderBunnyCrouch

func RenderBunnyCrouch(phase int) string

RenderBunnyCrouch returns the 3-line crouched bunny art for the given blink phase. Like RenderBunnyHop, lines have no intrinsic horizontal position.

func RenderBunnyHop

func RenderBunnyHop(phase int) string

RenderBunnyHop returns the 3-line airborne bunny art for the given blink phase. Lines have no intrinsic horizontal position: the caller is responsible for padding each line to the desired offset within the container width.

func RenderCallout

func RenderCallout(st styles.Styles, spec CalloutSpec) string

RenderCallout renders semantic bordered content.

func RenderDivider

func RenderDivider(st styles.Styles, width int) string

RenderDivider renders a full-width semantic divider.

func RenderHeaderBlock

func RenderHeaderBlock(st styles.Styles, spec HeaderBlockSpec) string

RenderHeaderBlock renders shared title/meta/divider workflow chrome.

func RenderKeyHints

func RenderKeyHints(st styles.Styles, hints []KeyHint, separator string) string

RenderKeyHints renders a semantic keybind row.

func RenderOverlayDivider

func RenderOverlayDivider(st styles.Styles, width int) string

RenderOverlayDivider renders a semantic divider line for overlay content.

func RenderOverlayFrame

func RenderOverlayFrame(st styles.Styles, frameWidth int, spec OverlayFrameSpec) string

RenderOverlayFrame renders the outer overlay shell around header, body, and footer content.

func RenderPane

func RenderPane(st styles.Styles, spec PaneSpec) string

RenderPane renders shared bordered pane chrome around already-sized content.

func RenderProgressBar

func RenderProgressBar(st styles.Styles, done, total, width int) string

RenderProgressBar renders a semantic text progress bar of the given width.

func RenderSplitOverlayBody

func RenderSplitOverlayBody(st styles.Styles, layout SplitOverlayLayout, spec SplitOverlaySpec) string

RenderSplitOverlayBody renders a split left/right pane body using a computed layout.

func RenderTabs

func RenderTabs(st styles.Styles, labels []string, active int, separator string) string

RenderTabs renders an active/inactive semantic tabs row.

func ToastTickCmd

func ToastTickCmd() tea.Cmd

ToastTickCmd returns a Cmd that fires after 1s.

Types

type BunnyBlinkMsg

type BunnyBlinkMsg struct{ Phase int }

BunnyBlinkMsg is dispatched when the blink animation state should change. Phase 0 = eyes open, phase 1 = eyes closed.

type BunnyHopStepMsg

type BunnyHopStepMsg struct{}

BunnyHopStepMsg advances the hop animation by one frame. It is reused for both in-hop frame advances and between-hop pauses.

type BunnyHopTriggerMsg

type BunnyHopTriggerMsg struct{ Hops int }

BunnyHopTriggerMsg begins a hop sequence. Hops is the number of individual hops (2 or 3), chosen randomly at fire time. A 2-hop sequence touches the box once; a 3-hop sequence touches it twice.

type BunnySide

type BunnySide int

BunnySide determines on which corner of the box the bunny sits. The value is chosen randomly at startup and held for the lifetime of the model.

const (
	BunnySideLeft  BunnySide = iota // bunny sits on the top-left corner  (╭)
	BunnySideRight                  // bunny sits on the top-right corner (╮)
)

type CalloutSpec

type CalloutSpec struct {
	Body    string
	Width   int
	Variant CalloutVariant
}

CalloutSpec describes a bordered content box.

type CalloutVariant

type CalloutVariant int

CalloutVariant selects the semantic surface treatment.

const (
	CalloutDefault CalloutVariant = iota
	CalloutCard
	CalloutWarning
	CalloutRunning // active/accent border color for in-progress tool cards
	CalloutError   // error border color for failed tool cards
	CalloutTool    // completed tool call — more visible border than CalloutDefault
)

type ConfirmDialog

type ConfirmDialog struct {
	Title   string
	Message string
	OnYes   tea.Cmd
	Active  bool
	Styles  styles.Styles
}

ConfirmDialog is a generic yes/no confirmation modal.

func NewConfirmDialog

func NewConfirmDialog(st styles.Styles, title, message string, onYes tea.Cmd) ConfirmDialog

NewConfirmDialog creates an active confirmation dialog.

func (ConfirmDialog) View

func (d ConfirmDialog) View() string

View renders the dialog; returns empty string when inactive.

type ConfirmMsg

type ConfirmMsg struct{ Confirmed bool }

ConfirmMsg is emitted when the dialog is resolved.

type HeaderBlockSpec

type HeaderBlockSpec struct {
	Title   string
	Meta    string
	Width   int
	Divider bool
	// StatusLine, when non-empty and Divider is true, replaces the ─── divider
	// row with this pre-rendered string. The header line count is unchanged;
	// callers can use this to show a transient warning in-place without pushing
	// subsequent content down.
	StatusLine string
}

HeaderBlockSpec describes a semantic title/meta/divider block.

type KeyHint

type KeyHint struct {
	Key   string
	Label string
}

KeyHint is a semantic key/label pair.

type OverlayFrameSpec

type OverlayFrameSpec struct {
	HeaderLines []string
	Body        string
	Footer      string
	Focused     bool
}

OverlayFrameSpec describes the outer overlay shell.

type OverlayPaneSpec

type OverlayPaneSpec struct {
	Title        string
	DividerWidth int
	Body         string
	Focused      bool
}

OverlayPaneSpec describes a bordered pane inside a split overlay body.

type PaneSpec

type PaneSpec struct {
	Content string
	Width   int
	Height  int
	Focused bool
}

PaneSpec describes a bordered application pane.

type RenderedKeyHint

type RenderedKeyHint struct {
	Raw      string
	Rendered string
}

RenderedKeyHint preserves both rendered and plain-text forms for layout decisions.

func RenderKeyHintFragments

func RenderKeyHintFragments(st styles.Styles, hints []KeyHint) []RenderedKeyHint

RenderKeyHintFragments styles individual keybind hints for shared consumption.

type SplitOverlayLayout

type SplitOverlayLayout struct {
	FrameWidth      int
	ContentWidth    int
	InputWidth      int
	BodyHeight      int
	LeftPaneWidth   int
	RightPaneWidth  int
	LeftInnerWidth  int
	RightInnerWidth int
	ListHeight      int
	ViewportWidth   int
	ViewportHeight  int
}

SplitOverlayLayout is the computed geometry for rendering a split overlay.

func ComputeSplitOverlayLayout

func ComputeSplitOverlayLayout(termWidth, termHeight, chromeLines int, spec SplitOverlaySizingSpec) SplitOverlayLayout

ComputeSplitOverlayLayout calculates the shared geometry for split overlays.

type SplitOverlaySizingSpec

type SplitOverlaySizingSpec struct {
	MaxOverlayWidth   int
	LeftMinWidth      int
	RightMinWidth     int
	LeftWeight        int
	RightWeight       int
	MinBodyHeight     int
	DefaultBodyHeight int
	HeightRatioNum    int
	HeightRatioDen    int
	InputWidthOffset  int
}

SplitOverlaySizingSpec describes the geometry constraints for a split list/detail overlay.

type SplitOverlaySpec

type SplitOverlaySpec struct {
	LeftPane  OverlayPaneSpec
	RightPane OverlayPaneSpec
}

SplitOverlaySpec describes the split-pane body content.

type Toast

type Toast struct {
	Message string
	Level   ToastLevel
	Expires time.Time
	// contains filtered or unexported fields
}

type ToastLevel

type ToastLevel int
const (
	ToastInfo ToastLevel = iota
	ToastSuccess
	ToastWarning
	ToastError
)

type ToastModel

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

func NewToastModel

func NewToastModel(st styles.Styles) ToastModel

func (*ToastModel) AddToast

func (m *ToastModel) AddToast(msg string, level ToastLevel)

func (*ToastModel) HasToasts

func (m *ToastModel) HasToasts() bool

func (*ToastModel) Prune

func (m *ToastModel) Prune()

func (*ToastModel) SetWidth

func (m *ToastModel) SetWidth(terminalWidth int)

func (*ToastModel) StackView

func (m *ToastModel) StackView(pinned ...Toast) string

func (*ToastModel) View

func (m *ToastModel) View() string

type ToastTickMsg

type ToastTickMsg time.Time

ToastTickMsg is sent every second to prune expired toasts.

Jump to

Keyboard shortcuts

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