output

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
const DigestMaxLen = 19

DigestMaxLen is the default max length for truncated digests. Shows algorithm prefix plus first few chars: "sha256:abc123..."

Variables

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

func FormatBytes(n int64) string

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

func FormatBytesFromJSON

func FormatBytesFromJSON(n *json.Number) string

FormatBytesFromJSON formats a json.Number byte count as human-readable. Returns empty string if n is nil.

func FormatDigest

func FormatDigest(digest string) string

FormatDigest shortens a digest string for display using the default length.

func TruncateDigest

func TruncateDigest(digest string, maxLen int) string

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

func NewPalette(enabled bool) *Palette

NewPalette creates a new color palette. If enabled is false, all methods return the input unchanged.

func (*Palette) Blue

func (p *Palette) Blue(s string) string

Blue returns blue text.

func (*Palette) Bold

func (p *Palette) Bold(s string) string

Bold returns bold text.

func (*Palette) BoldGreen

func (p *Palette) BoldGreen(s string) string

BoldGreen returns bold green text (for success).

func (*Palette) BoldRed

func (p *Palette) BoldRed(s string) string

BoldRed returns bold red text (for errors).

func (*Palette) Cyan

func (p *Palette) Cyan(s string) string

Cyan returns cyan text.

func (*Palette) Dim

func (p *Palette) Dim(s string) string

Dim returns dimmed text.

func (*Palette) Failure

func (p *Palette) Failure(s string) string

Failure formats a failure indicator.

func (*Palette) Green

func (p *Palette) Green(s string) string

Green returns green text.

func (*Palette) Magenta

func (p *Palette) Magenta(s string) string

Magenta returns magenta text.

func (*Palette) Red

func (p *Palette) Red(s string) string

Red returns red text.

func (*Palette) Success

func (p *Palette) Success(s string) string

Success formats a success indicator.

func (*Palette) Yellow

func (p *Palette) Yellow(s string) string

Yellow returns yellow text.

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.

func (*ProgressReader) Read

func (pr *ProgressReader) Read(p []byte) (int, error)

Read implements io.Reader and updates progress.

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.

func (*Spinner) Fail

func (s *Spinner) Fail(message string)

Fail stops the spinner and shows a failure message.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner without showing a completion message.

func (*Spinner) Success

func (s *Spinner) Success(message string)

Success stops the spinner and shows a success message.

func (*Spinner) UpdateMessage added in v0.1.17

func (s *Spinner) UpdateMessage(message string)

UpdateMessage changes the spinner's message while it's still running. This is useful for showing progress updates without stopping the spinner.

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.

func (*TableWriter) Row

func (t *TableWriter) Row(cols ...string)

Row writes a table row.

type Writer

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

Writer handles formatted output for the CLI.

func New

func New(stdout, stderr io.Writer, opts Options) *Writer

New creates a new output writer.

func (*Writer) Error

func (w *Writer) Error(format string, args ...interface{})

Error writes to stderr. File paths are redacted when redaction is enabled.

func (*Writer) IsCI

func (w *Writer) IsCI() bool

IsCI returns true if CI mode is enabled.

func (*Writer) IsJSON

func (w *Writer) IsJSON() bool

IsJSON returns true if JSON output is enabled.

func (*Writer) IsQuiet

func (w *Writer) IsQuiet() bool

IsQuiet returns true if quiet mode is enabled.

func (*Writer) IsTTY

func (w *Writer) IsTTY() bool

IsTTY returns true if stdout is a terminal.

func (*Writer) IsVerbose

func (w *Writer) IsVerbose() bool

IsVerbose returns true if verbose output is enabled.

func (*Writer) JSON

func (w *Writer) JSON(v interface{}) error

JSON writes a value as JSON to stdout.

func (*Writer) JSONCompact

func (w *Writer) JSONCompact(v interface{}) error

JSONCompact writes a value as compact JSON to stdout.

func (*Writer) KeyValue

func (w *Writer) KeyValue(key, value string)

KeyValue prints a key-value pair with consistent formatting.

func (*Writer) Palette

func (w *Writer) Palette() *Palette

Palette returns the color palette.

func (*Writer) Print

func (w *Writer) Print(format string, args ...interface{})

Print writes to stdout (respects quiet mode).

func (*Writer) PrintAlways

func (w *Writer) PrintAlways(format string, args ...interface{})

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

func (w *Writer) Prompt(prompt string) (string, error)

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

func (w *Writer) PromptConfirm(format string, args ...interface{}) bool

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

func (w *Writer) PromptRequired(prompt string) (string, error)

PromptRequired keeps prompting until non-empty input is provided. Returns ErrNotInteractive if stdin is not a TTY.

func (*Writer) PromptWithDefault

func (w *Writer) PromptWithDefault(prompt, defaultVal string) (string, error)

PromptWithDefault reads input with a default value shown in brackets. If user enters empty input, returns the default.

func (*Writer) Section

func (w *Writer) Section(title string)

Section prints a section header.

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

func (w *Writer) StartSpinner(message string) *Spinner

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

func (w *Writer) StartSpinnerWithContext(ctx context.Context, message string) *Spinner

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

func (w *Writer) Success(format string, args ...interface{})

Success prints a success message.

func (*Writer) Table

func (w *Writer) Table() *TableWriter

Table creates a new table writer for tabular output.

func (*Writer) Verbose

func (w *Writer) Verbose(format string, args ...interface{})

Verbose writes to stdout only in verbose mode.

func (*Writer) Warning

func (w *Writer) Warning(format string, args ...interface{})

Warning prints a warning message. File paths are redacted when redaction is enabled.

Jump to

Keyboard shortcuts

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