output

package
v1.3.0 Latest Latest
Warning

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

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

README

CLI Output Package

This package provides colorized output and loading animations for the agentmgr CLI.

Features

Colors

The output package provides a consistent color scheme across CLI commands:

  • Green: Success messages and installed agents
  • Purple: Headers and emphasis
  • Orange: Warnings and updates available
  • Red: Errors
  • Cyan: Info messages
  • Gray: Muted text (methods, secondary info)
Color Control

Colors can be disabled in three ways:

  1. --no-color flag: agentmgr agent list --no-color
  2. NO_COLOR environment variable: export NO_COLOR=1
  3. Configuration file: Set ui.use_colors: false in config
Spinner Animations

Loading spinners provide visual feedback during long-running operations:

spinner := output.NewSpinner(
    output.WithMessage("Loading catalog..."),
    output.WithNoColor(!cfg.UI.UseColors),
)
spinner.Start()

// Do work...

spinner.Success("Operation completed!")
// or
spinner.Error("Operation failed")
// or
spinner.Stop()

The spinner automatically:

  • Displays an animated spinner during operation
  • Clears the spinner line when done
  • Shows appropriate icons for success/error/warning/info
Printer

The Printer provides a unified interface for colored output:

printer := output.NewPrinter(cfg, noColor)

printer.Success("Installation complete!")
printer.Info("Checking for updates...")
printer.Warning("Agent version is outdated")
printer.Error("Failed to connect to registry")
Styles

Access style helpers via printer.Styles():

styles := printer.Styles()

// Format agent names, versions, methods, headers
agentName := styles.FormatAgentName("aider")
version := styles.FormatVersion("1.2.3", hasUpdate)
method := styles.FormatMethod("npm")
header := styles.FormatHeader("AGENT")

// Status icons
icon := styles.UpdateIcon()      // ⬆
icon = styles.InstalledIcon()    // ●
icon = styles.NotInstalledIcon() // ○

// Badges
badge := styles.FormatBadge("new", "success")

Usage in Commands

Agent List

Shows a colored table with:

  • Purple headers
  • Bold agent names
  • Orange versions for outdated agents
  • Gray installation methods
  • Status icons (● for installed, ⬆ for updates available)
  • Spinner while detecting agents and checking versions
Agent Install

Shows spinner during:

  • Catalog loading
  • Package installation

Progress messages:

  • "Loading catalog..."
  • "Installing {agent} via {method}..."
  • "✓ Installed {agent} {version} successfully"
Agent Update

Shows spinner during:

  • Catalog loading
  • Agent detection
  • Version checking
  • Update operations

Colored output for:

  • List of available updates
  • Update progress for each agent
  • Success/error messages

Spinner Frames

Available spinner frame sets:

output.SpinnerFrames.Dots     // ⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏
output.SpinnerFrames.Line     // -\|/
output.SpinnerFrames.Arrow    // ←↖↑↗→↘↓↙
output.SpinnerFrames.Pulse    // ◐◓◑◒
output.SpinnerFrames.Binary   // 010010 001001 100100
output.SpinnerFrames.Circle   // ◜◠◝◞◡◟

Default is Dots which works well across all terminals.

Color Palette

The color palette is based on the Dracula theme:

  • Purple: #BD93F9
  • Green: #50FA7B
  • Orange: #FFB86C
  • Red: #FF5555
  • Cyan: #8BE9FD
  • Yellow: #F1FA8C
  • Gray: #6272A4
  • White: #F8F8F2

These colors provide good contrast and accessibility in both light and dark terminals.

Terminal Compatibility

The package uses Lip Gloss and termenv which automatically detect terminal capabilities:

  • True Color (24-bit): Full color support
  • ANSI 256 (8-bit): Approximate colors
  • ANSI (4-bit): Basic colors
  • ASCII: No colors (when NO_COLOR is set)

The output gracefully degrades based on terminal capabilities.

Documentation

Overview

Package output provides CLI output utilities with color support.

Package output provides CLI output utilities with color support.

Index

Constants

This section is empty.

Variables

