output

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package output provides format-aware output writing for the CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bold

func Bold(s string) string

Bold wraps text in bold ANSI formatting.

func Cyan

func Cyan(s string) string

Cyan wraps text in cyan ANSI color.

func Green

func Green(s string) string

Green wraps text in green ANSI color.

func IsTTY

func IsTTY() bool

IsTTY returns true if stdout is a terminal.

func IsTerminal

func IsTerminal(f *os.File) bool

IsTerminal returns true if the file is a terminal.

func Red

func Red(s string) string

Red wraps text in red ANSI color.

func ShouldColorize

func ShouldColorize(colorSetting string) bool

ShouldColorize determines whether to use colors based on config, env, and TTY.

func Spinner

func Spinner(msg string) func()

Spinner writes a simple spinner message to stderr.

func TerminalWidth

func TerminalWidth() int

TerminalWidth returns the terminal width, defaulting to 80.

func Yellow

func Yellow(s string) string

Yellow wraps text in yellow ANSI color.

Types

type Format

type Format string

Format represents an output format.

const (
	FormatTable Format = "table"
	FormatJSON  Format = "json"
	FormatYAML  Format = "yaml"
)

type MultiProgress

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

MultiProgress manages multiple progress bars for backup.

func NewMultiProgress

func NewMultiProgress(color bool) *MultiProgress

NewMultiProgress creates a new multi-progress display.

func (*MultiProgress) Add

func (mp *MultiProgress) Add(label string, total int) *Progress

Add adds a progress item.

func (*MultiProgress) Start

func (mp *MultiProgress) Start()

Start begins rendering progress to stderr.

func (*MultiProgress) Stop

func (mp *MultiProgress) Stop()

Stop stops the multi-progress display.

type Progress

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

Progress tracks progress for a single item.

func NewProgress

func NewProgress(label string, total int, color bool) *Progress

NewProgress creates a new progress tracker.

func (*Progress) Complete

func (p *Progress) Complete()

Complete marks the progress as done.

func (*Progress) Current

func (p *Progress) Current() int

Current returns the current count.

func (*Progress) Increment

func (p *Progress) Increment()

Increment advances the progress by 1.

func (*Progress) IsDone

func (p *Progress) IsDone() bool

IsDone returns whether the progress is complete.

func (*Progress) Set

func (p *Progress) Set(current, total int)

Set updates both current and total.

type Writer

type Writer struct {
	Out    io.Writer
	Err    io.Writer
	Format Format
	Color  bool
	Quiet  bool
}

Writer writes formatted output to stdout.

func New

func New(format string, color bool, quiet bool) *Writer

New creates a new Writer with the given format.

func (*Writer) Errorf

func (w *Writer) Errorf(format string, args ...any)

Errorf writes an error to stderr.

func (*Writer) Hint

func (w *Writer) Hint(msg string)

Hint writes a hint to stderr (unless quiet).

func (*Writer) Info

func (w *Writer) Info(msg string)

Info writes an informational message to stderr (unless quiet).

func (*Writer) Success

func (w *Writer) Success(msg string)

Success writes a success message to stderr (unless quiet).

func (*Writer) Warn

func (w *Writer) Warn(msg string)

Warn writes a warning to stderr.

func (*Writer) WriteFormatted

func (w *Writer) WriteFormatted(v any, tableHeaders []string, tableRows [][]string) error

WriteFormatted outputs v in the configured format. For table format, tableHeaders and tableRows are used.

func (*Writer) WriteJSON

func (w *Writer) WriteJSON(v any) error

WriteJSON outputs v as JSON.

func (*Writer) WriteKeyValueTable

func (w *Writer) WriteKeyValueTable(m map[string]any) error

WriteKeyValueTable outputs a map as a vertical KEY / VALUE table. Nested values are summarized (e.g. "(array, 3 items)").

func (*Writer) WriteTable

func (w *Writer) WriteTable(headers []string, rows [][]string)

WriteTable outputs headers and rows as a table.

func (*Writer) WriteYAML

func (w *Writer) WriteYAML(v any) error

WriteYAML outputs v as YAML.

func (*Writer) Writeln

func (w *Writer) Writeln(s string)

Writeln writes a line to stdout.

Jump to

Keyboard shortcuts

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