iostreams

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionWidth = 10
)

Variables

This section is empty.

Functions

func EnvColorDisabled

func EnvColorDisabled() bool

func EnvColorForced

func EnvColorForced() bool

func IsTerminal

func IsTerminal(stream IOStream) bool

IsTerminal returns true if the stream is a terminal.

Types

type ActionLogger

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

ActionLogger logs formatted Task actions.

func NewActionLogger

func NewActionLogger(ios *IOStreams, dryRun bool) *ActionLogger

NewActionLogger returns a new ActionLogger.

func (*ActionLogger) Failure

func (l *ActionLogger) Failure(action string, line string, args ...any)

Failure logs a line to os.StdErr prefixed with a failure icon and action label.

Example:

// Prints "✖ [    action]: hello, world\n"
Failure("action", "hello, %s", "world")

func (*ActionLogger) Info

func (l *ActionLogger) Info(action string, line string, args ...any)

Info logs a line to os.StdErr prefixed with an info icon and action label.

Example:

// Prints "• [    action]: hello, world\n"
Info("action", "hello, %s", "world")

func (*ActionLogger) Success

func (l *ActionLogger) Success(action string, line string, args ...any)

Success logs a line to os.StdErr prefixed with a success icon and action label.

Example:

// Prints "✓ [    action]: hello, world\n"
Success("action", "hello, %s", "world")

func (*ActionLogger) Warning

func (l *ActionLogger) Warning(action string, line string, args ...any)

Warning logs a line to os.StdErr prefixed with a warning icon and action label.

Example:

// Prints "! [    action]: hello, world\n"
Warning("action", "hello, %s", "world")

type ColorFunc

type ColorFunc func(string) string

type Formatter

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

Formatter wraps strings in ANSI escape sequences.

func NewFormatter

func NewFormatter(enabled bool) *Formatter

func (*Formatter) Blue

func (f *Formatter) Blue(t string) string

func (*Formatter) Bluef

func (f *Formatter) Bluef(t string, args ...interface{}) string

func (*Formatter) Bold

func (f *Formatter) Bold(t string) string

func (*Formatter) Boldf

func (f *Formatter) Boldf(t string, args ...interface{}) string

func (*Formatter) ColorFromString

func (f *Formatter) ColorFromString(s string) ColorFunc

func (*Formatter) Cyan

func (f *Formatter) Cyan(t string) string

func (*Formatter) Cyanf

func (f *Formatter) Cyanf(t string, args ...interface{}) string

func (*Formatter) Failure

func (f *Formatter) Failure(t string) string

func (*Formatter) FailureIcon

func (f *Formatter) FailureIcon() string

func (*Formatter) Gray

func (f *Formatter) Gray(t string) string

func (*Formatter) Grayf

func (f *Formatter) Grayf(t string, args ...interface{}) string

func (*Formatter) Green

func (f *Formatter) Green(t string) string

func (*Formatter) Greenf

func (f *Formatter) Greenf(t string, args ...interface{}) string

func (*Formatter) Info

func (f *Formatter) Info(t string) string

func (*Formatter) InfoIcon

func (f *Formatter) InfoIcon() string

func (*Formatter) Magenta

func (f *Formatter) Magenta(t string) string

func (*Formatter) Magentaf

func (f *Formatter) Magentaf(t string, args ...interface{}) string

func (*Formatter) Red

func (f *Formatter) Red(t string) string

func (*Formatter) Redf

func (f *Formatter) Redf(t string, args ...interface{}) string

func (*Formatter) Success

func (f *Formatter) Success(t string) string

func (*Formatter) SuccessIcon

func (f *Formatter) SuccessIcon() string

func (*Formatter) Warning

func (f *Formatter) Warning(t string) string

func (*Formatter) WarningIcon

func (f *Formatter) WarningIcon() string

func (*Formatter) Yellow

func (f *Formatter) Yellow(t string) string

func (*Formatter) Yellowf

func (f *Formatter) Yellowf(t string, args ...interface{}) string

