tui

package
v0.0.182 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package tui provides terminal UI components using lipgloss

Package tui provides terminal UI components for comanda using bubbletea and lipgloss

Index

Constants

This section is empty.

Variables

View Source
var (
	// RoundedBox uses rounded corners (╭╮╰╯)
	RoundedBox = lipgloss.NewStyle().
				Border(lipgloss.RoundedBorder()).
				BorderForeground(lipgloss.Color("240"))

	// NormalBox uses standard corners (┌┐└┘)
	NormalBox = lipgloss.NewStyle().
				Border(lipgloss.NormalBorder()).
				BorderForeground(lipgloss.Color("240"))

	// DoubleBox uses double-line borders (╔╗╚╝)
	DoubleBox = lipgloss.NewStyle().
				Border(lipgloss.DoubleBorder()).
				BorderForeground(lipgloss.Color("240"))

	// HeaderBox is a bold double-line box for headers
	HeaderBox = lipgloss.NewStyle().
				Border(lipgloss.DoubleBorder()).
				BorderForeground(lipgloss.Color("99")).
				Bold(true)

	// Separator creates a horizontal line
	SeparatorStyle = lipgloss.NewStyle().
					Foreground(lipgloss.Color("240"))
)

Box styles for consistent rendering across the codebase

View Source
var ModelContextWindow = map[string]int{

	"claude-code":                200000,
	"claude-sonnet-4-20250514":   200000,
	"claude-opus-4-20250514":     200000,
	"claude-3-5-sonnet-20241022": 200000,
	"claude-3-5-haiku-20241022":  200000,
	"claude-3-opus-20240229":     200000,
	"claude-3-sonnet-20240229":   200000,
	"claude-3-haiku-20240307":    200000,

	"gpt-4":        128000,
	"gpt-4-turbo":  128000,
	"gpt-4o":       128000,
	"gpt-4o-mini":  128000,
	"gpt-4.1":      1000000,
	"gpt-4.1-mini": 1000000,
	"gpt-4.1-nano": 1000000,
	"o1":           200000,
	"o1-mini":      128000,
	"o1-preview":   128000,
	"o3":           200000,
	"o3-mini":      200000,
	"o4-mini":      200000,

	"gemini-2.0-flash":      1000000,
	"gemini-2.0-flash-lite": 1000000,
	"gemini-2.5-pro":        1000000,
	"gemini-2.5-flash":      1000000,
	"gemini-1.5-pro":        2000000,
	"gemini-1.5-flash":      1000000,

	"default": 128000,
}

ModelContextWindow holds context window sizes for different models

Functions

func ArrowDown added in v0.0.148

func ArrowDown(width int) string

ArrowDown returns a down arrow (▼) centered in width

func DoubleSeparator added in v0.0.148

func DoubleSeparator(width int) string

DoubleSeparator returns a double-line separator

func RenderBox added in v0.0.148

func RenderBox(text string, width int) string

RenderBox renders text in a rounded box with auto-width

func RenderDoubleBox added in v0.0.148

func RenderDoubleBox(text string, width int) string

RenderDoubleBox renders text in a double-line box with auto-width

func RenderHeaderBox added in v0.0.148

func RenderHeaderBox(text string, width int) string

RenderHeaderBox renders text in a header-style box with auto-width

func RenderMultiLineBox added in v0.0.148

func RenderMultiLineBox(lines []string, width int, useDouble bool) string

RenderMultiLineBox renders multiple lines in a box with auto-width

func RunChart

func RunChart(workflowName string, nodes []*ChartNode, stats ChartStats) error

RunChart starts the chart TUI

func Separator added in v0.0.148

func Separator(width int) string

Separator returns a horizontal separator line of specified width

func VerticalConnector added in v0.0.148

func VerticalConnector(width int) string

VerticalConnector returns a vertical connector (│) centered in width

Types

type Activity

type Activity struct {
	Timestamp time.Time
	Type      string // "tool", "output", "error", "info"
	Message   string
}

Activity represents a recent activity in the dashboard

type ChartModel

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

ChartModel is the bubbletea model for the chart view

