ui

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package ui provides shared UI components and utilities for the AutoCmd terminal interface.

Index

Constants

View Source
const (
	// ToolInsetPrefix is the standard horizontal padding for tool execution blocks.
	ToolInsetPrefix = "    "
	// ToolFirstContentGutterPrefix is the prefix used for the first line of tool output.
	ToolFirstContentGutterPrefix = "   ⎿ "
	// ToolContentGutterPrefix is the prefix used for subsequent lines of tool output.
	ToolContentGutterPrefix = "     "
)

Variables

This section is empty.

Functions

func AnsweredQuestionCount

func AnsweredQuestionCount(d domain.QuestionDisplay, per []QuestionPerState) int

AnsweredQuestionCount returns how many questions have a non-empty answer (for the review summary).

func HandleQuestionKey

HandleQuestionKey applies one logical key to state and returns updated state and outcome.

func IsVisuallyEmpty

func IsVisuallyEmpty(s string) bool

IsVisuallyEmpty returns true if the string contains only ANSI escape codes and whitespace.

func NormalizeBlock

func NormalizeBlock(s string) string

NormalizeBlock ensures a block has at least one leading newline and no trailing newlines. It respects larger gaps by prepending N-1 newlines if the source has more than 2 leading newlines. It also trims any visually empty lines (ANSI/whitespace only) from the start and end.

func OnReview

OnReview reports whether the UI is on the synthetic review step (Active == n with n > 1).

func QuestionHasAnswer

func QuestionHasAnswer(q domain.QuestionInfo, st QuestionPerState) bool

QuestionHasAnswer is true if the question has a non-empty selection or custom text.

func ShortNum

func ShortNum(n int) string

func ToAdaptiveColor

func ToAdaptiveColor(c ColorInfo) lipgloss.AdaptiveColor

ToAdaptiveColor converts a ColorInfo (e.g. from config) to lipgloss.AdaptiveColor.

func TrimVisuallyEmpty

func TrimVisuallyEmpty(s string) string

TrimVisuallyEmpty removes leading and trailing lines that contain only ANSI escape codes and whitespace.

func UnansweredIndices

func UnansweredIndices(d domain.QuestionDisplay, per []QuestionPerState) []int

UnansweredIndices returns the 1-based indices of questions without answers.

Types

type Action

type Action struct {
	Fn    func(item Item) tea.Cmd
	Key   string
	Label string
	Quit  bool
}

Action defines a keybinding the caller can register.

type ActionBlockSpec

type ActionBlockSpec struct {
	Frame        string
	HeaderLines  []string
	ContentLines []string
	FooterLines  []string
	Status       ToolStatus
}

ActionBlockSpec is the semantic rendering contract passed from ToolRenderer to Theme. Theme consumes this structure for placement and styling only.

type ColorInfo

type ColorInfo interface {
	Light() string
	Dark() string
}

ColorInfo matches the methods provided by config.ColorConfig.

type Config

type Config struct {
	Title string
	Items []Item
	// Theme controls the visual styling of the picker.
	// If nil, a default style that roughly matches the global theme is used.
	Theme   *Theme
	Actions []Action
}

Config configures the picker.

type ContentTruncateMode

type ContentTruncateMode int

ContentTruncateMode defines how large tool outputs should be truncated for display.

type GlamourRenderer

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

GlamourRenderer wraps glamour.TermRenderer to implement Renderer.

func (*GlamourRenderer) Render

func (g *GlamourRenderer) Render(markdown string) string

Render implements Renderer. On error, it returns the original markdown and logs.

type Item

type Item struct {
	ID     string
	Label  string
	Detail string
	Group  string
	Active bool
	Faded  bool
}

Item is a single selectable row.

type NoOpGater

type NoOpGater struct{}

NoOpGater implements a gater that performs no truncation.

func NewNoOpGater

func NewNoOpGater() *NoOpGater

NewNoOpGater returns a gater that performs no truncation.

func (*NoOpGater) Gate

func (g *NoOpGater) Gate(lines []string, _ int, _ bool, _ *Theme) ([]string, int)

Gate returns the input lines as-is.

type PassthroughRenderer

type PassthroughRenderer struct{}

PassthroughRenderer is a no-op renderer that returns markdown as-is.

func (*PassthroughRenderer) Render

func (p *PassthroughRenderer) Render(markdown string) string

Render returns the original markdown without modification.

