ui

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package ui provides terminal UI components for Rnix CLI.

Index

Constants

View Source
const (
	ColorKernel  = "#888888"
	ColorAgent   = "#5B9BD5"
	ColorSuccess = "#6BCB77"
	ColorWarning = "#FFD93D"
	ColorError   = "#FF6B6B"
	ColorMuted   = "#666666"
)

Color constants for the Rnix design system.

Variables

View Source
var (
	KernelStyle    lipgloss.Style
	AgentStyle     lipgloss.Style
	AgentBoldStyle lipgloss.Style // AgentStyle + Bold, pre-computed for FormatTraceLine
	SuccessStyle   lipgloss.Style
	ErrorStyle     lipgloss.Style
	WarningStyle   lipgloss.Style
	MutedStyle     lipgloss.Style
	BoldStyle      lipgloss.Style
)

Style set for styled terminal output.

Functions

func AlertSeverityIcon added in v0.7.2

func AlertSeverityIcon(severity int) string

AlertSeverityIcon returns the icon for an alert severity level. In ASCII mode, error/critical use "[!]" and warn uses "(!)".

func EventTypeIcon added in v0.7.2

func EventTypeIcon(eventType string) string

EventTypeIcon returns the display icon for a unified event type. In ASCII mode, emoji/Unicode symbols are replaced with terminal-safe equivalents.

func FormatCostBudget added in v0.7.2

func FormatCostBudget(usedCost, maxCost float64) string

FormatCostBudget formats cost usage with budget limit. Returns "$0.15/$1.00" when maxCost > 0, or "-" otherwise.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration for human-readable display.

func FormatRelativeTime added in v0.7.2

func FormatRelativeTime(t time.Time) string

FormatRelativeTime formats a time as a relative duration string like "3s ago", "2m ago".

func FormatSkills

func FormatSkills(skills []string, maxWidth int, dash string) string

FormatSkills formats a skill list for display, truncating if needed.

func FormatTokens

func FormatTokens(n int) string

FormatTokens formats an integer with comma thousand separators.

func FormatTokensBudget added in v0.7.2

func FormatTokensBudget(used int, maxTokens int64) string

FormatTokensBudget formats token usage with optional budget limit. Returns "12,345/50,000" when maxTokens > 0, or "12,345" otherwise.

func FormatTraceLine

func FormatTraceLine(r *Renderer, event types.SyscallEvent, verbose bool) string

FormatTraceLine formats a SyscallEvent into a styled trace line using lipgloss. This is the UI-layer replacement for debug.FormatEvent's raw ANSI output.

func InitStyles

func InitStyles(profile TerminalProfile)

InitStyles initializes the lipgloss style set based on the terminal profile. ColorLevel 0 means no color; all styles degrade to plain text.

func IsASCIIMode added in v0.7.2

func IsASCIIMode() bool

IsASCIIMode is the exported form of isASCIIMode. Returns true when RNIX_ASCII=1 or RNIX_ASCII=true.

func IsFailedResult added in v0.7.0

func IsFailedResult(result string) bool

IsFailedResult is the exported form of isFailedResult. Returns true when the result string indicates failure.

func IsStale added in v0.7.2

func IsStale(lastHeartbeat time.Time, stepTimeout time.Duration) bool

IsStale returns true if a process has exceeded its step timeout. Returns false if timeout is disabled (0) or heartbeat is zero.

func RenderComposeDownHeader

func RenderComposeDownHeader(r *Renderer, file string)

RenderComposeDownHeader outputs the compose down header line.

func RenderComposeDownSummary

func RenderComposeDownSummary(r *Renderer, killed []ComposeDownEntry, skipped []ComposeDownEntry, errors []string)

RenderComposeDownSummary outputs the compose down teardown summary.

func RenderComposeDownSummaryJSON

func RenderComposeDownSummaryJSON(r *Renderer, killed []ComposeDownEntry, skipped []ComposeDownEntry, errors []string)

RenderComposeDownSummaryJSON outputs the compose down summary as JSON.

func RenderComposeHeader

func RenderComposeHeader(r *Renderer, intent string)

RenderComposeHeader outputs the compose orchestration header line.

func RenderComposeProgress

func RenderComposeProgress(r *Renderer, name string, status string, index int, total int, exitCode int)

RenderComposeProgress outputs a real-time progress line for a compose agent. Format: compose N/total name: status (exit_code)

func RenderComposeSummary

func RenderComposeSummary(r *Renderer, results []compose.ScheduleResult, tokenMap map[string]int)

RenderComposeSummary outputs the compose orchestration summary table.

func RenderComposeSummaryJSON

func RenderComposeSummaryJSON(r *Renderer, results []compose.ScheduleResult, tokenMap map[string]int)

RenderComposeSummaryJSON outputs the compose summary as JSON.

func RenderDriftList

func RenderDriftList(r *Renderer, drifts []ipc.DriftItemWire, mode OutputMode)

RenderDriftList renders the list of active drifts.

func RenderError

func RenderError(r *Renderer, device string, reason string, impact string, suggestion string)

RenderError outputs a three-line error block:

✗ {device}: {reason}
  → {impact}
  → 建议: {suggestion}

func RenderIntentList

func RenderIntentList(r *Renderer, trees []*ipc.IntentTreeWire, mode OutputMode)

RenderIntentList renders a table of all intents.

func RenderIntentMergeResult

func RenderIntentMergeResult(r *Renderer, added, modified []string, mode OutputMode)

RenderIntentMergeResult renders the result of an incremental merge operation.