func NewChartModel

func NewChartModel(workflowName string, nodes []*ChartNode, stats ChartStats) ChartModel

NewChartModel creates a new chart model

func (ChartModel) Init

func (m ChartModel) Init() tea.Cmd

Init initializes the model

func (ChartModel) Update

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

Update handles messages

func (ChartModel) View

func (m ChartModel) View() string

View renders the model

type ChartNode

type ChartNode struct {
	Name        string
	Model       string
	Type        string // "step", "parallel", "loop", "condition"
	IsValid     bool
	Children    []*ChartNode
	Input       string
	Output      string
	Action      string
	LoopConfig  *LoopConfig
	IsDeferred  bool
	Description string
}

ChartNode represents a node in the workflow chart

type ChartStats

type ChartStats struct {
	TotalSteps    int
	ParallelSteps int
	LoopCount     int
	ValidSteps    int
	DeferredSteps int
	Models        map[string]int
}

ChartStats holds workflow statistics

type DashboardModel

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

DashboardModel is the bubbletea model for the live dashboard

func NewDashboardModel

func NewDashboardModel(workflowName string, reporter *ProgressReporter) *DashboardModel

NewDashboardModel creates a new dashboard model

func RunDashboard

func RunDashboard(workflowName string, reporter *ProgressReporter) (*DashboardModel, *tea.Program)

RunDashboard starts the dashboard TUI and returns the program for external control

func RunDashboardWithDebug added in v0.0.154

func RunDashboardWithDebug(workflowName string, reporter *ProgressReporter, debugWriter *DebugWriter) (*DashboardModel, *tea.Program)

RunDashboardWithDebug starts the dashboard TUI with debug output capture

func (*DashboardModel) Init

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

Init initializes the model

func (*DashboardModel) SetDebugWriter added in v0.0.154

func (m *DashboardModel) SetDebugWriter(w *DebugWriter)

SetDebugWriter attaches a debug writer to capture debug/verbose output.

func (*DashboardModel) Update

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

Update handles messages

func (*DashboardModel) View

func (m *DashboardModel) View() string

View renders the dashboard

type DebugLinesMsg added in v0.0.154

type DebugLinesMsg struct {
	Lines []string
}

DebugLinesMsg is sent when debug lines are updated

type DebugWriter added in v0.0.154

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

DebugWriter captures debug output and forwards it to a channel for TUI display. It implements io.Writer so it can be used with log.SetOutput().

func NewDebugWriter added in v0.0.154

func NewDebugWriter(original io.Writer, maxLines int) *DebugWriter

NewDebugWriter creates a new DebugWriter that captures output. original is the fallback writer (e.g., os.Stderr) for when TUI is not active. maxLines limits how many lines are kept in the buffer.

func (*DebugWriter) Clear added in v0.0.154

func (w *DebugWriter) Clear()

Clear empties the buffer.

func (*DebugWriter) LastN added in v0.0.154

func (w *DebugWriter) LastN(n int) []string

LastN returns the last n lines.

func (*DebugWriter) Lines added in v0.0.154

func (w *DebugWriter) Lines() []string

Lines returns a copy of all captured lines.

func (*DebugWriter) Original added in v0.0.154

func (w *DebugWriter) Original() io.Writer

Original returns the original writer for passthrough.

func (*DebugWriter) SetOnChange added in v0.0.154

func (w *DebugWriter) SetOnChange(fn func([]string))

SetOnChange sets a callback that's called whenever new lines are added.

func (*DebugWriter) Write added in v0.0.154

func (w *DebugWriter) Write(p []byte) (n int, err error)

Write implements io.Writer. It captures the output and optionally forwards to original.

type EventMsg

type EventMsg struct {
	Event ProgressEvent
}

EventMsg wraps a progress event

type LogWatcher

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

LogWatcher monitors a stream log file and emits progress events

func NewLogWatcher

func NewLogWatcher(path string, reporter *ProgressReporter) *LogWatcher

NewLogWatcher creates a new log watcher

func (*LogWatcher) SetModel added in v0.0.153

func (w *LogWatcher) SetModel(model string)

