output

package
v1.7.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	IsColorEnabled = os.Getenv("NO_COLOR") == "" && term.IsTerminal(int(os.Stdout.Fd()))
)

Functions

func Blue

func Blue(s string) string

func Bluef

func Bluef(s string, args ...interface{}) string

func Bold

func Bold(s string) string

func Boldf

func Boldf(s string, args ...interface{}) string

func Cyan

func Cyan(s string) string

func Cyanf

func Cyanf(s string, args ...interface{}) string

func Dim

func Dim(s string) string

func Dimf

func Dimf(s string, args ...interface{}) string

func FormatAsList added in v0.7.0

func FormatAsList(items []string) string

func FormatDoc added in v0.2.1

func FormatDoc(str string) string

FormatDoc is designed to take a large block of heredoc text and replace formatting elements within it. Like a really cheap basic version of Markdown

func Green

func Green(s string) string

func Greenf

func Greenf(s string, args ...interface{}) string

func Magenta

func Magenta(s string) string

func Magentaf

func Magentaf(s string, args ...interface{}) string

func PrintArray

func PrintArray[T any](items []T, cmd *cobra.Command, mappers Mappers[T]) error

func PrintRows added in v0.7.0

func PrintRows(rows []*DataRow, w io.Writer)

func Red

func Red(s string) string

func Redf

func Redf(s string, args ...interface{}) string

func Truncate

func Truncate(maxWidth int, s string) string

func Yellow

func Yellow(s string) string

func Yellowf

func Yellowf(s string, args ...interface{}) string

Types

type DataRow added in v0.7.0

type DataRow struct {
	Name  string
	Value string
}

func NewDataRow added in v0.7.0

func NewDataRow(name string, value string) *DataRow

type IdAndName

type IdAndName struct {
	Id   string `json:"Id"`
	Name string `json:"Name"`
}

Common struct used for rendering JSON summaries of things that just have an ID and a Name

type Mappers

type Mappers[T any] struct {
	// A function which will convert T into an output structure suitable for json.Marshal (e.g. IdAndName).
	// If you leave this as nil, then the command will simply not support output as JSON and will
	// fail if someone asks for it
	Json func(item T) any

	// A function which will convert T into ?? suitable for table printing
	// If you leave this as nil, then the command will simply not support output as
	// a table and will fail if someone asks for it
	Table TableDefinition[T]

	// A function which will convert T into a string suitable for basic text display
	// If you leave this as nil, then the command will simply not support output as basic text and will
	// fail if someone asks for it
	Basic func(item T) string
}

carries conversion functions used by PrintArray and potentially other output code in future

type Table

type Table interface {
	AddRow(...string)
	Print() error
}

func NewTable

func NewTable(writer io.Writer) Table

type TableDefinition

type TableDefinition[T any] struct {
	Header []string
	Row    func(item T) []string
}

Jump to

Keyboard shortcuts

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