View Source
var SpinnerFrames = struct {
	Dots   []string
	Line   []string
	Arrow  []string
	Pulse  []string
	Binary []string
	Circle []string
}{
	Dots:   []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"},
	Line:   []string{"-", "\\", "|", "/"},
	Arrow:  []string{"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"},
	Pulse:  []string{"◐", "◓", "◑", "◒"},
	Binary: []string{"010010", "001001", "100100", "010010", "001001"},
	Circle: []string{"◜", "◠", "◝", "◞", "◡", "◟"},
}

SpinnerFrames contains predefined spinner frame sets.

Functions

func NoColor added in v1.1.0

func NoColor(cfg *config.Config, explicitNoColor bool) bool

NoColor returns the single source of truth for "should output be colorless?" given a config and an explicit flag. Callers should use this helper instead of reading cfg.UI.UseColors, NO_COLOR, and --no-color separately, which historically drifted between call sites.

Order of precedence (any -> true):

  • NO_COLOR environment variable is set to a non-empty value
  • --no-color flag (caller passes this as explicitNoColor)
  • cfg.UI.UseColors is false

func VisibleWidth

func VisibleWidth(s string) int

VisibleWidth returns the visible width of a string (excluding ANSI codes)

Types

type Printer

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

Printer handles colorized output for CLI commands.

func NewPrinter

func NewPrinter(cfg *config.Config, noColor bool) *Printer

NewPrinter creates a new Printer instance.

func (*Printer) Error

func (p *Printer) Error(format string, args ...interface{})

Error prints an error message.

func (*Printer) Info

func (p *Printer) Info(format string, args ...interface{})

Info prints an info message.

func (*Printer) NoColor added in v1.1.0

func (p *Printer) NoColor() bool

NoColor returns true if the printer is configured to render without color. Use this to propagate the same setting to spinners and other output helpers, avoiding the need to re-derive from env / config at each call site.

func (*Printer) Print

func (p *Printer) Print(format string, args ...interface{})

Print prints a plain message.

func (*Printer) Printf

func (p *Printer) Printf(format string, args ...interface{})

Printf prints a formatted message without a newline.

func (*Printer) Println

func (p *Printer) Println(args ...interface{})

Println prints a message with a newline.

func (*Printer) SetErrorOutput

func (p *Printer) SetErrorOutput(w io.Writer)

SetErrorOutput sets the error output writer.

func (*Printer) SetOutput

func (p *Printer) SetOutput(w io.Writer)

SetOutput sets the output writer.

func (*Printer) Styles

func (p *Printer) Styles() *Styles

Styles returns the style definitions.

func (*Printer) Success

func (p *Printer) Success(format string, args ...interface{})

Success prints a success message.

func (*Printer) Warning

func (p *Printer) Warning(format string, args ...interface{})

Warning prints a warning message.

type Spinner

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

Spinner displays a loading animation in the terminal.

func NewSpinner

func NewSpinner(opts ...SpinnerOption) *Spinner

NewSpinner creates a new spinner instance.

func (*Spinner) Error

func (s *Spinner) Error(msg string)

Error stops the spinner and shows an error message.

func (*Spinner) Info

func (s *Spinner) Info(msg string)

Info stops the spinner and shows an info message.

func (*Spinner) Start

func (s *Spinner) Start()

Start starts the spinner animation.

When the output is not a TTY (e.g. piped, redirected, captured in CI), Start is a no-op. This prevents ANSI escape sequences from corrupting downstream consumers.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner animation.

When the spinner never started (non-TTY path), Stop is a no-op and the clear-line escape sequence is not emitted.

func (*Spinner) Success

func (s *Spinner) Success(msg string)

Success stops the spinner and shows a success message.

func (*Spinner) UpdateMessage

func (s *Spinner) UpdateMessage(msg string)

UpdateMessage updates the spinner message while it's running.

func (*Spinner) Warning

func (s *Spinner) Warning(msg string)

Warning stops the spinner and shows a warning message.

type SpinnerOption

type SpinnerOption func(*Spinner)

