output

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package output provides CLI output handling with support for multiple modes.

This package abstracts stdout/stderr writing to enable:

  • Testable CLI commands via io.Writer injection
  • JSON output mode for scripting
  • Quiet mode for CI environments
  • Golden file testing
  • Colored output with TTY detection
  • Spinner animations for long operations

Index

Constants

View Source
const (
	CheckMark   = "\u2713" // ✓
	XMark       = "\u2717" // ✗
	WarningMark = "\u26A0" // ⚠
	InfoMark    = "\u2139" // ℹ
)

Status symbols

Variables

This section is empty.

Functions

This section is empty.

Types

type Spinner

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

Spinner wraps briandowns/spinner with graceful fallback.

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner animation.

func (*Spinner) StopWithFailure

func (s *Spinner) StopWithFailure(message string)

StopWithFailure stops spinner and shows failure message.

func (*Spinner) StopWithSuccess

func (s *Spinner) StopWithSuccess(message string)

StopWithSuccess stops spinner and shows success message.

func (*Spinner) StopWithWarning

func (s *Spinner) StopWithWarning(message string)

StopWithWarning stops spinner and shows warning message.

func (*Spinner) UpdateMessage

func (s *Spinner) UpdateMessage(message string)

UpdateMessage changes the spinner message.

type Writer

type Writer struct {
	Out     io.Writer
	Err     io.Writer
	JSON    bool
	Quiet   bool
	Verbose bool
	NoInput bool
	// contains filtered or unexported fields
}

Writer handles CLI output with multiple modes.

func Default

func Default() *Writer

Default returns a Writer configured for stdout/stderr.

func FromContext

func FromContext(ctx context.Context) *Writer

FromContext retrieves the Writer from context, or returns Default().

func NewWriter

func NewWriter(out, err io.Writer, term *terminal.Info) *Writer

NewWriter creates a Writer with custom writers and terminal info.

func (*Writer) Debug

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

Debug writes to stdout only in verbose mode.

func (*Writer) Error

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

Error writes to stderr.

func (*Writer) Errorln

func (w *Writer) Errorln(args ...interface{})

Errorln writes a line to stderr.

func (*Writer) Failure

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

Failure writes an error message with an X mark.

func (*Writer) Info

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

Info writes an info message.

func (*Writer) Muted

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

Muted writes muted/gray text.

func (*Writer) Print

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

Print writes to stdout (respects quiet mode).

func (*Writer) PrintJSON

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

PrintJSON outputs structured data as JSON.

func (*Writer) Println

func (w *Writer) Println(args ...interface{})

Println writes a line to stdout (respects quiet mode).

func (*Writer) SetNoColor

func (w *Writer) SetNoColor(disabled bool)

SetNoColor disables colored output.

func (*Writer) Spinner

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

Spinner creates a new spinner for long operations. Returns nil if spinners are disabled (non-TTY or quiet mode).

func (*Writer) Success

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

Success writes a success message with a checkmark.

func (*Writer) Terminal

func (w *Writer) Terminal() *terminal.Info

Terminal returns the terminal info.

func (*Writer) Warning

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

Warning writes a warning message.

func (*Writer) WithContext

func (w *Writer) WithContext(ctx context.Context) context.Context

WithContext stores the Writer in the context.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write implements io.Writer, writing to Out.

Jump to

Keyboard shortcuts

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