output

package
v0.0.0-...-ef18e8d Latest Latest
Warning

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

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

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

View Source
const (
	SeparatorWidth      = 50
	RepoNameWidth       = 20
	RepoSizeWidth       = 10
	RepoLastFetchWidth  = 20
	RepoWorkspacesWidth = 10
	RepoAliasWidth      = 16
	RepoURLWidth        = 45
	RepoTagsWidth       = 20
)

Shared formatting constants for CLI output.

Variables

View Source
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"))
)
View Source
var ASCIIBox = BoxChars{
	TopLeft:     "+",
	TopRight:    "+",
	BottomLeft:  "+",
	BottomRight: "+",
	Horizontal:  "-",
	Vertical:    "|",
	TeeLeft:     "+",
	TeeRight:    "+",
}

ASCIIBox provides ASCII fallback characters.

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

func Colorize(style lipgloss.Style, text string) string

Colorize renders text with the provided style when color is enabled.

func Column

func Column(text string, width int, style lipgloss.Style) string

Column renders a fixed-width column with optional styling.

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes formats a byte count as a human-readable string (B, KB, MB, GB).

func FormatErrorJSON

func FormatErrorJSON(err error) string

FormatErrorJSON returns a standardized JSON error string.

func FormatKeyValue

func FormatKeyValue(key, value string, keyWidth int) string

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

func FormatStatusSummary(label string, parts []string, style lipgloss.Style, icon string) string

FormatStatusSummary formats a summary line with a leading status icon.

func HorizontalRule

func HorizontalRule(width int) string

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

func PrintErrorJSON(err error) error

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 Println

func Println(message string)

Println prints a message with newline.

func SanitizeInlineMessage

func SanitizeInlineMessage(text string, maxRunes int) string

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 Summary

func Summary(parts ...string) string

Summary outputs a summary line with bullet separators.

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

func WriteIndentedJSON(w io.Writer, v interface{}) error

WriteIndentedJSON writes the value as indented JSON to the provided writer.

func WriteReportHeader

func WriteReportHeader(w io.Writer, title string, width int)

WriteReportHeader writes a report title and divider.

func WriteReportSummary

func WriteReportSummary(w io.Writer, summary string, width int)

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 NewBox

func NewBox(title string) *Box

NewBox creates a new Box with the given title.

func (*Box) Render

func (b *Box) Render(lines []string)

Render renders complete box content.

func (*Box) RenderWithSections

func (b *Box) RenderWithSections(sections []BoxSection)

RenderWithSections renders box content with multiple sections.

func (*Box) WithStyle

func (b *Box) WithStyle(style BoxStyle) *Box

WithStyle sets the box style.

func (*Box) WithWidth

func (b *Box) WithWidth(width int) *Box

WithWidth sets the box width.

func (*Box) WithWriter

func (b *Box) WithWriter(w io.Writer) *Box

WithWriter sets the output writer.

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

type BoxSection struct {
	Title string
	Lines []string
}

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

func NewIconsWithMode(useUnicode bool) Icons

NewIconsWithMode creates Icons with explicit Unicode mode.

func (Icons) Behind

func (i Icons) Behind() string

Behind returns the behind remote icon (↓ or v).

func (Icons) Bullet

func (i Icons) Bullet() string

Bullet returns a list bullet (• or *).

func (Icons) Clean

func (i Icons) Clean() string

Clean returns the clean icon (○ or -).

func (Icons) Dirty

func (i Icons) Dirty() string

Dirty returns the dirty/modified icon (● or *).

func (Icons) Error

func (i Icons) Error() string

Error returns the error icon (✗ or [X]).

func (Icons) Info

func (i Icons) Info() string

Info returns the info icon (ℹ or [i]).

func (Icons) ResultIcon

func (i Icons) ResultIcon(success bool) string

ResultIcon returns the appropriate icon for success/failure.

func (Icons) SpinnerFrames

func (i Icons) SpinnerFrames() []string

SpinnerFrames returns the frames for an animated spinner.

func (Icons) StatusIcon

func (i Icons) StatusIcon(isDirty bool) string

StatusIcon returns the appropriate icon for a clean/dirty status.

func (Icons) Success

func (i Icons) Success() string

Success returns the success icon (✓ or [ok]).

func (Icons) Unpushed

func (i Icons) Unpushed() string

Unpushed returns the unpushed commits icon (↑ or ^).

func (Icons) UseUnicode

func (i Icons) UseUnicode() bool

UseUnicode returns whether Unicode icons are enabled.

func (Icons) Warning

func (i Icons) Warning() string

Warning returns the warning icon (⚠ or [!]).

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

func (p *Progress) Cancel()

Cancel marks the progress as cancelled.

func (*Progress) Current

func (p *Progress) Current() int

Current returns the current progress count.

func (*Progress) Finish

func (p *Progress) Finish()

Finish completes the progress bar and moves to a new line.

func (*Progress) Increment

func (p *Progress) Increment(msg string)

Increment advances progress by one and optionally updates the message.

func (*Progress) IsTTY

func (p *Progress) IsTTY() bool

IsTTY returns whether progress output goes to a terminal.

func (*Progress) SetCurrent

func (p *Progress) SetCurrent(n int, msg string)

SetCurrent sets the current progress value directly.

func (*Progress) SetMessage

func (p *Progress) SetMessage(msg string)

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

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner with the given initial message.

func (*Spinner) SetMessage

func (s *Spinner) SetMessage(msg string)

SetMessage updates the spinner message.

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner and clears the line.

func (*Spinner) StopWithError

func (s *Spinner) StopWithError(message string)

StopWithError stops the spinner with an error message.

func (*Spinner) StopWithMessage

func (s *Spinner) StopWithMessage(icon, message string)

StopWithMessage stops the spinner and displays a final message.

func (*Spinner) StopWithSuccess

func (s *Spinner) StopWithSuccess(message string)

StopWithSuccess stops the spinner with a success message.

func (*Spinner) WithWriter

func (s *Spinner) WithWriter(w io.Writer) *Spinner

WithWriter sets a custom writer for the spinner. Must be called before Start().

Jump to

Keyboard shortcuts

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