SpinnerOption is a functional option for configuring a Spinner.

func WithFrames

func WithFrames(frames []string) SpinnerOption

WithFrames sets custom spinner frames.

func WithInterval

func WithInterval(interval time.Duration) SpinnerOption

WithInterval sets the spinner animation interval.

func WithMessage

func WithMessage(msg string) SpinnerOption

WithMessage sets the spinner message.

func WithNoColor

func WithNoColor(noColor bool) SpinnerOption

WithNoColor disables color output.

func WithOutput

func WithOutput(w io.Writer) SpinnerOption

WithOutput sets the spinner output writer.

type Styles

type Styles struct {

	// Colors
	Purple lipgloss.Color
	Green  lipgloss.Color
	Orange lipgloss.Color
	Red    lipgloss.Color
	Cyan   lipgloss.Color
	Yellow lipgloss.Color
	Gray   lipgloss.Color
	White  lipgloss.Color

	// Text styles
	Success lipgloss.Style
	Error   lipgloss.Style
	Warning lipgloss.Style
	Info    lipgloss.Style
	Muted   lipgloss.Style
	Bold    lipgloss.Style
	Header  lipgloss.Style

	// Status styles
	StatusInstalled lipgloss.Style
	StatusUpdate    lipgloss.Style
	StatusNotFound  lipgloss.Style
	StatusError     lipgloss.Style

	// Badge styles
	Badge        lipgloss.Style
	BadgeSuccess lipgloss.Style
	BadgeWarning lipgloss.Style
	BadgeError   lipgloss.Style
	BadgeInfo    lipgloss.Style
	// contains filtered or unexported fields
}

Styles holds the visual styles for CLI output.

func (*Styles) ErrorIcon

func (s *Styles) ErrorIcon() string

ErrorIcon returns the error icon.

func (*Styles) FormatAgentName

func (s *Styles) FormatAgentName(name string) string

FormatAgentName formats an agent name.

func (*Styles) FormatBadge

func (s *Styles) FormatBadge(text, variant string) string

FormatBadge formats a badge with the given variant.

func (*Styles) FormatHeader

func (s *Styles) FormatHeader(text string) string

FormatHeader formats a table header.

func (*Styles) FormatMethod

func (s *Styles) FormatMethod(method string) string

FormatMethod formats an installation method.

func (*Styles) FormatStatus

func (s *Styles) FormatStatus(status string) string

FormatStatus formats a status indicator with color.

func (*Styles) FormatVersion

func (s *Styles) FormatVersion(version string, hasUpdate bool) string

FormatVersion formats a version string with color.

func (*Styles) InfoIcon

func (s *Styles) InfoIcon() string

InfoIcon returns the info icon.

func (*Styles) InstalledIcon

func (s *Styles) InstalledIcon() string

InstalledIcon returns the installed icon.

func (*Styles) NotInstalledIcon

func (s *Styles) NotInstalledIcon() string

NotInstalledIcon returns the not installed icon.

func (*Styles) SuccessIcon

func (s *Styles) SuccessIcon() string

SuccessIcon returns the success icon.

func (*Styles) UpdateIcon

func (s *Styles) UpdateIcon() string

UpdateIcon returns the update available icon.

func (*Styles) WarningIcon

func (s *Styles) WarningIcon() string

WarningIcon returns the warning icon.

type Table

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

Table handles aligned table output with ANSI color support.

func NewTable

func NewTable() *Table

NewTable creates a new Table instance.

func (*Table) AddRow

func (t *Table) AddRow(cells ...string) *Table

AddRow adds a row to the table.

func (*Table) Render

func (t *Table) Render()

Render outputs the table with proper alignment.

func (*Table) SetHeaders

func (t *Table) SetHeaders(headers ...string) *Table

SetHeaders sets the table headers.

func (*Table) SetOutput

func (t *Table) SetOutput(w io.Writer) *Table

SetOutput sets the output writer.

func (*Table) SetPadding

func (t *Table) SetPadding(p int) *Table

SetPadding sets the column padding.

Jump to

Keyboard shortcuts

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