tui

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package tui implements the interactive terminal UI using Bubble Tea.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, cfg Config) error

Run starts the TUI.

Types

type AgentReadyMsg added in v0.16.20

type AgentReadyMsg struct {
	Agent *core.Agent
}

AgentReadyMsg signals background setup is complete and the agent is ready.

type CommandSuggestion added in v0.23.1

type CommandSuggestion struct {
	Name        string
	Description string
}

CommandSuggestion holds a slash command name and description for autocomplete display.

type Config

type Config struct {
	Shell    *shell.Shell
	Agent    *core.Agent
	Session  *session.Session
	Model    core.Model
	Models   []core.Model // available models from registry
	SessDir  string       // session directory path
	Theme    Theme
	App      *ext.App         // extension API surface
	Settings *config.Settings // user settings (nil-safe)

	// SetupFn runs as a background Cmd from Init(). It performs heavy startup
	// work (loading extensions, building agent) and returns an AgentReadyMsg.
	SetupFn func() AgentReadyMsg
}

Config configures the TUI app.

type InputModel

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

InputModel manages the composer textarea with slash command autocomplete.

func NewInputModel

func NewInputModel(styles Styles, commands []CommandSuggestion) InputModel

NewInputModel creates a new composer input.

func (*InputModel) Blur

func (m *InputModel) Blur()

Blur unfocuses the textarea.

func (*InputModel) Focus

func (m *InputModel) Focus()

Focus focuses the textarea.

func (*InputModel) LoadHistory added in v0.16.24

func (m *InputModel) LoadHistory(path string)

LoadHistory reads persistent history from disk and sets the path for future saves. Missing file is a no-op.

func (*InputModel) PushHistory added in v0.5.0

func (m *InputModel) PushHistory(s string)

PushHistory adds an entry to the input history, resets the cursor, and persists the history to disk.

func (*InputModel) Reset

func (m *InputModel) Reset()

Reset clears the textarea.

func (*InputModel) SetAttachment added in v0.5.0

func (m *InputModel) SetAttachment(s string)

SetAttachment sets the attachment indicator shown above the input.

func (*InputModel) SetCommands added in v0.16.20

func (m *InputModel) SetCommands(cmds []CommandSuggestion)

SetCommands updates the registered commands for autocomplete.

func (*InputModel) SetValue

func (m *InputModel) SetValue(s string)

SetValue sets the textarea content.

func (*InputModel) SetWidth

func (m *InputModel) SetWidth(w int)

SetWidth updates the input width.

func (InputModel) Update

func (m InputModel) Update(msg tea.Msg) (InputModel, tea.Cmd)

Update handles input events.

func (*InputModel) Value

func (m *InputModel) Value() string

Value returns the current text.

func (InputModel) View

func (m InputModel) View() string

View renders the input.

type MessageView

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

MessageView renders conversation messages.

func NewMessageView

func NewMessageView(styles Styles, width int, glamourStyle string) MessageView

NewMessageView creates a message renderer. glamourStyle selects the glamour markdown theme (e.g. "dark", "light", "notty"); empty string defaults to "dark".

func (*MessageView) RenderMessage

func (v *MessageView) RenderMessage(msg core.Message) string

RenderMessage renders a single message.

func (*MessageView) RenderStreaming

func (v *MessageView) RenderStreaming(text string, thinking string, cache *streamCache) string

RenderStreaming renders a partial assistant response being streamed. Uses glamour with caching — only re-renders when newline count changes. Newline-only triggering avoids mid-line re-renders during code blocks, where incomplete syntax causes glamour to produce unstable output (flicker).

func (*MessageView) SetWidth

func (v *MessageView) SetWidth(w int)

SetWidth updates the rendering width, re-creating the glamour renderer.

type ModalAskCancelMsg added in v0.23.1

type ModalAskCancelMsg struct{}

ModalAskCancelMsg is sent when a cancelable modal is dismissed with Esc.

type ModalCloseMsg

type ModalCloseMsg struct{}

ModalCloseMsg is sent when the modal is dismissed.

type ModalItem

type ModalItem struct {
	ID    string
	Label string
	Desc  string
}

ModalItem is an item in a modal list.

type ModalModel

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

ModalModel is a generic list selector modal.

func NewModalModel

func NewModalModel(title string, items []ModalItem, styles Styles) ModalModel

NewModalModel creates a modal.

func (*ModalModel) Hide

func (m *ModalModel) Hide()

Hide hides the modal.

func (*ModalModel) SetCancelable added in v0.23.1

func (m *ModalModel) SetCancelable(on bool)

SetCancelable marks the modal as cancelable — Esc emits ModalAskCancelMsg.

func (*ModalModel) SetItems

func (m *ModalModel) SetItems(items []ModalItem)

SetItems updates the items list.

func (*ModalModel) SetSize

func (m *ModalModel) SetSize(w, h int)

SetSize updates the modal dimensions.

func (*ModalModel) Show

func (m *ModalModel) Show()

Show makes the modal visible.

func (ModalModel) Update

func (m ModalModel) Update(msg tea.Msg) (ModalModel, tea.Cmd)

