output

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OsPrinter = stdPrinter{OsInOut{}} //nolint:gochecknoglobals

OsPrinter is the default printer for the CLI. It uses the standard input, output, and error streams.

Functions

func IsReaderTerminal

func IsReaderTerminal(r io.Reader) bool

IsReaderTerminal returns true if the given reader is a real terminal.

func IsWriterTerminal

func IsWriterTerminal(w io.Writer) bool

IsWriterTerminal returns true if the given writer is a real terminal.

func WithContext

func WithContext(ctx context.Context, p Printer) context.Context

WithContext returns a new context with the given Printer set.

Types

type Contextual added in v0.2.0

type Contextual interface {
	// Context returns the context.Context.
	Context() context.Context
}

Contextual is an interface for types that can provide a context.Context.

type ContextualPrinter added in v0.2.0

type ContextualPrinter struct {
	Contextual
	Printer
}

ContextualPrinter is a type that embeds a Contextual and a Printer.

type InputOutput

type InputOutput interface {
	InOrStdin() io.Reader
	OutOrStdout() io.Writer
	ErrOrStderr() io.Writer
}

InputOutput is an interface for types that can provide input and output and error streams. It is compatible with Cobra functions, so that the cobra.Command can be passed an InputOutput implementation.

type OsInOut

type OsInOut struct{}

OsInOut is an InputOutput implementation that uses the standard input, output, and error streams.

func (OsInOut) ErrOrStderr

func (o OsInOut) ErrOrStderr() io.Writer

func (OsInOut) InOrStdin

func (o OsInOut) InOrStdin() io.Reader

func (OsInOut) OutOrStdout

func (o OsInOut) OutOrStdout() io.Writer

type Printer

type Printer interface {
	Print(i ...any)
	Println(i ...any)
	Printf(format string, i ...any)

	PrintErr(i ...any)
	PrintErrln(i ...any)
	PrintErrf(format string, i ...any)

	InputOutput
}

func PrinterFrom

func PrinterFrom(ctx context.Context) Printer

PrinterFrom returns the Printer from the context, or the default printer if none is set. The default printer is OsPrinter.

type TestOutputs

type TestOutputs struct {
	Out, Err *bytes.Buffer
}

TestOutputs is a struct that contains the output and error buffers.

func (TestOutputs) ErrOrStderr

func (t TestOutputs) ErrOrStderr() io.Writer

ErrOrStderr returns the error stream.

func (TestOutputs) OutOrStdout

func (t TestOutputs) OutOrStdout() io.Writer

OutOrStdout returns the output stream.

type TestPrinter

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

TestPrinter is an InputOutput implementation that uses a buffer for input.

func NewTestPrinter

func NewTestPrinter() TestPrinter

NewTestPrinter returns a TestPrinter with a buffer for input.

func NewTestPrinterWithAnswers

func NewTestPrinterWithAnswers(answers []string) TestPrinter

NewTestPrinterWithAnswers returns a TestPrinter with the given answers as input.

func NewTestPrinterWithInput

func NewTestPrinterWithInput(input io.Reader) TestPrinter

NewTestPrinterWithInput returns a TestPrinter with the given input.

func (TestPrinter) Outputs

func (p TestPrinter) Outputs() TestOutputs

func (TestPrinter) Print

func (p TestPrinter) Print(i ...any)

func (TestPrinter) PrintErr

func (p TestPrinter) PrintErr(i ...any)

func (TestPrinter) PrintErrf

func (p TestPrinter) PrintErrf(format string, i ...any)

func (TestPrinter) PrintErrln

func (p TestPrinter) PrintErrln(i ...any)

func (TestPrinter) Printf

func (p TestPrinter) Printf(format string, i ...any)

func (TestPrinter) Println

func (p TestPrinter) Println(i ...any)

Jump to

Keyboard shortcuts

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