output

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bold

func Bold(s string) string

func Dim

func Dim(s string) string

func EscapePlainField added in v0.3.0

func EscapePlainField(value string) string

EscapePlainField escapes control characters in value so it can be rendered safely on a single line. Used by both --plain output and the styled --dry-run preview so an embedded newline does not break the layout.

func Green

func Green(s string) string

func ImageEnabled

func ImageEnabled() bool

ImageEnabled returns whether image rendering is enabled (follows color gate).

func IsBrokenPipeError

func IsBrokenPipeError(err error) bool

IsBrokenPipeError reports whether err represents a closed downstream pipe.

func IsTTY

func IsTTY() bool

func PrintJSON

func PrintJSON(w io.Writer, data json.RawMessage, jqExpr string) error

func PrintJSONStream

func PrintJSONStream(w io.Writer, key string, writeItems func(func(any) error) error) error

PrintJSONStream keeps the same atomic-output contract as PrintJSONStreamWithJQ for user-visible `--all --json` flows.

func PrintJSONStreamWithJQ

func PrintJSONStreamWithJQ(w io.Writer, key, jqExpr string, writeItems func(func(any) error) error) error

PrintJSONStreamWithJQ stages user-visible output before copying it to the final writer. This is intentional: `gumroad ... --all --jq ...` must fail atomically so late pagination/jq errors never leave partial machine-readable output on stdout. Do not switch this back to direct stdout streaming unless the CLI contract changes.

func PrintPlain

func PrintPlain(w io.Writer, rows [][]string) error

func Red

func Red(s string) string

func RenderImage

func RenderImage(w io.Writer, imageURL string, maxWidth int)

RenderImage downloads an image from imageURL and writes ANSI half-block pixel art to w, fitting within maxWidth terminal columns. Silent no-op on any failure — this is purely decorative.

func RenderImageWithContext

func RenderImageWithContext(ctx context.Context, w io.Writer, imageURL string, maxWidth int)

RenderImageWithContext downloads an image from imageURL and writes ANSI half-block pixel art to w, fitting within maxWidth terminal columns. Silent no-op on any failure — this is purely decorative.

func ResetColorEnabledForTesting

func ResetColorEnabledForTesting()

ResetColorEnabledForTesting clears the test-only color override.

func ResetStdoutIsTerminalForTesting

func ResetStdoutIsTerminalForTesting()

ResetStdoutIsTerminalForTesting restores default stdout TTY detection.

func SetColorEnabledForTesting

func SetColorEnabledForTesting(enabled bool)

SetColorEnabledForTesting forces color on or off regardless of runtime writer and terminal detection. This is a testing seam.

func SetStdoutIsTerminalForTesting

func SetStdoutIsTerminalForTesting(enabled bool)

SetStdoutIsTerminalForTesting overrides stdout TTY detection for tests.

func StreamJSONArrayEnvelope

func StreamJSONArrayEnvelope(w io.Writer, key string, writeItems func(func(any) error) error) error

func TerminalWidth

func TerminalWidth(defaultWidth int) int

TerminalWidth returns the terminal width or defaultWidth if detection fails.

func TerminalWidthFor

func TerminalWidthFor(w io.Writer, defaultWidth int) int

TerminalWidthFor returns the terminal width for the supplied writer when backed by a TTY file descriptor, or defaultWidth if detection fails.

func WithPager

func WithPager(stdout, stderr io.Writer, fn func(io.Writer) error) error

func WriteJSONStreamTo

func WriteJSONStreamTo(w io.Writer, key string, writeItems func(func(any) error) error) error

WriteJSONStreamTo writes a JSON envelope directly to w without staging. Prefer PrintJSONStream for user-facing command output; this helper stays raw for internal composition and focused unit tests.

func Writef

func Writef(w io.Writer, format string, args ...any) error

func Writeln

func Writeln(w io.Writer, args ...any) error

func Yellow

func Yellow(s string) string

Types

type Pager

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

Pager wraps output through a system pager (e.g. less) when stdout is an interactive terminal. Falls back to direct stdout otherwise. Callers must Close the pager to wait for the process to finish.

func NewPager

func NewPager() *Pager

NewPager starts a pager process if stdout is an interactive TTY with a capable terminal. Returns a passthrough to os.Stdout otherwise.

func NewPagerTo

func NewPagerTo(stdout, stderr io.Writer) *Pager

NewPagerTo writes to the supplied stdout writer and only spawns a system pager when that writer is a terminal-backed file.

func (*Pager) Close

func (p *Pager) Close() error

func (*Pager) Write

func (p *Pager) Write(b []byte) (int, error)

type Spinner

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

func NewSpinner

func NewSpinner(message string) *Spinner

func NewSpinnerTo

func NewSpinnerTo(message string, w io.Writer) *Spinner

func (*Spinner) SetMessage added in v0.2.0

func (s *Spinner) SetMessage(message string)

SetMessage replaces the spinner label. It is safe to call from any goroutine and takes effect on the next animation tick. Calls before Start or after Stop are accepted but nothing is rendered.

func (*Spinner) Start

func (s *Spinner) Start()

func (*Spinner) Stop

func (s *Spinner) Stop()

type Styler

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

func NewStyler

func NewStyler(noColor bool) Styler

func NewStylerForWriter

func NewStylerForWriter(w io.Writer, noColor bool) Styler

func (Styler) Bold

func (s Styler) Bold(value string) string

func (Styler) Dim

func (s Styler) Dim(value string) string

func (Styler) Enabled

func (s Styler) Enabled() bool

func (Styler) Green

func (s Styler) Green(value string) string

func (Styler) Red

func (s Styler) Red(value string) string

func (Styler) Yellow

func (s Styler) Yellow(value string) string

type Table

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

func NewStyledTable

func NewStyledTable(styler Styler, headers ...string) *Table

NewStyledTable binds a command-scoped styler up front. Command handlers should prefer this constructor so explicit flags like --no-color propagate consistently instead of falling back to writer auto-detection.

func NewTable

func NewTable(headers ...string) *Table

func (*Table) AddRow

func (t *Table) AddRow(values ...string)

func (*Table) Render

func (t *Table) Render(w io.Writer) error

func (*Table) SetStyler

func (t *Table) SetStyler(styler Styler)

SetStyler overrides the table's header styling. Command handlers should pass opts.Style() here (or use NewStyledTable) so explicit output flags keep working even when stdout still looks like a capable terminal.

Jump to

Keyboard shortcuts

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