Update handles modal events.

func (ModalModel) View

func (m ModalModel) View() string

View renders the modal.

func (ModalModel) Visible

func (m ModalModel) Visible() bool

Visible returns whether the modal is shown.

type ModalSelectMsg

type ModalSelectMsg struct {
	Item ModalItem
}

ModalSelectMsg is sent when an item is selected.

type Model

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

Model is the Bubble Tea model for the TUI.

func New

func New(cfg Config) Model

New creates a TUI model.

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model.

func (Model) Update

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

Update implements tea.Model.

func (Model) View

func (m Model) View() tea.View

View implements tea.Model.

type OverlayModel added in v0.18.0

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

OverlayModel manages a stack of named overlays. Escape dismisses the topmost.

func NewOverlayModel added in v0.18.0

func NewOverlayModel(styles Styles) OverlayModel

NewOverlayModel creates an overlay manager.

func (*OverlayModel) Close added in v0.18.0

func (o *OverlayModel) Close(key string)

Close removes a specific overlay by key.

func (*OverlayModel) DismissTop added in v0.18.0

func (o *OverlayModel) DismissTop()

DismissTop removes the topmost overlay (Escape behavior).

func (OverlayModel) HPos added in v0.23.1

func (o OverlayModel) HPos() lipgloss.Position

HPos returns the horizontal anchor of the topmost overlay as a lipgloss Position (Left=0, Center=0.5, Right=1). Accepted anchor strings are the same as parseAnchor: "left", "right", "top-left", "bottom-right", etc.

func (*OverlayModel) ScrollDown added in v0.18.0

func (o *OverlayModel) ScrollDown()

ScrollDown scrolls the topmost overlay down.

func (*OverlayModel) ScrollUp added in v0.18.0

func (o *OverlayModel) ScrollUp()

ScrollUp scrolls the topmost overlay up.

func (*OverlayModel) SetSize added in v0.18.0

func (o *OverlayModel) SetSize(w, h int)

SetSize updates the available dimensions.

func (*OverlayModel) Show added in v0.18.0

func (o *OverlayModel) Show(key, title, content, anchor, width string)

Show pushes an overlay onto the stack. If an overlay with the same key exists, it is replaced (moved to the top).

func (OverlayModel) VPos added in v0.23.1

func (o OverlayModel) VPos() lipgloss.Position

VPos returns the vertical anchor of the topmost overlay as a lipgloss Position (Top=0, Center=0.5, Bottom=1). Accepted anchor strings are the same as parseAnchor: "top", "bottom", "top-left", "bottom-right", etc.

func (OverlayModel) View added in v0.18.0

func (o OverlayModel) View() string

View renders the topmost overlay. The caller composites this on top of the main view.

func (OverlayModel) Visible added in v0.18.0

func (o OverlayModel) Visible() bool

Visible returns true if at least one overlay is showing.

type StatusBar

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

StatusBar renders the footer status bar. Sections are registered through ext.RegisterStatusSection. Values are set via Set(key, value).

func NewStatusBar

func NewStatusBar(styles Styles) StatusBar

NewStatusBar creates a status bar.

func (*StatusBar) Set added in v0.5.0

func (s *StatusBar) Set(key, value string)

Set updates a named status section's display value. Pass empty string to clear the section.

func (*StatusBar) SetRegistry added in v0.5.0

func (s *StatusBar) SetRegistry(sections []ext.StatusSection)

SetRegistry updates the registered section definitions. Sections are sorted once here so renderSide does not need to sort on every render.

func (*StatusBar) SetSpinnerView added in v0.5.0

func (s *StatusBar) SetSpinnerView(v string)

SetSpinnerView updates the spinner display (empty string = hidden).

func (*StatusBar) SetWidth

func (s *StatusBar) SetWidth(w int)

SetWidth updates the available width.

func (StatusBar) View

func (s StatusBar) View() string

View renders the status bar.

type Styles

type Styles struct {
	App            lipgloss.Style
	Header         lipgloss.Style
	Footer         lipgloss.Style
	UserMsg        lipgloss.Style
	AssistantLabel lipgloss.Style
	ToolError      lipgloss.Style
	Thinking       lipgloss.Style
	Spinner        lipgloss.Style
	InputBorder    lipgloss.Style
	Muted          lipgloss.Style
	Error          lipgloss.Style
	Success        lipgloss.Style
	Warning        lipgloss.Style
	BorderColor    color.Color
}

Styles holds precomputed lipgloss styles derived from a Theme.

func NewStyles

func NewStyles(t Theme) Styles

NewStyles creates styles from a theme.

type Theme

type Theme struct {
	Primary      color.Color
	Secondary    color.Color
	Muted        color.Color
	Error        color.Color
	Success      color.Color
	Warning      color.Color
	Background   color.Color
	Foreground   color.Color
	Border       color.Color
	GlamourStyle string // glamour markdown style name (e.g. "dark", "light", "notty")
}

Theme holds all colors used by the TUI.

func DefaultTheme

func DefaultTheme() Theme

DefaultTheme returns the built-in color theme.

Jump to

Keyboard shortcuts

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