SetModel updates the model for token estimation

func (*LogWatcher) Start

func (w *LogWatcher) Start()

Start begins watching the log file

func (*LogWatcher) Stop

func (w *LogWatcher) Stop()

Stop stops watching

type LoopConfig

type LoopConfig struct {
	MaxIterations int
	ExitCondition string
	ContextWindow int
}

LoopConfig contains loop-specific configuration

type Output

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

Output provides styled output for non-TUI mode

func NewOutput

func NewOutput(width int) *Output

NewOutput creates a new output helper

func (*Output) Bold

func (o *Output) Bold(message string) string

Bold prints bold text

func (*Output) Box

func (o *Output) Box(content string) string

Box wraps content in a styled box

func (*Output) Divider

func (o *Output) Divider() string

Divider prints a horizontal divider

func (*Output) Error

func (o *Output) Error(message string) string

Error prints an error message

func (*Output) Header

func (o *Output) Header(title string) string

Header prints a styled header box

func (*Output) HighlightBox

func (o *Output) HighlightBox(content string) string

HighlightBox wraps content in a highlighted box

func (*Output) Info

func (o *Output) Info(message string) string

Info prints an info message

func (*Output) ModelTag

func (o *Output) ModelTag(model string) string

ModelTag prints a colored model tag

func (*Output) Muted

func (o *Output) Muted(message string) string

Muted prints muted text

func (*Output) Progress

func (o *Output) Progress(current, total int, label string) string

Progress prints a styled progress line

func (*Output) Section

func (o *Output) Section(title, content string) string

Section prints a styled section box

func (*Output) SetEnabled

func (o *Output) SetEnabled(enabled bool)

SetEnabled enables or disables styled output

func (*Output) StatsBox

func (o *Output) StatsBox(stats map[string]interface{}) string

StatsBox prints a statistics box

func (*Output) Step

func (o *Output) Step(name, model, status string) string

Step prints a styled step indicator

func (*Output) SubHeader

func (o *Output) SubHeader(title string) string

SubHeader prints a styled subheader

func (*Output) Success

func (o *Output) Success(message string) string

Success prints a success message

func (*Output) Table

func (o *Output) Table(headers []string, rows [][]string) string

Table prints a simple styled table

func (*Output) Warning

func (o *Output) Warning(message string) string

Warning prints a warning message

type ProgressEvent

type ProgressEvent struct {
	Type        string // "step_start", "step_end", "loop_iter", "tool_call", "output", "error", "complete"
	Timestamp   time.Time
	StepName    string
	LoopName    string
	Iteration   int
	MaxIter     int
	Message     string
	TokensUsed  int
	TokensAvail int
	Error       error
}

ProgressEvent represents an event during workflow processing

type ProgressReporter

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

ProgressReporter sends progress events to subscribers

func NewProgressReporter

func NewProgressReporter() *ProgressReporter

NewProgressReporter creates a new progress reporter

func (*ProgressReporter) Close

func (p *ProgressReporter) Close()

Close cleans up all subscribers

func (*ProgressReporter) Complete

func (p *ProgressReporter) Complete(err error)

Complete emits a completion event

func (*ProgressReporter) Emit

func (p *ProgressReporter) Emit(event ProgressEvent)

Emit sends an event to all subscribers

func (*ProgressReporter) GetResourceUsage

func (p *ProgressReporter) GetResourceUsage() (cpuPercent float64, memoryMB float64)

GetResourceUsage returns current CPU and memory usage for this process and all children

func (*ProgressReporter) LoopIteration

func (p *ProgressReporter) LoopIteration(loopName string, iteration, maxIter int)

LoopIteration emits a loop iteration event

func (*ProgressReporter) Output

func (p *ProgressReporter) Output(message string)

Output emits an output event

func (*ProgressReporter) StepEnd

func (p *ProgressReporter) StepEnd(name string, err error)

StepEnd emits a step end event

func (*ProgressReporter) StepStart

func (p *ProgressReporter) StepStart(name string)

StepStart emits a step start event

func (*ProgressReporter) Subscribe

func (p *ProgressReporter) Subscribe() chan ProgressEvent

