iostreams

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorScheme

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

ColorScheme provides semantic color methods that respect whether color output is enabled.

func NewColorScheme

func NewColorScheme(enabled bool) *ColorScheme

NewColorScheme creates a ColorScheme. When enabled is false, all methods return undecorated text.

func (*ColorScheme) Bold

func (cs *ColorScheme) Bold(s string) string

Bold renders text in bold.

func (*ColorScheme) Cyan

func (cs *ColorScheme) Cyan(s string) string

Cyan renders text in cyan.

func (*ColorScheme) FailureIcon

func (cs *ColorScheme) FailureIcon() string

FailureIcon returns a red X mark if color is enabled, plain otherwise.

func (*ColorScheme) Green

func (cs *ColorScheme) Green(s string) string

Green renders text in green.

func (*ColorScheme) Magenta

func (cs *ColorScheme) Magenta(s string) string

Magenta renders text in magenta.

func (*ColorScheme) Muted

func (cs *ColorScheme) Muted(s string) string

Muted renders text in gray (dimmed).

func (*ColorScheme) Red

func (cs *ColorScheme) Red(s string) string

Red renders text in red.

func (*ColorScheme) SuccessIcon

func (cs *ColorScheme) SuccessIcon() string

SuccessIcon returns a green check mark if color is enabled, plain otherwise.

func (*ColorScheme) SuccessIconWithColor

func (cs *ColorScheme) SuccessIconWithColor(msg string) string

SuccessIconWithColor returns the success icon followed by the message in green.

func (*ColorScheme) WarningIcon

func (cs *ColorScheme) WarningIcon() string

WarningIcon returns a yellow exclamation mark if color is enabled, plain otherwise.

func (*ColorScheme) Yellow

func (cs *ColorScheme) Yellow(s string) string

Yellow renders text in yellow.

type IOStreams

type IOStreams struct {
	In     io.Reader
	Out    io.Writer
	ErrOut io.Writer
	// contains filtered or unexported fields
}

IOStreams provides the standard streams for the CLI along with TTY detection, color support, pager integration, and other terminal helpers.

func New

func New() *IOStreams

New creates an IOStreams wired to the real os.Stdin, os.Stdout, and os.Stderr, with TTY status auto-detected. Setting FJ_FORCE_TTY=1 (or legacy FGJ_FORCE_TTY=1) forces all streams to be treated as TTYs.

func Test

func Test() *IOStreams

Test creates an IOStreams backed by bytes.Buffers, suitable for unit tests. All TTY flags are false.

func (*IOStreams) ColorEnabled

func (s *IOStreams) ColorEnabled() bool

ColorEnabled returns true when color output should be used. Color is enabled when stdout is a TTY and the NO_COLOR environment variable is not set.

func (*IOStreams) ColorScheme

func (s *IOStreams) ColorScheme() *ColorScheme

ColorScheme returns a lazily-initialized ColorScheme that respects the current color settings.

func (*IOStreams) ConfirmAction

func (s *IOStreams) ConfirmAction(prompt string) (bool, error)

ConfirmAction prompts the user with a yes/no question and returns their answer. It returns an error if stdin is not a TTY (non-interactive).

func (*IOStreams) IsStderrTTY

func (s *IOStreams) IsStderrTTY() bool

IsStderrTTY reports whether standard error is connected to a terminal.

func (*IOStreams) IsStdinTTY

func (s *IOStreams) IsStdinTTY() bool

IsStdinTTY reports whether standard input is connected to a terminal.

func (*IOStreams) IsStdoutTTY

func (s *IOStreams) IsStdoutTTY() bool

IsStdoutTTY reports whether standard output is connected to a terminal.

func (*IOStreams) NewTablePrinter

func (s *IOStreams) NewTablePrinter() *TablePrinter

NewTablePrinter creates a TablePrinter that writes to this IOStreams' output.

func (*IOStreams) OpenInBrowser

func (s *IOStreams) OpenInBrowser(url string) error

OpenInBrowser opens the given URL in the user's default browser.

func (*IOStreams) StartPager

func (s *IOStreams) StartPager() error

StartPager starts an external pager process and redirects Out to its stdin. It checks FJ_PAGER (or legacy FGJ_PAGER), then PAGER, then defaults to "less". If LESS is not already set, it is set to "FRX" for a good default experience.

func (*IOStreams) StartSpinner

func (s *IOStreams) StartSpinner(label string)

StartSpinner shows an animated spinner with the given label on stderr. It only runs when stderr is a TTY. Call StopSpinner to halt it.

func (*IOStreams) StopPager

func (s *IOStreams) StopPager()

StopPager closes the pager's stdin pipe and waits for the process to exit. It restores Out to the original writer.

func (*IOStreams) StopSpinner

func (s *IOStreams) StopSpinner()

StopSpinner halts the spinner and clears the line on stderr.

func (*IOStreams) TerminalWidth

func (s *IOStreams) TerminalWidth() int

TerminalWidth returns the width of the terminal connected to stdout. If stdout is not a terminal, it returns 80.

type TablePrinter

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

TablePrinter prints TTY-aware tables. In TTY mode it uses aligned columns with bold headers. In pipe mode it emits tab-separated values without headers.

func NewTablePrinter

func NewTablePrinter(ios *IOStreams) *TablePrinter

NewTablePrinter creates a TablePrinter that writes to ios.Out.

func (*TablePrinter) AddHeader

func (t *TablePrinter) AddHeader(headers ...string)

AddHeader sets the column headers. Headers are only displayed in TTY mode.

func (*TablePrinter) AddRow

func (t *TablePrinter) AddRow(fields ...string)

AddRow appends a row of fields to the table.

func (*TablePrinter) Render

func (t *TablePrinter) Render() error

Render writes the table to the IOStreams output. In TTY mode it uses tabwriter with bold headers. In pipe mode it emits tab-separated values without headers.

Jump to

Keyboard shortcuts

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