Documentation
¶
Overview ¶
Package output provides helpers for CLI output formatting.
Package output provides helpers for CLI output formatting.
Package output provides helpers for CLI output formatting.
Package output provides helpers for CLI output formatting.
Package output provides helpers for CLI output formatting.
Package output provides helpers for CLI output formatting.
Package output provides helpers for CLI output formatting.
Package output provides helpers for CLI output formatting.
Package output provides helpers for CLI output formatting.
Package output provides helpers for CLI output formatting.
Index ¶
- Constants
- Variables
- func ColorEnabled() bool
- func Colorize(style lipgloss.Style, text string) string
- func Column(text string, width int, style lipgloss.Style) string
- func FormatBytes(bytes int64) string
- func FormatErrorJSON(err error) string
- func FormatKeyValue(key, value string, keyWidth int) string
- func FormatStatusRow(name string, nameWidth int, status string, style lipgloss.Style, icon string) string
- func FormatStatusSummary(label string, parts []string, style lipgloss.Style, icon string) string
- func HorizontalRule(width int) string
- func Info(message string)
- func Infof(format string, args ...interface{})
- func Print(message string)
- func PrintErrorJSON(err error) error
- func PrintJSON(v interface{}) error
- func Printf(format string, args ...interface{})
- func Println(message string)
- func SanitizeInlineMessage(text string, maxRunes int) string
- func Success(action, target string)
- func SuccessWithPath(action, target, path string)
- func Summary(parts ...string) string
- func UnicodeEnabled() bool
- func Warnf(format string, args ...interface{})
- func WriteIndentedJSON(w io.Writer, v interface{}) error
- func WriteReportHeader(w io.Writer, title string, width int)
- func WriteReportSummary(w io.Writer, summary string, width int)
- func WriteStructuredReport(w io.Writer, report interface{}, jsonOutput bool, ...) error
- type Box
- type BoxChars
- type BoxSection
- type BoxStyle
- type ErrorInfo
- type Icons
- func (i Icons) Behind() string
- func (i Icons) Bullet() string
- func (i Icons) Clean() string
- func (i Icons) Dirty() string
- func (i Icons) Error() string
- func (i Icons) Info() string
- func (i Icons) ResultIcon(success bool) string
- func (i Icons) SpinnerFrames() []string
- func (i Icons) StatusIcon(isDirty bool) string
- func (i Icons) Success() string
- func (i Icons) Unpushed() string
- func (i Icons) UseUnicode() bool
- func (i Icons) Warning() string
- type JSONPrinter
- type Progress
- type ProgressOptions
- type Response
- type Spinner
Constants ¶
const ( SeparatorWidth = 50 RepoNameWidth = 20 RepoSizeWidth = 10 RepoLastFetchWidth = 20 RepoWorkspacesWidth = 10 RepoAliasWidth = 16 RepoURLWidth = 45 RepoTagsWidth = 20 )
Shared formatting constants for CLI output.
Variables ¶
var ( // AccentStyle highlights headers and labels. AccentStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#22D3EE")).Bold(true) // SuccessStyle highlights successful outcomes. SuccessStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#10B981")) // WarningStyle highlights warnings and dry-run output. WarningStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#F59E0B")) // ErrorStyle highlights errors and failures. ErrorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#EF4444")) // InfoStyle highlights informational messages. InfoStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#38BDF8")) // MutedStyle de-emphasizes secondary text. MutedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#9CA3AF")) )
var ASCIIBox = BoxChars{
TopLeft: "+",
TopRight: "+",
BottomLeft: "+",
BottomRight: "+",
Horizontal: "-",
Vertical: "|",
TeeLeft: "+",
TeeRight: "+",
}
ASCIIBox provides ASCII fallback characters.
var UnicodeBox = BoxChars{
TopLeft: "┌",
TopRight: "┐",
BottomLeft: "└",
BottomRight: "┘",
Horizontal: "─",
Vertical: "│",
TeeLeft: "├",
TeeRight: "┤",
}
UnicodeBox provides Unicode box-drawing characters.
Functions ¶
func ColorEnabled ¶
func ColorEnabled() bool
ColorEnabled returns true when color output should be used. Precedence: NO_COLOR > CANOPY_COLOR > TTY detection > TERM=dumb.
func FormatBytes ¶
FormatBytes formats a byte count as a human-readable string (B, KB, MB, GB).
func FormatErrorJSON ¶
FormatErrorJSON returns a standardized JSON error string.
func FormatKeyValue ¶
FormatKeyValue formats a key-value pair for display.
func FormatStatusRow ¶
func FormatStatusRow(name string, nameWidth int, status string, style lipgloss.Style, icon string) string
FormatStatusRow formats a single icon/name/status row for CLI output.
func FormatStatusSummary ¶
FormatStatusSummary formats a summary line with a leading status icon.
func HorizontalRule ¶
HorizontalRule outputs a horizontal divider line.
func Info ¶
func Info(message string)
Info prints a neutral information message. Example: Info("No orphaned worktrees found.") -> "No orphaned worktrees found."
func Infof ¶
func Infof(format string, args ...interface{})
Infof prints a formatted neutral information message. Example: Infof("Found %d items", 5) -> "Found 5 items"
func Print ¶
func Print(message string)
Print prints a message without newline. Use for raw output like paths or data.
func PrintErrorJSON ¶
PrintErrorJSON writes an error as structured JSON to stdout.
func PrintJSON ¶
func PrintJSON(v interface{}) error
PrintJSON writes the value as indented JSON to stdout.
func Printf ¶
func Printf(format string, args ...interface{})
Printf prints a formatted message without newline.
func SanitizeInlineMessage ¶
SanitizeInlineMessage collapses whitespace and truncates long inline messages.
func Success ¶
func Success(action, target string)
Success prints a success message in the format: "<action> <target>\n" Example: Success("Created workspace", "my-workspace") -> "Created workspace my-workspace"
func SuccessWithPath ¶
func SuccessWithPath(action, target, path string)
SuccessWithPath prints a success message with a path in the format: "<action> <target> in <path>\n" Example: SuccessWithPath("Created workspace", "my-ws", "/path/to/ws") -> "Created workspace my-ws in /path/to/ws"
func UnicodeEnabled ¶
func UnicodeEnabled() bool
UnicodeEnabled returns true when Unicode output should be used. This follows the same rules as ColorEnabled since non-color terminals often also have limited Unicode support.
func Warnf ¶
func Warnf(format string, args ...interface{})
Warnf prints a formatted warning message to stderr. Example: Warnf("Missing %d files", 3) -> "Missing 3 files"
func WriteIndentedJSON ¶
WriteIndentedJSON writes the value as indented JSON to the provided writer.
func WriteReportHeader ¶
WriteReportHeader writes a report title and divider.
func WriteReportSummary ¶
WriteReportSummary writes a report summary with a divider.
func WriteStructuredReport ¶
func WriteStructuredReport(w io.Writer, report interface{}, jsonOutput bool, renderHuman func(io.Writer) error) error
WriteStructuredReport writes a raw JSON report or renders a human-readable report. Unlike PrintJSON, this preserves the caller's existing top-level JSON shape.
Types ¶
type Box ¶
type Box struct {
// contains filtered or unexported fields
}
Box renders content within a bordered box.
func (*Box) RenderWithSections ¶
func (b *Box) RenderWithSections(sections []BoxSection)
RenderWithSections renders box content with multiple sections.
type BoxChars ¶
type BoxChars struct {
TopLeft string
TopRight string
BottomLeft string
BottomRight string
Horizontal string
Vertical string
TeeLeft string
TeeRight string
}
BoxChars defines the characters used for box drawing.
type BoxSection ¶
BoxSection represents a titled section within a box.
type BoxStyle ¶
type BoxStyle struct {
Title lipgloss.Style
Content lipgloss.Style
Border lipgloss.Style
HeaderLine lipgloss.Style
}
BoxStyle defines visual styling for a box.
func DefaultBoxStyle ¶
func DefaultBoxStyle() BoxStyle
DefaultBoxStyle returns the default styling for boxes.
type ErrorInfo ¶
type ErrorInfo struct {
Code string `json:"code"`
Message string `json:"message"`
Context map[string]string `json:"context,omitempty"`
Details string `json:"details,omitempty"`
}
ErrorInfo represents structured error information in JSON output.
type Icons ¶
type Icons struct {
// contains filtered or unexported fields
}
Icons provides consistent status icons for CLI output. When Unicode is disabled (e.g., NO_COLOR=1 or piped output), ASCII fallbacks are used for terminal compatibility.
func NewIcons ¶
func NewIcons() Icons
NewIcons creates a new Icons instance based on color/terminal capabilities.
func NewIconsWithMode ¶
NewIconsWithMode creates Icons with explicit Unicode mode.
func (Icons) ResultIcon ¶
ResultIcon returns the appropriate icon for success/failure.
func (Icons) SpinnerFrames ¶
SpinnerFrames returns the frames for an animated spinner.
func (Icons) StatusIcon ¶
StatusIcon returns the appropriate icon for a clean/dirty status.
func (Icons) UseUnicode ¶
UseUnicode returns whether Unicode icons are enabled.
type JSONPrinter ¶
type JSONPrinter struct {
// contains filtered or unexported fields
}
JSONPrinter handles JSON output formatting.
func NewJSONPrinter ¶
func NewJSONPrinter() *JSONPrinter
NewJSONPrinter creates a new JSONPrinter with default settings.
func (*JSONPrinter) PrintError ¶
func (p *JSONPrinter) PrintError(err error) error
PrintError prints an error response.
func (*JSONPrinter) PrintSuccess ¶
func (p *JSONPrinter) PrintSuccess(data interface{}) error
PrintSuccess prints a successful response with the given data.
func (*JSONPrinter) WithWriter ¶
func (p *JSONPrinter) WithWriter(w io.Writer) *JSONPrinter
WithWriter sets a custom writer for the printer.
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress tracks and displays operation progress.
func NewProgress ¶
func NewProgress(opts ProgressOptions) *Progress
NewProgress creates a progress tracker with the given options.
func (*Progress) Finish ¶
func (p *Progress) Finish()
Finish completes the progress bar and moves to a new line.
func (*Progress) SetCurrent ¶
SetCurrent sets the current progress value directly.
func (*Progress) SetMessage ¶
SetMessage updates the current operation message.
type ProgressOptions ¶
type ProgressOptions struct {
Total int
Width int
ShowPercentage bool
ShowCount bool
Writer io.Writer
}
ProgressOptions configures progress bar behavior.
func DefaultProgressOptions ¶
func DefaultProgressOptions(total int) ProgressOptions
DefaultProgressOptions returns sensible defaults for progress display.
type Response ¶
type Response struct {
Success bool `json:"success"`
Data interface{} `json:"data,omitempty"`
Error *ErrorInfo `json:"error,omitempty"`
}
Response is the standard JSON envelope for all CLI output.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner provides an animated loading indicator for long-running operations.
func NewSpinner ¶
NewSpinner creates a new spinner with the given initial message.
func (*Spinner) SetMessage ¶
SetMessage updates the spinner message.
func (*Spinner) StopWithError ¶
StopWithError stops the spinner with an error message.
func (*Spinner) StopWithMessage ¶
StopWithMessage stops the spinner and displays a final message.
func (*Spinner) StopWithSuccess ¶
StopWithSuccess stops the spinner with a success message.