Subscribe adds a subscriber channel

func (*ProgressReporter) TokenUpdate

func (p *ProgressReporter) TokenUpdate(used, available int)

TokenUpdate emits a token usage update

func (*ProgressReporter) ToolCall

func (p *ProgressReporter) ToolCall(message string)

ToolCall emits a tool call event

func (*ProgressReporter) Unsubscribe

func (p *ProgressReporter) Unsubscribe(ch chan ProgressEvent)

Unsubscribe removes a subscriber channel

type Theme

type Theme struct {
	// Base colors
	Primary   lipgloss.Color
	Secondary lipgloss.Color
	Accent    lipgloss.Color
	Muted     lipgloss.Color
	Success   lipgloss.Color
	Warning   lipgloss.Color
	Error     lipgloss.Color

	// Background colors
	BgPrimary   lipgloss.Color
	BgSecondary lipgloss.Color

	// Model colors (for distinguishing different AI providers)
	ModelColors map[string]lipgloss.Color

	// Pre-built styles
	Title       lipgloss.Style
	Subtitle    lipgloss.Style
	Body        lipgloss.Style
	MutedText   lipgloss.Style
	SuccessText lipgloss.Style
	WarningText lipgloss.Style
	ErrorText   lipgloss.Style

	// Box styles
	BoxNormal    lipgloss.Style
	BoxHighlight lipgloss.Style
	BoxError     lipgloss.Style
	BoxSuccess   lipgloss.Style

	// Progress bar colors
	ProgressFull  lipgloss.Color
	ProgressEmpty lipgloss.Color
}

Theme defines the color scheme and styles for the TUI

func DefaultTheme

func DefaultTheme() *Theme

DefaultTheme returns the default comanda theme

func (*Theme) ModelColor

func (t *Theme) ModelColor(model string) lipgloss.Color

ModelColor returns the color for a given model name

func (*Theme) ModelStyle

func (t *Theme) ModelStyle(model string) lipgloss.Style

ModelStyle returns a style configured for a given model

func (*Theme) ProgressBar

func (t *Theme) ProgressBar(percent float64, width int) string

ProgressBar creates a progress bar string

func (*Theme) StatusIcon

func (t *Theme) StatusIcon(status string) (string, lipgloss.Style)

StatusIcon returns an icon and style for a status

type TickMsg

type TickMsg time.Time

TickMsg is sent on each tick for time/resource updates

type TokenEstimator added in v0.0.153

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

TokenEstimator tracks estimated token usage during workflow execution

func NewTokenEstimator added in v0.0.153

func NewTokenEstimator(model string, reporter *ProgressReporter) *TokenEstimator

NewTokenEstimator creates a token estimator for a given model

func (*TokenEstimator) AddInput added in v0.0.153

func (t *TokenEstimator) AddInput(text string)

AddInput records input characters Does not emit events - call EmitUpdate() explicitly when ready

func (*TokenEstimator) AddOutput added in v0.0.153

func (t *TokenEstimator) AddOutput(text string)

AddOutput records output characters (can be called incrementally for streaming) Does not emit events - call EmitUpdate() explicitly when ready

func (*TokenEstimator) EmitUpdate added in v0.0.153

func (t *TokenEstimator) EmitUpdate()

EmitUpdate sends the current token estimate to the reporter

func (*TokenEstimator) GetContextPercent added in v0.0.153

func (t *TokenEstimator) GetContextPercent() float64

GetContextPercent returns the estimated context window usage percentage

func (*TokenEstimator) GetEstimates added in v0.0.153

func (t *TokenEstimator) GetEstimates() (inputTokens, outputTokens, contextLimit int)

GetEstimates returns estimated token counts Uses ~4 characters per token as rough estimate for English text

func (*TokenEstimator) Reset added in v0.0.153

func (t *TokenEstimator) Reset()

Reset clears the token counts (e.g., between steps)

func (*TokenEstimator) SetModel added in v0.0.153

func (t *TokenEstimator) SetModel(model string)

SetModel updates the model and context limit

Jump to

Keyboard shortcuts

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