Documentation
¶
Index ¶
- type ColorScheme
- func (cs *ColorScheme) Bold(s string) string
- func (cs *ColorScheme) Cyan(s string) string
- func (cs *ColorScheme) FailureIcon() string
- func (cs *ColorScheme) Green(s string) string
- func (cs *ColorScheme) Magenta(s string) string
- func (cs *ColorScheme) Muted(s string) string
- func (cs *ColorScheme) Red(s string) string
- func (cs *ColorScheme) SuccessIcon() string
- func (cs *ColorScheme) SuccessIconWithColor(msg string) string
- func (cs *ColorScheme) WarningIcon() string
- func (cs *ColorScheme) Yellow(s string) string
- type IOStreams
- func (s *IOStreams) ColorEnabled() bool
- func (s *IOStreams) ColorScheme() *ColorScheme
- func (s *IOStreams) ConfirmAction(prompt string) (bool, error)
- func (s *IOStreams) IsStderrTTY() bool
- func (s *IOStreams) IsStdinTTY() bool
- func (s *IOStreams) IsStdoutTTY() bool
- func (s *IOStreams) NewTablePrinter() *TablePrinter
- func (s *IOStreams) OpenInBrowser(url string) error
- func (s *IOStreams) StartPager() error
- func (s *IOStreams) StartSpinner(label string)
- func (s *IOStreams) StopPager()
- func (s *IOStreams) StopSpinner()
- func (s *IOStreams) TerminalWidth() int
- type TablePrinter
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) 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) 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 ¶
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 ¶
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 ¶
IsStderrTTY reports whether standard error is connected to a terminal.
func (*IOStreams) IsStdinTTY ¶
IsStdinTTY reports whether standard input is connected to a terminal.
func (*IOStreams) IsStdoutTTY ¶
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 ¶
OpenInBrowser opens the given URL in the user's default browser.
func (*IOStreams) StartPager ¶
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 ¶
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 ¶
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.