Documentation
¶
Overview ¶
Package ui provides the interactive terminal REPL for Smara.
Index ¶
- Constants
- Variables
- func GetGlobalProgram() *tea.Program
- func InjectLog(role, content string)
- func IsCommand(input string) bool
- func IsExitCommand(input string) bool
- func NewProgram(m AppModel) *tea.Program
- func ParseCommand(input string) (string, []string)
- func PrintAgent(content string, mode string)
- func PrintBanner(v string)
- func PrintError(format string, args ...interface{})
- func PrintHelp()
- func PrintInfo(format string, args ...interface{})
- func PrintKeyboardShortcuts()
- func PrintModeChange(mode, emoji, description string)
- func PrintStatusBar(mode string, promptCount int, totalTokens int)
- func PrintSuccess(format string, args ...interface{})
- func PrintUsageStats(promptCount int, totalTokens int, avgTokens int, totalCost float64, ...)
- func PrintWarning(format string, args ...interface{})
- func SetGlobalProgram(p *tea.Program)
- func ShowProviderSelector() error
- func SpinnerStart(msg string)
- func SpinnerStop(success bool)
- func SpinnerTick()
- func TUIPrintError(format string, args ...interface{})
- func TUIPrintInfo(format string, args ...interface{})
- func TUIPrintSuccess(format string, args ...interface{})
- func TUIPrintWarning(format string, args ...interface{})
- type AppModel
- type AppSupervisor
- type ChatMessage
- type ConfirmRequestMsg
- type LogMsg
- type ProcessMsg
- type Prompt
- type StreamMsg
Constants ¶
const ( Reset = "\033[0m" Bold = "\033[1m" Dim = "\033[2m" Italic = "\033[3m" Cyan = "\033[36m" Green = "\033[32m" Yellow = "\033[33m" Red = "\033[31m" Magenta = "\033[35m" Blue = "\033[34m" White = "\033[37m" BgCyan = "\033[46m" BgBlue = "\033[44m" BgYellow = "\033[43m" BgGreen = "\033[42m" BgMagenta = "\033[45m" )
ANSI color codes
Variables ¶
var ErrInterrupted = fmt.Errorf("interrupted")
ErrInterrupted is returned when the user interrupts input with Ctrl+C
Mode colors mapped by mode name
var ModeEmojis = map[string]string{
"ask": "💬",
"rush": "⚡",
"plan": "📋",
}
Mode emojis
var ModeOrder = []string{"ask", "rush", "plan"}
ModeOrder defines the cycle order for Tab key
Functions ¶
func GetGlobalProgram ¶
GetGlobalProgram returns the global program
func IsExitCommand ¶
IsExitCommand checks if the input is an exit command.
func NewProgram ¶
NewProgram creates a new bubbletea program
func ParseCommand ¶
ParseCommand extracts command and arguments from a /command input.
func PrintAgent ¶
PrintAgent displays agent output with mode indicator.
func PrintError ¶
func PrintError(format string, args ...interface{})
PrintError displays an error message.
func PrintInfo ¶
func PrintInfo(format string, args ...interface{})
PrintInfo displays an info message.
func PrintKeyboardShortcuts ¶
func PrintKeyboardShortcuts()
PrintKeyboardShortcuts displays keyboard shortcuts overlay.
func PrintModeChange ¶
func PrintModeChange(mode, emoji, description string)
PrintModeChange displays a mode change notification.
func PrintStatusBar ¶
PrintStatusBar displays a status bar at the bottom of the terminal.
func PrintSuccess ¶
func PrintSuccess(format string, args ...interface{})
PrintSuccess displays a success message.
func PrintUsageStats ¶
func PrintUsageStats(promptCount int, totalTokens int, avgTokens int, totalCost float64, totalDuration string)
PrintUsageStats displays usage statistics after each prompt. Accepts agent.Stats but displays it in a user-friendly format.
func PrintWarning ¶
func PrintWarning(format string, args ...interface{})
PrintWarning displays a warning message.
func SetGlobalProgram ¶
SetGlobalProgram sets the global program for log injection
func ShowProviderSelector ¶
func ShowProviderSelector() error
func SpinnerStart ¶
func SpinnerStart(msg string)
SpinnerStart begins a spinner animation (call in goroutine).
func TUIPrintError ¶
func TUIPrintError(format string, args ...interface{})
PrintError replaces the standard PrintError when using TUI
func TUIPrintInfo ¶
func TUIPrintInfo(format string, args ...interface{})
PrintInfo replaces the standard PrintInfo when using TUI
func TUIPrintSuccess ¶
func TUIPrintSuccess(format string, args ...interface{})
PrintSuccess replaces the standard PrintSuccess when using TUI
func TUIPrintWarning ¶
func TUIPrintWarning(format string, args ...interface{})
PrintWarning replaces the standard PrintWarning when using TUI
Types ¶
type AppModel ¶
type AppModel struct {
// contains filtered or unexported fields
}
AppModel is the Bubbletea model for our TUI
func InitialModel ¶
func InitialModel(sup AppSupervisor, onCmd func(cmd string, args []string)) AppModel
InitialModel creates a new model
func (*AppModel) LoadHistory ¶
LoadHistory injects previous history into the model
type AppSupervisor ¶
type AppSupervisor interface {
ProcessPrompt(ctx context.Context, prompt string) (*agent.PromptResult, error)
GetMode() agent.Mode
SetMode(mode agent.Mode)
GetModelInfo() (string, string)
}
Supervisor interface to avoid circular dependency
type ChatMessage ¶
type ChatMessage struct {
Role string // "System", "User", "Agent"
Content string
Thinking string
Time time.Time
InputTokens int
OutputTokens int
Duration time.Duration
}
ChatMessage represents a single message in the UI
type ConfirmRequestMsg ¶
type LogMsg ¶
type LogMsg struct {
Message ChatMessage
}
LogMsg allows external systems to inject messages into the UI
type ProcessMsg ¶
type ProcessMsg struct {
Result *agent.PromptResult
Err error
}
ProcessMsg is sent when the supervisor finishes processing
type Prompt ¶
type Prompt struct {
// contains filtered or unexported fields
}
Prompt manages the interactive REPL loop with raw terminal input.
func (*Prompt) OnModeChange ¶
OnModeChange sets a callback that fires when Tab cycles the mode.
func (*Prompt) ReadLine ¶
ReadLine reads a line of input with raw terminal mode for Tab key support.
func (*Prompt) ReadLineWithCancel ¶
ReadLineWithCancel reads a line of input with context cancellation support. When context is cancelled, returns ErrInterrupted.