ui

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package ui provides the interactive terminal REPL for Smara.

Index

Constants

View Source
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

View Source
var ErrInterrupted = fmt.Errorf("interrupted")

ErrInterrupted is returned when the user interrupts input with Ctrl+C

View Source
var ModeColors = map[string]string{
	"ask":  Cyan,
	"rush": Yellow,
	"plan": Magenta,
}

Mode colors mapped by mode name

View Source
var ModeEmojis = map[string]string{
	"ask":  "💬",
	"rush": "⚡",
	"plan": "📋",
}

Mode emojis

View Source
var ModeOrder = []string{"ask", "rush", "plan"}

ModeOrder defines the cycle order for Tab key

Functions

func GetGlobalProgram

func GetGlobalProgram() *tea.Program

GetGlobalProgram returns the global program

func InjectLog

func InjectLog(role, content string)

Programmatic message injection

func IsCommand

func IsCommand(input string) bool

IsCommand checks if the input is a special command (starts with /).

func IsExitCommand

func IsExitCommand(input string) bool

IsExitCommand checks if the input is an exit command.

func NewProgram

func NewProgram(m AppModel) *tea.Program

NewProgram creates a new bubbletea program

func ParseCommand

func ParseCommand(input string) (string, []string)

ParseCommand extracts command and arguments from a /command input.

func PrintAgent

func PrintAgent(content string, mode string)

PrintAgent displays agent output with mode indicator.

func PrintBanner

func PrintBanner(v string)

PrintBanner displays the Smara startup banner.

func PrintError

func PrintError(format string, args ...interface{})

PrintError displays an error message.

func PrintHelp

func PrintHelp()

PrintHelp displays available REPL commands.

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

func PrintStatusBar(mode string, promptCount int, totalTokens int)

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

func SetGlobalProgram(p *tea.Program)

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 SpinnerStop

func SpinnerStop(success bool)

SpinnerStop ends the spinner animation.

func SpinnerTick

func SpinnerTick()

SpinnerTick updates the spinner animation.

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) Init

func (m AppModel) Init() tea.Cmd

Init initializes the app

func (*AppModel) LoadHistory

func (m *AppModel) LoadHistory(history []struct{ Role, Content string })

LoadHistory injects previous history into the model

func (AppModel) Update

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

Update handles messages and state changes

func (AppModel) View

func (m AppModel) View() string

View renders the UI

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 ConfirmRequestMsg struct {
	Message    string
	ResponseCh chan bool
}

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 NewPrompt

func NewPrompt() *Prompt

NewPrompt creates a new interactive prompt.

func (*Prompt) OnModeChange

func (p *Prompt) OnModeChange(fn func(newMode string))

OnModeChange sets a callback that fires when Tab cycles the mode.

func (*Prompt) ReadLine

func (p *Prompt) ReadLine() (string, error)

ReadLine reads a line of input with raw terminal mode for Tab key support.

func (*Prompt) ReadLineWithCancel

func (p *Prompt) ReadLineWithCancel(ctx context.Context) (string, error)

ReadLineWithCancel reads a line of input with context cancellation support. When context is cancelled, returns ErrInterrupted.

func (*Prompt) SetMode

func (p *Prompt) SetMode(mode string)

SetMode updates the prompt's displayed mode.

type StreamMsg

type StreamMsg struct {
	Chunk      string
	IsThinking bool
}

StreamMsg is received when a chunk of text is streamed from LLM

Jump to

Keyboard shortcuts

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