print

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RESET is the escape sequence for unsetting any previous commands.
	RESET = 0
	// ESC is the escape sequence used to send ANSI commands in the terminal.
	ESC = 27
)

Variables

This section is empty.

Functions

func FormatFn

func FormatFn[T any](formatFn func(PrintOptions, T) string) func(PrintOptions, interface{}) string

FormatFn is a wrapper of a function of specific type to a function of interface{}. It acts as an adapter to allow using the function with the Column.FormatFn.

func SprintfWithColor

func SprintfWithColor(color Color, format string, a ...interface{}) string

SprintfWithColor formats according to the provided pattern and returns the result as a string with the necessary ansii escape codes for color

Types

type Cell

type Cell struct {
	Column  Column
	Content string
}

Cell is a single cell in a table in a specific column.

type Color

type Color int

color is a type that captures the ANSI code for colors on the terminal.

var (
	RED    Color = 31
	GREEN  Color = 32
	YELLOW Color = 33
)

type Column

type Column struct {
	Header      string
	Width       int
	MaxLineWrap int // Maximum number of lines to wrap the content to.
	WrapPrefix  string
	FormatFn    func(o PrintOptions, obj interface{}) string
}

Column defines a column in a table.

func (Column) Format

func (c Column) Format(o PrintOptions, obj interface{}) Cell

Format turns the object into a string for the Cell using the FormatFn.

type KubectlPrinter added in v0.3.0

type KubectlPrinter struct {
	Printer printers.ResourcePrinter
}

func (KubectlPrinter) PrintStatuses added in v0.3.0

func (p KubectlPrinter) PrintStatuses(statuses []status.ObjectStatus, w io.Writer)

type OutStreams added in v0.3.0

type OutStreams struct {
	Std io.Writer
	Err io.Writer
}

type PeriodicPrinter

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

PeriodicPrinter prints status updates to the terminal, as they arrive to the update channel. It tracks the number of lines printed and clears the screen before printing the next update.

func NewPeriodicPrinter

func NewPeriodicPrinter(printer StatusPrinter, out OutStreams, updateChan <-chan eval.StatusUpdate,
	callback func([]status.ObjectStatus)) *PeriodicPrinter

func (*PeriodicPrinter) Start

func (p *PeriodicPrinter) Start()

type PrintOptions

type PrintOptions struct {
	ShowGroup bool // By default, group names are not shown.
	ShowOk    bool // By default, OK statuses are not shown.
	Width     int  // Width of the output. If 0, wrapping is disabled.
	Color     bool // Use colors to indicate the health.
}

type StatusPrinter

type StatusPrinter interface {
	PrintStatuses(statuses []status.ObjectStatus, w io.Writer)
}

StatusPrinter is an interface for printing status updates.

type TreePrinter added in v0.3.0

type TreePrinter struct {
	PrintOpts PrintOptions
}

TreePrinter implements StatusPrinter interface for printing the status of resources in a tabular format.

func NewTreePrinter added in v0.3.0

func NewTreePrinter(opts PrintOptions) *TreePrinter

func (*TreePrinter) PrintStatuses added in v0.3.0

func (t *TreePrinter) PrintStatuses(objects []status.ObjectStatus, w io.Writer)

Jump to

Keyboard shortcuts

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