func RenderIntentNodeEvent

func RenderIntentNodeEvent(r *Renderer, eventType, nodeID, detail string, pid uint64, mode OutputMode)

RenderIntentNodeEvent renders a node lifecycle event.

func RenderIntentNodeRetry

func RenderIntentNodeRetry(r *Renderer, nodeID string, attempt, maxRetries int, mode OutputMode)

RenderIntentNodeRetry renders a retry event.

func RenderIntentNodeTimeout

func RenderIntentNodeTimeout(r *Renderer, nodeID string, mode OutputMode)

RenderIntentNodeTimeout renders a timeout event.

func RenderIntentProgress

func RenderIntentProgress(r *Renderer, completed, total int, mode OutputMode)

RenderIntentProgress renders a progress update.

func RenderIntentStatusDetail

func RenderIntentStatusDetail(r *Renderer, tree *ipc.IntentTreeWire, mode OutputMode)

RenderIntentStatusDetail renders an enhanced status view for a single intent.

func RenderIntentTree

func RenderIntentTree(r *Renderer, tree *ipc.IntentTreeWire, mode OutputMode)

RenderIntentTree renders the intent tree decomposition.

func RenderProcessTable

func RenderProcessTable(r *Renderer, procs []vfs.ProcInfo, verbose, showUUID bool)

RenderProcessTable renders a formatted process table to the renderer's writer. PID and STATE columns are always shown. Additional columns appear based on terminal width. When verbose is true, PPID and full INTENT columns are included. When showUUID is true, a truncated UUID column is displayed after PID.

func RenderResult

func RenderResult(r *Renderer, title string, content string)

RenderResult outputs a result box with a double-line border. Border color is success green; width adapts to min(termWidth, 120). Long content (>20 lines) is truncated with a line count indicator.

func RenderSummary

func RenderSummary(r *Renderer, pid types.PID, exitCode int, tokens int, elapsed time.Duration, provider, model string)

RenderSummary outputs a summary footer line:

[kernel] PID {N} exited({code}) | provider/model | tokens: {N} | elapsed: {N}s

func StateBadge added in v0.7.2

func StateBadge(state types.ProcessState, result string) string

StateBadge returns a coloured emoji or ASCII badge for a process state. For Dead processes, result distinguishes success (exit 0) from failure.

Unicode: Running/Created → 🟢, Suspended → 🟡, Dead+fail → "" (row is styled red), Dead+success → "" (row is dimmed) ASCII: [R], [S], [E], [D]

func StateSymbol added in v0.7.0

func StateSymbol(state types.ProcessState, result string) string

StateSymbol returns a single-character status symbol for the given process state. For Dead processes, result is inspected to distinguish success (exit 0) from failure (exit != 0): an empty result or one containing "error", "fail", or "timeout" is treated as failure.

When RNIX_ASCII=1, ASCII-safe characters are used instead of Unicode glyphs.

func StripAnsi

func StripAnsi(s string) string

StripAnsi removes ANSI escape sequences from a string to calculate visible width.

Types

type ComposeDownEntry

type ComposeDownEntry struct {
	PID    types.PID
	Intent string
	State  string // only set for skipped (completed) processes
}

ComposeDownEntry represents a single process entry in compose down results.

type OutputMode

type OutputMode int

OutputMode determines the verbosity and format of CLI output.

const (
	ModeDefault OutputMode = iota
	ModeQuiet
	ModeVerbose
	ModeJSON
)

type ProgressReporter

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

ProgressReporter outputs agent progress messages to the renderer.

func NewProgressReporter

func NewProgressReporter(r *Renderer) *ProgressReporter

NewProgressReporter creates a ProgressReporter attached to the given renderer.

func (*ProgressReporter) AgentMessage

func (p *ProgressReporter) AgentMessage(pid types.PID, format string, args ...any)

AgentMessage outputs an agent-prefixed message: [agent/{pid}] {message}

func (*ProgressReporter) AgentStep

func (p *ProgressReporter) AgentStep(pid types.PID, step, total int)

AgentStep outputs a reasoning step progress line (verbose mode only after Story 3.6).

func (*ProgressReporter) AgentStepComplete added in v0.7.0

func (p *ProgressReporter) AgentStepComplete(pid types.PID, step int, action string, summary string)

AgentStepComplete outputs a step completion summary: [agent/{pid}] step {step}: {summary} When summary is non-empty, it is displayed directly (action type is omitted to avoid double-arrow with tool_call summaries that already contain "→"). When summary is empty, only the action type is shown.

func (*ProgressReporter) KernelMessage

func (p *ProgressReporter) KernelMessage(format string, args ...any)

KernelMessage outputs a kernel-prefixed message: [kernel] {message}

type Renderer

type Renderer struct {
	Profile    TerminalProfile
	Writer     io.Writer
	OutputMode OutputMode
}

Renderer manages styled output to a writer using a detected terminal profile.

func NewRenderer

func NewRenderer(w io.Writer, mode OutputMode) *Renderer

NewRenderer creates a Renderer for the given writer and output mode.

type TerminalProfile

type TerminalProfile struct {
	Width      int
	IsTTY      bool
	ColorLevel int // 0=none, 1=16-color, 2=256-color, 3=truecolor
	IsUnicode  bool
}

TerminalProfile describes the capabilities of the output terminal.

func DetectProfile

func DetectProfile(w io.Writer) TerminalProfile

DetectProfile inspects the given writer and environment to build a TerminalProfile.

Jump to

Keyboard shortcuts

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