output

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: Apache-2.0 Imports: 16 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

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