print

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 10 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(T) string) func(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(obj interface{}) string
}

Column defines a column in a table.

func (Column) Format

func (c Column) Format(obj interface{}) Cell

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

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, 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.
}

type StatusPrinter

type StatusPrinter interface {
	PrintStatuses(statuses []status.ObjectStatus) int
	PrintError(err error) int
	Printf(raw string, args ...interface{})
}

StatusPrinter is an interface for printing status updates.

type TablePrinter

type TablePrinter struct {
	IOStreams genericclioptions.IOStreams
	PrintOpts PrintOptions
}

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

func NewTablePrinter

func NewTablePrinter(ioStreams genericclioptions.IOStreams, opts PrintOptions) *TablePrinter

func (*TablePrinter) PrintError

func (t *TablePrinter) PrintError(err error) int

func (*TablePrinter) PrintStatuses

func (t *TablePrinter) PrintStatuses(objects []status.ObjectStatus) int

func (*TablePrinter) Printf

func (t *TablePrinter) Printf(format string, a ...interface{})

Jump to

Keyboard shortcuts

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