type IOStream

type IOStream interface {
	io.Reader
	io.Writer
	Fd() uintptr
	String() string
}

IOStream represents an input or output stream.

type IOStreams

type IOStreams struct {
	// os.Stdin (or mock when unit testing)
	In IOStream
	// os.Stdout (or mock when unit testing)
	Out IOStream
	// os.Stderr (or mock when unit testing)
	Err IOStream
	// contains filtered or unexported fields
}

Container for the three main CLI I/O streams.

func System

func System() *IOStreams

Returns an IOStreams containing os.Stdin, os.Stdout, and os.Stderr.

func Test

func Test() *IOStreams

Returns an IOStreams with mock in/out/err values.

func (*IOStreams) Formatter

func (s *IOStreams) Formatter() *Formatter

Formatter returns a ANSI string formatter.

func (*IOStreams) IsColorEnabled

func (s *IOStreams) IsColorEnabled() bool

IsColorEnabled returns true if color output is enabled.

func (*IOStreams) IsInteractive

func (s *IOStreams) IsInteractive() bool

IsInteractive returns true if running interactively. Will be false if either (a) std in/out is not a TTY, or (b) the user has explicitly requested not to be prompted.

func (*IOStreams) IsStderrTTY

func (s *IOStreams) IsStderrTTY() bool

IsStderrTTY returns true if [IOStreams.Err] is a TTY.

func (*IOStreams) IsStdinTTY

func (s *IOStreams) IsStdinTTY() bool

IsStdinTTY returns true if [IOStreams.In] is a TTY.

func (*IOStreams) IsStdoutTTY

func (s *IOStreams) IsStdoutTTY() bool

IsStdoutTTY returns true if [IOStreams.Out] is a TTY.

func (*IOStreams) ProgressIndicatorEnabled

func (s *IOStreams) ProgressIndicatorEnabled() bool

ProgressIndicatorEnabled returns true if the progress indicator is enabled.

func (*IOStreams) SetColorEnabled

func (s *IOStreams) SetColorEnabled(v bool)

SetColorEnabled sets whether color is enabled.

func (*IOStreams) SetInteractive

func (s *IOStreams) SetInteractive(v bool)

SetInteractive explicitly sets whether this is an interactive session.

func (*IOStreams) SetProgressIndicatorEnabled

func (s *IOStreams) SetProgressIndicatorEnabled(v bool)

SetProgressIndicatorEnabled sets whether the progress indicator is enabled.

func (*IOStreams) SetStderrTTY

func (s *IOStreams) SetStderrTTY(isTTY bool)

SetStderrTTY explicitly flags [IOStreams.Err] as a TTY.

func (*IOStreams) SetStdinTTY

func (s *IOStreams) SetStdinTTY(isTTY bool)

SetStdinTTY explicitly flags [IOStreams.In] as a TTY.

func (*IOStreams) SetStdoutTTY

func (s *IOStreams) SetStdoutTTY(isTTY bool)

SetStdoutTTY explicitly flags [IOStreams.Out] as a TTY.

func (*IOStreams) StartProgressIndicator

func (s *IOStreams) StartProgressIndicator()

func (*IOStreams) StartProgressIndicatorWithLabel

func (s *IOStreams) StartProgressIndicatorWithLabel(label string)

func (*IOStreams) StopProgressIndicator

func (s *IOStreams) StopProgressIndicator()

type IconLogger

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

IconLogger is a generic logger that prefixes lines with status icons.

func NewIconLogger

func NewIconLogger(ios *IOStreams) *IconLogger

NewIconLogger returns a new IconLogger.

func (*IconLogger) Failure

func (l *IconLogger) Failure(line string, args ...any)

func (*IconLogger) Info

func (l *IconLogger) Info(line string, args ...any)

func (*IconLogger) Success

func (l *IconLogger) Success(line string, args ...any)

func (*IconLogger) Warning

func (l *IconLogger) Warning(line string, args ...any)

Jump to

Keyboard shortcuts

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