Documentation
¶
Overview ¶
Package tui provides terminal UI components using lipgloss
Package tui provides terminal UI components for comanda using bubbletea and lipgloss
Index ¶
- Variables
- func ArrowDown(width int) string
- func DoubleSeparator(width int) string
- func RenderBox(text string, width int) string
- func RenderDoubleBox(text string, width int) string
- func RenderHeaderBox(text string, width int) string
- func RenderMultiLineBox(lines []string, width int, useDouble bool) string
- func RunChart(workflowName string, nodes []*ChartNode, stats ChartStats) error
- func Separator(width int) string
- func VerticalConnector(width int) string
- type Activity
- type ChartModel
- type ChartNode
- type ChartStats
- type DashboardModel
- func NewDashboardModel(workflowName string, reporter *ProgressReporter) *DashboardModel
- func RunDashboard(workflowName string, reporter *ProgressReporter) (*DashboardModel, *tea.Program)
- func RunDashboardWithDebug(workflowName string, reporter *ProgressReporter, debugWriter *DebugWriter) (*DashboardModel, *tea.Program)
- type DebugLinesMsg
- type DebugWriter
- type EventMsg
- type LogWatcher
- type LoopConfig
- type Output
- func (o *Output) Bold(message string) string
- func (o *Output) Box(content string) string
- func (o *Output) Divider() string
- func (o *Output) Error(message string) string
- func (o *Output) Header(title string) string
- func (o *Output) HighlightBox(content string) string
- func (o *Output) Info(message string) string
- func (o *Output) ModelTag(model string) string
- func (o *Output) Muted(message string) string
- func (o *Output) Progress(current, total int, label string) string
- func (o *Output) Section(title, content string) string
- func (o *Output) SetEnabled(enabled bool)
- func (o *Output) StatsBox(stats map[string]interface{}) string
- func (o *Output) Step(name, model, status string) string
- func (o *Output) SubHeader(title string) string
- func (o *Output) Success(message string) string
- func (o *Output) Table(headers []string, rows [][]string) string
- func (o *Output) Warning(message string) string
- type ProgressEvent
- type ProgressReporter
- func (p *ProgressReporter) Close()
- func (p *ProgressReporter) Complete(err error)
- func (p *ProgressReporter) Emit(event ProgressEvent)
- func (p *ProgressReporter) GetResourceUsage() (cpuPercent float64, memoryMB float64)
- func (p *ProgressReporter) LoopIteration(loopName string, iteration, maxIter int)
- func (p *ProgressReporter) Output(message string)
- func (p *ProgressReporter) StepEnd(name string, err error)
- func (p *ProgressReporter) StepStart(name string)
- func (p *ProgressReporter) Subscribe() chan ProgressEvent
- func (p *ProgressReporter) TokenUpdate(used, available int)
- func (p *ProgressReporter) ToolCall(message string)
- func (p *ProgressReporter) Unsubscribe(ch chan ProgressEvent)
- type Theme
- type TickMsg
- type TokenEstimator
- func (t *TokenEstimator) AddInput(text string)
- func (t *TokenEstimator) AddOutput(text string)
- func (t *TokenEstimator) EmitUpdate()
- func (t *TokenEstimator) GetContextPercent() float64
- func (t *TokenEstimator) GetEstimates() (inputTokens, outputTokens, contextLimit int)
- func (t *TokenEstimator) Reset()
- func (t *TokenEstimator) SetModel(model string)
Constants ¶
This section is empty.
Variables ¶
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
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 DoubleSeparator ¶ added in v0.0.148
DoubleSeparator returns a double-line separator
func RenderDoubleBox ¶ added in v0.0.148
RenderDoubleBox renders text in a double-line box with auto-width
func RenderHeaderBox ¶ added in v0.0.148
RenderHeaderBox renders text in a header-style box with auto-width
func RenderMultiLineBox ¶ added in v0.0.148
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 VerticalConnector ¶ added in v0.0.148
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
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) SetDebugWriter ¶ added in v0.0.154
func (m *DashboardModel) SetDebugWriter(w *DebugWriter)
SetDebugWriter attaches a debug writer to capture debug/verbose output.
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.
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
type LoopConfig ¶
LoopConfig contains loop-specific configuration
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
Output provides styled output for non-TUI mode
func (*Output) HighlightBox ¶
HighlightBox wraps content in a highlighted box
func (*Output) SetEnabled ¶
SetEnabled enables or disables styled output
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) 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 (*Theme) ModelColor ¶
ModelColor returns the color for a given model name
func (*Theme) ModelStyle ¶
ModelStyle returns a style configured for a given model
func (*Theme) ProgressBar ¶
ProgressBar creates a progress bar string
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