printer

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package printer provides a printer abstraction for human readable output.

Index

Constants

This section is empty.

Variables

View Source
var ConsolePrinter = New(os.Stdout)

Functions

func FatalError

func FatalError(err error)

func GetWriter

func GetWriter(ctx context.Context) (io.Writer, bool)

GetWriter returns the writer from the context, or the fallback if provided

func KeyValueValidationError

func KeyValueValidationError(title string, errors []KeyValueError)

func LineBreak

func LineBreak()

func List

func List(title string, items []string)

func ListTree

func ListTree(title string, list []Tree)

func StatusList

func StatusList(title string, items []StatusListItem)

func Title

func Title(title string)

func WithWriter

func WithWriter(ctx context.Context, writer io.Writer) context.Context

WithWriter sets the writer to be used within the context of the printer function.

Types

type ConsoleOutput

type ConsoleOutput interface {
	ConsoleOutput() string
}

type DeferredWriter

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

func NewDeferedWriter

func NewDeferedWriter(w io.Writer) *DeferredWriter

func (*DeferredWriter) Flush

func (dw *DeferredWriter) Flush() error

func (*DeferredWriter) Write

func (dw *DeferredWriter) Write(bytes []byte) (int, error)

type KeyValueError

type KeyValueError struct {
	Key     string
	Message string
}

type Printer

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

func Ctx

func Ctx(ctx context.Context) *Printer

func New

func New(writer io.Writer) *Printer

func WithBase

func WithBase(style styles.RenderFunc) *Printer

func WithLight

func WithLight(style styles.RenderFunc) *Printer

func (*Printer) Ctx

func (c *Printer) Ctx(ctx context.Context) *Printer

func (*Printer) FatalError

func (c *Printer) FatalError(err error)

FatalError printer an error message for an unknown or unexpected error. This is used when an error in the system was unexpected, and the error output should be displayed to the user.

If the error implements the ConsoleOutput interface, the ConsoleOutput method will be called to get the error output.

func (*Printer) KeyValueValidationError

func (c *Printer) KeyValueValidationError(title string, errors []KeyValueError)

func (*Printer) LineBreak

func (c *Printer) LineBreak()

func (*Printer) List

func (c *Printer) List(title string, items []string)

List prints a list of items with a title.

Example:

Some Title
  - Item 1
  - Item 2
  - Item 3

func (*Printer) ListTree

func (c *Printer) ListTree(title string, list []Tree)

func (*Printer) StatusList

func (c *Printer) StatusList(title string, items []StatusListItem)

StatusList prints a list of status items with a title.

Example:

Some Title
 ✔ Status 1
 ✘ Status 2
 ✔ Status 3

func (*Printer) Title

func (c *Printer) Title(title string)

func (*Printer) WithBase

func (c *Printer) WithBase(style styles.RenderFunc) *Printer

func (*Printer) WithLight

func (c *Printer) WithLight(style styles.RenderFunc) *Printer

type StatusListItem

type StatusListItem struct {
	Ok     bool
	Status string
}

type Tree

type Tree struct {
	Text     string
	Children []Tree
}

Jump to

Keyboard shortcuts

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