printer

package
v0.17.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MPL-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package printer defines funtionality for "printing" text to an io.Writer e.g. os.Stdout, os.Stderr etc. with a consistent style for errors, warnings, information etc.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// Stderr is the default stderr printer
	Stderr = NewPrinter(os.Stderr)
	// Stdout is the default stdout printer
	Stdout = NewPrinter(os.Stdout)

	// DefaultPrinters groups the default stdout and stderr printers.
	DefaultPrinters = Printers{
		Stdout: Stdout,
		Stderr: Stderr,
	}
)

Functions

This section is empty.

Types

type Printer

type Printer struct {
	io.Writer
}

Printer encapsulates an io.Writer

func NewPrinter

func NewPrinter(w io.Writer) *Printer

NewPrinter creates a new Printer with the provider io.Writer e.g.: stdio, stderr, file etc.

Example
p := NewPrinter(os.Stdout)
p.Println("Doing something")
p.Warn("doing something fishy")
p.ErrorWithDetails(
	"failed to find fish",
	stderrors.New("error 1"),
)
Output:
Doing something
Warning: doing something fishy
Error: failed to find fish
> error 1

func (*Printer) Error added in v0.4.5

func (p *Printer) Error(arg any)

Error prints a message with a "Error:" prefix. The prefix is printed in the boldRed style.

func (*Printer) ErrorWithDetails added in v0.4.5

func (p *Printer) ErrorWithDetails(title string, err error)

ErrorWithDetails prints an error with a title and the underlying error. If the error contains multiple error items, each error is printed with a `->` prefix. e.g.: Error: parsing failed -> somefile.tm:8,3-7: terramate schema error: unrecognized attribute -> somefile.tm:9,4-7: terramate schema error: unrecognized block

func (*Printer) Errorf added in v0.6.1

func (p *Printer) Errorf(format string, a ...any)

Errorf is short for Error(fmt.Sprintf(...)).

func (*Printer) Fatal added in v0.5.0

func (p *Printer) Fatal(err any)

Fatal prints an error and calls os.Exit(1).

func (*Printer) FatalWithDetails added in v0.6.1

func (p *Printer) FatalWithDetails(title string, err error)

FatalWithDetails prints an error with a title and the underlying error and calls os.Exit(1).

func (*Printer) Fatalf added in v0.6.1

func (p *Printer) Fatalf(format string, a ...any)

Fatalf is short for Fatal(fmt.Sprintf(...)).

func (*Printer) Printf added in v0.13.1

func (p *Printer) Printf(format string, a ...any)

Printf prints a formatted message to the io.Writer

func (*Printer) Println

func (p *Printer) Println(msg string)

Println prints a message to the io.Writer

func (*Printer) Success added in v0.4.5

func (p *Printer) Success(msg string)

Success prints a message in the boldGreen style

func (*Printer) Successf added in v0.6.1

func (p *Printer) Successf(format string, a ...any)

Successf is short for Success(fmt.Sprintf(...)).

func (*Printer) Warn added in v0.4.5

func (p *Printer) Warn(arg any)

Warn prints a message with a "Warning:" prefix. The prefix is printed in the boldYellow style.

func (*Printer) WarnWithDetails added in v0.4.5

func (p *Printer) WarnWithDetails(title string, err error)

WarnWithDetails is similar to ErrorWithDetailsln but prints a warning instead

func (*Printer) Warnf added in v0.6.1

func (p *Printer) Warnf(format string, a ...any)

Warnf is short for Warn(fmt.Sprintf(...)).

type Printers added in v0.13.1

type Printers struct {
	Stdout *Printer
	Stderr *Printer
}

Printers groups stdout and stderr printers.

Jump to

Keyboard shortcuts

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