type Picker

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

Picker is a reusable grouped list selection model.

func NewPicker

func NewPicker(cfg Config) *Picker

NewPicker creates a new Picker with the given configuration.

func (*Picker) CursorItem

func (m *Picker) CursorItem() (Item, bool)

CursorItem returns the item currently under the cursor.

func (*Picker) Init

func (m *Picker) Init() tea.Cmd

Init initializes the picker model.

func (*Picker) RefreshItems

func (m *Picker) RefreshItems(items []Item)

RefreshItems allows the caller to update the list (e.g. after a rename or delete).

func (*Picker) Selected

func (m *Picker) Selected() (*Item, bool)

Selected returns the item that was selected by the user.

func (*Picker) Update

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

Update handles keyboard messages for navigation and selection.

func (*Picker) View

func (m *Picker) View() string

View renders the picker as a string.

type QuestionOutcome

type QuestionOutcome struct {
	Answers   [][]string
	Done      bool
	Cancelled bool
}

QuestionOutcome is the reducer result when the user submits or cancels.

type QuestionPerState

type QuestionPerState struct {
	CustomBuffer       string
	MultiSelected      []bool
	Cursor             int
	SingleSelected     int
	CustomInputFocused bool
	CustomSelected     bool
}

QuestionPerState is state for one question in the toolbox.

type QuestionUIState

type QuestionUIState struct {
	Per          []QuestionPerState
	Active       int
	ReviewCursor int
	Submitted    bool
}

QuestionUIState is interactive UI state for QuestionDisplay (prompt-owned; lives in ui to avoid import cycles with ToolRenderer).

func NewQuestionUIState

func NewQuestionUIState(d domain.QuestionDisplay) QuestionUIState

NewQuestionUIState initializes state for d.Questions (one QuestionPerState each).

type RenderSpecOptions

type RenderSpecOptions struct {
	TruncateMode             ContentTruncateMode
	TruncateFromContentIndex int
	Scrollable               bool
}

RenderSpecOptions configures the behavior of the tool rendering pipeline.

type Renderer

type Renderer interface {
	Render(markdown string) string
}

Renderer renders markdown to ANSI strings. Failure should be handled internally.

func NewGlamourRenderer

func NewGlamourRenderer(width int, isDark bool) Renderer

NewGlamourRenderer creates a Renderer using glamour with the given width. If glamour initialization fails, it logs the error and returns a PassthroughRenderer.

type SpinnerRenderer

type SpinnerRenderer struct {
	Style lipgloss.Style
}

SpinnerRenderer handles braille spinner animations.

func NewSpinnerRenderer

func NewSpinnerRenderer(style lipgloss.Style) *SpinnerRenderer

NewSpinnerRenderer creates a new SpinnerRenderer.

func (*SpinnerRenderer) Frame

func (r *SpinnerRenderer) Frame(tick int) string

Frame returns the spinner character for a given tick.

type Theme

type Theme struct {
	PrimaryCol lipgloss.AdaptiveColor
	SuccessCol lipgloss.AdaptiveColor
	ErrorCol   lipgloss.AdaptiveColor
	MutedCol   lipgloss.AdaptiveColor
	TextCol    lipgloss.AdaptiveColor
}

Theme provides styling and configuration for the UI.

func (*Theme) ActionBlock

func (t *Theme) ActionBlock(content string, status ToolStatus, _ string) string

ActionBlock renders a simple action block with header and content.

func (*Theme) Box

func (t *Theme) Box(content string, _ int, status ToolStatus) string

Box exists for compatibility while tests migrate from box-style assertions.

func (*Theme) Error

func (t *Theme) Error(s string) string

func (*Theme) ErrorColor

func (t *Theme) ErrorColor() lipgloss.AdaptiveColor

ErrorColor returns the theme's error adaptive color.

func (*Theme) Muted

func (t *Theme) Muted(s string) string

Muted styles a string with the theme's muted color.

func (*Theme) MutedColor

func (t *Theme) MutedColor() lipgloss.AdaptiveColor

MutedColor returns the theme's muted adaptive color.

func (*Theme) Primary

func (t *Theme) Primary(s string) string

Primary styles a string with the theme's primary color.

func (*Theme) PrimaryColor

func (t *Theme) PrimaryColor() lipgloss.AdaptiveColor

PrimaryColor returns the theme's primary adaptive color.

