output

package
v1.3.154 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package output handles CLI output formatting (pretty tables, JSON, raw).

Index

Constants

This section is empty.

Variables

View Source
var (
	// F is the global formatter, set during initialization.
	F Formatter = &AgentFormatter{w: os.Stdout}
	// IsHuman indicates whether rich output mode is active.
	IsHuman bool
)
View Source
var (
	Bold    = color.New(color.Bold).SprintFunc()
	Green   = color.New(color.FgGreen).SprintFunc()
	Red     = color.New(color.FgRed).SprintFunc()
	Yellow  = color.New(color.FgYellow).SprintFunc()
	Cyan    = color.New(color.FgCyan).SprintFunc()
	Dim     = color.New(color.Faint).SprintFunc()
	Success = color.New(color.FgGreen, color.Bold).SprintFunc()
	Error   = color.New(color.FgRed, color.Bold).SprintFunc()
)

Functions

func Errorf

func Errorf(format string, args ...any)

Errorf prints an error message to stderr.

func Infof

func Infof(format string, args ...any)

Infof prints an info message.

func InitFormatter

func InitFormatter(human bool)

InitFormatter sets up the global formatter based on mode.

func JSON

func JSON(data any) error

JSON prints data as indented JSON to stdout.

func StatusColor

func StatusColor(status string) string

StatusColor returns a colored status string.

func Successf

func Successf(format string, args ...any)

Successf prints a success message.

func Table

func Table(headers []string, rows [][]string)

Table prints a simple table with headers and rows.

Types

type AgentFormatter

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

func (*AgentFormatter) CheckResult

func (f *AgentFormatter) CheckResult(name, status, message string)

func (*AgentFormatter) CheckSummary

func (f *AgentFormatter) CheckSummary(ok, warn, fail int)

func (*AgentFormatter) Error

func (f *AgentFormatter) Error(msg string)

func (*AgentFormatter) Finish

func (f *AgentFormatter) Finish()

func (*AgentFormatter) Info

func (f *AgentFormatter) Info(msg string)

func (*AgentFormatter) KeyValue

func (f *AgentFormatter) KeyValue(key, value string)

func (*AgentFormatter) List

func (f *AgentFormatter) List(items []string)

func (*AgentFormatter) Printf

func (f *AgentFormatter) Printf(format string, a ...any)

func (*AgentFormatter) Println

func (f *AgentFormatter) Println(a ...any)

func (*AgentFormatter) Progress

func (f *AgentFormatter) Progress(completed, total int)

func (*AgentFormatter) Section

func (f *AgentFormatter) Section(title string)

func (*AgentFormatter) SectionIcon

func (f *AgentFormatter) SectionIcon(_ string) string

func (*AgentFormatter) StatusText

func (f *AgentFormatter) StatusText(status string) string

func (*AgentFormatter) Success

func (f *AgentFormatter) Success(msg string)

func (*AgentFormatter) Table

func (f *AgentFormatter) Table(headers []string, rows [][]string)

func (*AgentFormatter) Warning

func (f *AgentFormatter) Warning(msg string)

type Formatter

type Formatter interface {
	Table(headers []string, rows [][]string)
	Section(title string)
	KeyValue(key, value string)
	Success(msg string)
	Error(msg string)
	Finish()
	Info(msg string)
	Warning(msg string)
	List(items []string)
	Progress(completed, total int)
	CheckResult(name, status, message string)
	CheckSummary(ok, warn, fail int)
	StatusText(status string) string
	SectionIcon(id string) string
	Println(a ...any)
	Printf(format string, a ...any)
}

Formatter provides structured output methods for CLI commands.

type HumanFormatter

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

func (*HumanFormatter) CheckResult

func (f *HumanFormatter) CheckResult(name, status, message string)

func (*HumanFormatter) CheckSummary

func (f *HumanFormatter) CheckSummary(ok, warn, fail int)

func (*HumanFormatter) Error

func (f *HumanFormatter) Error(msg string)

func (*HumanFormatter) Finish

func (f *HumanFormatter) Finish()

Finish prints the agent hint at the end of human-mode output

func (*HumanFormatter) Info

func (f *HumanFormatter) Info(msg string)

func (*HumanFormatter) KeyValue

func (f *HumanFormatter) KeyValue(key, value string)

func (*HumanFormatter) List

func (f *HumanFormatter) List(items []string)

func (*HumanFormatter) Printf

func (f *HumanFormatter) Printf(format string, a ...any)

func (*HumanFormatter) Println

func (f *HumanFormatter) Println(a ...any)

func (*HumanFormatter) Progress

func (f *HumanFormatter) Progress(completed, total int)

func (*HumanFormatter) Section

func (f *HumanFormatter) Section(title string)

func (*HumanFormatter) SectionIcon

func (f *HumanFormatter) SectionIcon(id string) string

func (*HumanFormatter) StatusText

func (f *HumanFormatter) StatusText(status string) string

func (*HumanFormatter) Success

func (f *HumanFormatter) Success(msg string)

func (*HumanFormatter) Table

func (f *HumanFormatter) Table(headers []string, rows [][]string)

func (*HumanFormatter) Warning

func (f *HumanFormatter) Warning(msg string)

type Spinner

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

Spinner shows an animated spinner on a single line for human mode. In agent mode it's a no-op.

func NewSpinner

func NewSpinner(msg string) *Spinner

NewSpinner creates and starts a spinner with the given message.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner and clears the line.

func (*Spinner) StopError

func (s *Spinner) StopError(msg string)

StopError stops with a red X.

func (*Spinner) StopSuccess

func (s *Spinner) StopSuccess(msg string)

StopSuccess stops with a green checkmark.

func (*Spinner) StopWarning

func (s *Spinner) StopWarning(msg string)

StopWarning stops with a yellow warning sign.

func (*Spinner) StopWith

func (s *Spinner) StopWith(icon, msg string)

StopWith stops the spinner and replaces it with a final message.

Jump to

Keyboard shortcuts

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