Documentation
¶
Overview ¶
Package output provides formatted output for the epack CLI.
It handles human-readable vs JSON output, TTY detection, and NO_COLOR support.
Index ¶
- Constants
- Variables
- func FormatBytes(n int64) string
- func FormatBytesFromJSON(n *json.Number) string
- func FormatDigest(digest string) string
- func TruncateDigest(digest string, maxLen int) string
- type Options
- type Palette
- func (p *Palette) Blue(s string) string
- func (p *Palette) Bold(s string) string
- func (p *Palette) BoldGreen(s string) string
- func (p *Palette) BoldRed(s string) string
- func (p *Palette) Cyan(s string) string
- func (p *Palette) Dim(s string) string
- func (p *Palette) Failure(s string) string
- func (p *Palette) Green(s string) string
- func (p *Palette) Magenta(s string) string
- func (p *Palette) Red(s string) string
- func (p *Palette) Success(s string) string
- func (p *Palette) Yellow(s string) string
- type ProgressBar
- type ProgressReader
- type Spinner
- type StepTracker
- type TableWriter
- type Writer
- func (w *Writer) Error(format string, args ...interface{})
- func (w *Writer) IsCI() bool
- func (w *Writer) IsJSON() bool
- func (w *Writer) IsQuiet() bool
- func (w *Writer) IsTTY() bool
- func (w *Writer) IsVerbose() bool
- func (w *Writer) JSON(v interface{}) error
- func (w *Writer) JSONCompact(v interface{}) error
- func (w *Writer) KeyValue(key, value string)
- func (w *Writer) Palette() *Palette
- func (w *Writer) Print(format string, args ...interface{})
- func (w *Writer) PrintAlways(format string, args ...interface{})
- func (w *Writer) Println(args ...interface{})
- func (w *Writer) Prompt(prompt string) (string, error)
- func (w *Writer) PromptConfirm(format string, args ...interface{}) bool
- func (w *Writer) PromptRequired(prompt string) (string, error)
- func (w *Writer) PromptWithDefault(prompt, defaultVal string) (string, error)
- func (w *Writer) Section(title string)
- func (w *Writer) StartProgress(message string, total int64) *ProgressBar
- func (w *Writer) StartSpinner(message string) *Spinner
- func (w *Writer) StartSpinnerWithContext(ctx context.Context, message string) *Spinner
- func (w *Writer) StartSteps(steps []string) *StepTracker
- func (w *Writer) Success(format string, args ...interface{})
- func (w *Writer) Table() *TableWriter
- func (w *Writer) Verbose(format string, args ...interface{})
- func (w *Writer) Warning(format string, args ...interface{})
Constants ¶
const DigestMaxLen = 19
DigestMaxLen is the default max length for truncated digests. Shows algorithm prefix plus first few chars: "sha256:abc123..."
Variables ¶
var ErrNotInteractive = fmt.Errorf("cannot prompt: not running in interactive terminal")
ErrNotInteractive is returned when prompts are attempted in non-TTY mode.
Functions ¶
func FormatBytes ¶
FormatBytes formats a byte count as a human-readable string (KB, MB, GB).
func FormatBytesFromJSON ¶
FormatBytesFromJSON formats a json.Number byte count as human-readable. Returns empty string if n is nil.
func FormatDigest ¶
FormatDigest shortens a digest string for display using the default length.
func TruncateDigest ¶
TruncateDigest shortens a digest string for display with custom length. Keeps the algorithm prefix and first few characters.
Types ¶
type Options ¶
type Options struct {
Quiet bool // Suppress non-essential output
JSON bool // Output in JSON format
NoColor bool // Disable colored output
Verbose bool // Enable verbose output
CI bool // CI mode: disable spinners, add timestamps
}
Options configures the output writer.
type Palette ¶
type Palette struct {
// contains filtered or unexported fields
}
Palette provides color formatting that respects NO_COLOR.
func NewPalette ¶
NewPalette creates a new color palette. If enabled is false, all methods return the input unchanged.
type ProgressBar ¶
type ProgressBar struct {
// contains filtered or unexported fields
}
ProgressBar provides a progress indication for operations with known size. It displays a progress bar with percentage in TTY mode, or periodic percentage updates in non-TTY mode.
func (*ProgressBar) Done ¶
func (p *ProgressBar) Done(message string)
Done completes the progress bar with a success message.
func (*ProgressBar) Fail ¶
func (p *ProgressBar) Fail(message string)
Fail stops the progress bar and shows a failure message.
func (*ProgressBar) Update ¶
func (p *ProgressBar) Update(current int64)
Update sets the current progress. Thread-safe.
type ProgressReader ¶
type ProgressReader struct {
// contains filtered or unexported fields
}
ProgressReader wraps an io.Reader to report progress to a ProgressBar.
func NewProgressReader ¶
func NewProgressReader(r io.Reader, bar *ProgressBar) *ProgressReader
NewProgressReader creates a reader that updates the progress bar as data is read.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner provides animated progress indication for long-running operations. It displays a spinning animation in TTY mode, or falls back to simple status messages in non-TTY mode.
type StepTracker ¶
type StepTracker struct {
// contains filtered or unexported fields
}
StepTracker provides multi-step progress tracking for complex operations. It shows completed steps with checkmarks and the current step with a spinner.
func (*StepTracker) Complete ¶
func (st *StepTracker) Complete()
Complete marks the final step as complete.
func (*StepTracker) Current ¶
func (st *StepTracker) Current() int
Current returns the current step index (0-based).
func (*StepTracker) CurrentStep ¶
func (st *StepTracker) CurrentStep() string
CurrentStep returns the name of the current step.
func (*StepTracker) Fail ¶
func (st *StepTracker) Fail(message string)
Fail marks the current step as failed and stops tracking.
func (*StepTracker) Next ¶
func (st *StepTracker) Next() bool
Next advances to the next step. Returns false if all steps are complete. The previous step is marked as complete with a checkmark.
type TableWriter ¶
type TableWriter struct {
// contains filtered or unexported fields
}
TableWriter handles tabular output.
func (*TableWriter) Flush ¶
func (t *TableWriter) Flush() error
Flush flushes the table output and returns any error encountered.
func (*TableWriter) Header ¶
func (t *TableWriter) Header(cols ...string)
Header writes a table header row.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer handles formatted output for the CLI.
func (*Writer) JSONCompact ¶
JSONCompact writes a value as compact JSON to stdout.
func (*Writer) PrintAlways ¶
PrintAlways writes to stdout even in quiet mode.
func (*Writer) Println ¶
func (w *Writer) Println(args ...interface{})
Println writes a line to stdout (respects quiet mode).
func (*Writer) Prompt ¶
Prompt reads a line of text from stdin, displaying the given prompt. Returns the trimmed input and any error. If stdin is not a TTY, returns ErrNotInteractive.
func (*Writer) PromptConfirm ¶
PromptConfirm asks a yes/no question and returns true if the user confirms. Default is yes (pressing Enter confirms). Returns false in non-TTY mode.
func (*Writer) PromptRequired ¶
PromptRequired keeps prompting until non-empty input is provided. Returns ErrNotInteractive if stdin is not a TTY.
func (*Writer) PromptWithDefault ¶
PromptWithDefault reads input with a default value shown in brackets. If user enters empty input, returns the default.
func (*Writer) StartProgress ¶
func (w *Writer) StartProgress(message string, total int64) *ProgressBar
StartProgress begins a progress bar with the given message and total size. In TTY mode, it displays an animated bar. In non-TTY/CI mode, it prints periodic percentage updates.
func (*Writer) StartSpinner ¶
StartSpinner begins a spinner with the given message. The spinner animates in TTY mode or prints a static message otherwise. Call Success(), Fail(), or Stop() to end the spinner. For automatic cleanup on context cancellation, use StartSpinnerWithContext.
func (*Writer) StartSpinnerWithContext ¶
StartSpinnerWithContext begins a spinner that automatically stops when the context is cancelled. This prevents goroutine leaks if the caller panics or forgets to call Stop(). The spinner animates in TTY mode or prints a static message otherwise. In CI mode, spinners are disabled and timestamps are added. Call Success(), Fail(), or Stop() to end the spinner, or let the context cancel it.
func (*Writer) StartSteps ¶
func (w *Writer) StartSteps(steps []string) *StepTracker
StartSteps begins a multi-step operation with the given step names. Each step should be a short description (e.g., "Verifying pack integrity").
func (*Writer) Table ¶
func (w *Writer) Table() *TableWriter
Table creates a new table writer for tabular output.