func (*Theme) RenderActionBlock

func (t *Theme) RenderActionBlock(spec ActionBlockSpec) string

RenderActionBlock renders an action execution block using status markers and colors.

func (*Theme) Separator

func (t *Theme) Separator(width int, status ToolStatus) string

Separator returns a styled horizontal line.

func (*Theme) StatusPrefix

func (t *Theme) StatusPrefix(status ToolStatus, frame string) string

StatusPrefix returns a styled icon with a trailing space.

func (*Theme) Success

func (t *Theme) Success(s string) string

func (*Theme) SuccessColor

func (t *Theme) SuccessColor() lipgloss.AdaptiveColor

SuccessColor returns the theme's success adaptive color.

func (*Theme) TextColor

func (t *Theme) TextColor() lipgloss.AdaptiveColor

TextColor returns the theme's text adaptive color.

type ToolOutputGater

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

ToolOutputGater implements tool-specific truncation logic.

func NewToolOutputGater

func NewToolOutputGater(maxLines int) *ToolOutputGater

NewToolOutputGater creates a gater optimized for tool output (bash.diff).

func (*ToolOutputGater) Gate

func (g *ToolOutputGater) Gate(lines []string, _ int, _ bool, theme *Theme) ([]string, int)

Gate implements the gater interface optimized for tool output.

type ToolRenderer

type ToolRenderer struct {
	Theme *Theme
	Width int
	// contains filtered or unexported fields
}

ToolRenderer provides rendering for tool outputs (StringDisplay, DiffDisplay, BashDisplay).

func NewToolRenderer

func NewToolRenderer(theme *Theme, width int, g gater) *ToolRenderer

NewToolRenderer creates a new ToolRenderer.

func (*ToolRenderer) RenderBash

func (r *ToolRenderer) RenderBash(d domain.BashDisplay, output string, status ToolStatus, err string, frame string) string

RenderBash renders BashDisplay.

func (*ToolRenderer) RenderDiff

func (r *ToolRenderer) RenderDiff(d domain.DiffDisplay, status ToolStatus, err string, frame string) string

RenderDiff renders DiffDisplay.

func (*ToolRenderer) RenderQuestion

func (r *ToolRenderer) RenderQuestion(d domain.QuestionDisplay, state QuestionUIState, status ToolStatus, err string, frame string) string

RenderQuestion renders QuestionDisplay with interactive state (cursor, toggles, custom text). Unlike other tool renderers, it never prepends a status prefix (spinner/checkmark); the question header is the first line.

func (*ToolRenderer) RenderString

func (r *ToolRenderer) RenderString(d domain.StringDisplay, status ToolStatus, err string, frame string) string

RenderString renders StringDisplay.

type ToolStatus

type ToolStatus int

ToolStatus represents tool lifecycle state for display rendering.

const (
	// StatusRunning indicates that a tool or process is currently active.
	StatusRunning ToolStatus = iota
	// StatusAwaitingApproval indicates that a tool is blocked waiting for user consent.
	StatusAwaitingApproval
	// StatusSuccess indicates that a tool or process completed successfully.
	StatusSuccess
	// StatusError indicates that a tool or process failed.
	StatusError
)

type TruncatingGater

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

TruncatingGater implements viewport-style truncation.

func NewTruncatingGater

func NewTruncatingGater(maxLines int) *TruncatingGater

NewTruncatingGater creates a gater that truncates content after maxLines.

func (*TruncatingGater) Gate

func (g *TruncatingGater) Gate(lines []string, scrollOffset int, scrollable bool, theme *Theme) ([]string, int)

Gate implements the gater interface by truncating lines from the top.

Directories

Path Synopsis
Package authui provides the UI components for the authentication workflow.
Package authui provides the UI components for the authentication workflow.
Package history provides components for rendering the conversation history in the terminal.
Package history provides components for rendering the conversation history in the terminal.
Package info provides UI components for displaying system information and settings.
Package info provides UI components for displaying system information and settings.
Package model_picker provides UI components for selecting LLM models.
Package model_picker provides UI components for selecting LLM models.
Package prompt provides the main interactive prompt and tool execution UI.
Package prompt provides the main interactive prompt and tool execution UI.
Package session_picker provides UI components for selecting and managing chat sessions.
Package session_picker provides UI components for selecting and managing chat sessions.

Jump to

Keyboard shortcuts

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