output

package
v0.0.0-...-41e44c1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const TreeEnd = "└─"
View Source
const TreeLink = "│"
View Source
const TreeMid = "├─"

Variables

View Source
var ErrNotRecognized = errs.New("Not Recognized")
View Source
var SpinnerFrames = []string{`|`, `/`, `-`, `\`}

Functions

func Prepare

func Prepare(plain interface{}, structured interface{}) *preparedOutput

func Structured

func Structured(structured interface{}) *structuredOutput

Types

type Behavior

type Behavior int

Behavior defines control tokens that affect printing behavior.

const (
	Suppress Behavior = iota
)

Behavior tokens.

type Config

type Config struct {
	OutWriter   io.Writer
	ErrWriter   io.Writer
	Colored     bool
	Interactive bool
	ShellName   string
}

Config is the thing we pass to Outputer constructors

func (*Config) OutWriterFD

func (c *Config) OutWriterFD() (uintptr, bool)

type Editor

type Editor struct {
	JSON
}

func NewEditor

func NewEditor(config *Config) (Editor, error)

func (*Editor) Type

func (f *Editor) Type() Format

Type tells callers what type of outputer we are

type Emphasize

type Emphasize string

func (Emphasize) MarshalOutput

func (h Emphasize) MarshalOutput(f Format) interface{}

func (Emphasize) MarshalStructured

func (h Emphasize) MarshalStructured(f Format) interface{}

func (Emphasize) String

func (h Emphasize) String() string

type Format

type Format string
const (
	PlainFormatName  Format = "plain"  // human readable
	SimpleFormatName Format = "simple" // human readable without notice level
	JSONFormatName   Format = "json"   // plain json
	EditorFormatName Format = "editor" // alias of "json"
)

FormatName constants are tokens representing supported output formats.

func (Format) IsStructured

func (format Format) IsStructured() bool

type JSON

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

JSON is our JSON outputer, there's not much going on here, just forwards it to the JSON marshaller and provides a basic structure for error

func NewJSON

func NewJSON(config *Config) (JSON, error)

NewJSON constructs a new JSON struct

func (*JSON) Config

func (f *JSON) Config() *Config

Config returns the Config struct for the active instance

func (*JSON) Error

func (f *JSON) Error(value interface{})

Error will marshal and print the given value to the error writer NOTE that JSON always prints to the output writer, the error writer is unused.

func (*JSON) Fprint

func (f *JSON) Fprint(writer io.Writer, value interface{})

Fprint allows printing to a specific writer, using all the conveniences of the output package

func (*JSON) Notice

func (f *JSON) Notice(value interface{})

Notice is ignored by JSON, as they are considered as non-critical output and there's currently no reliable way to reliably combine this data into the eventual output

func (*JSON) Print

func (f *JSON) Print(v interface{})

Print will marshal and print the given value to the output writer

func (*JSON) Type

func (f *JSON) Type() Format

Type tells callers what type of outputer we are

type Marshaller

type Marshaller interface {
	MarshalOutput(Format) interface{}
}

type Mediator

type Mediator struct {
	Outputer
	// contains filtered or unexported fields
}

func (*Mediator) Error

func (m *Mediator) Error(v interface{})

func (*Mediator) Fprint

func (m *Mediator) Fprint(writer io.Writer, v interface{})

func (*Mediator) Notice

func (m *Mediator) Notice(v interface{})

func (*Mediator) Print

func (m *Mediator) Print(v interface{})

type Outputer

type Outputer interface {
	Fprint(writer io.Writer, value interface{})
	Print(value interface{})
	Error(value interface{})
	Notice(value interface{})
	Type() Format
	Config() *Config
}

Outputer is the initialized formatter

func Get

func Get() Outputer

Get is here for legacy use-cases, DO NOT USE IT FOR NEW CODE

func New

func New(formatName string, config *Config) (Outputer, error)

New constructs a new Outputer according to the given format name

type Plain

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

Plain is our plain outputer, it uses reflect to marshal the data. Semantic highlighting tags are supported as [NOTICE]foo[/RESET] Table output is supported if you pass a slice of structs Struct keys are localized by sending them to the locale library as field_key (lowercase)

func NewPlain

func NewPlain(config *Config) (Plain, error)

NewPlain constructs a new Plain struct

func (*Plain) Config

func (f *Plain) Config() *Config

Config returns the Config struct for the active instance

func (*Plain) Error

func (f *Plain) Error(value interface{})

Error will marshal and print the given value to the error writer, it wraps it in the error format but otherwise the only thing that identifies it as an error is the channel it writes it to

func (*Plain) Fprint

func (f *Plain) Fprint(writer io.Writer, v interface{})

Fprint allows printing to a specific writer, using all the conveniences of the output package

func (*Plain) Notice

func (f *Plain) Notice(value interface{})

Notice will marshal and print the given value to the error writer, it wraps it in the notice format but otherwise the only thing that identifies it as an error is the channel it writes it to

func (*Plain) Print

func (f *Plain) Print(value interface{})

Print will marshal and print the given value to the output writer

func (*Plain) Type

func (f *Plain) Type() Format

Type tells callers what type of outputer we are

type PlainOpts

type PlainOpts string

PlainOpts define available tokens for setting plain output options.

const (
	// SeparateLineOpt requests table output to be printed on a separate line (without columns)
	SeparateLineOpt PlainOpts = "separateLine"
	// VerticalTable requests a table be output vertically
	VerticalTable PlainOpts = "verticalTable"
	// EmptyNil replaces nil values with the empty string
	EmptyNil PlainOpts = "emptyNil"
	// HidePlain hides the field value in table output
	HidePlain PlainOpts = "hidePlain"
	// ShiftColsPrefix starts the column after the set qty
	ShiftColsPrefix PlainOpts = "shiftCols="
	// OmitEmpty omits empty values from output
	OmitEmpty PlainOpts = "omitEmpty"
	// HideDash hides the dash in table output
	HideDash PlainOpts = "hideDash"
	// OmitKey hides the current struct key from output, its value is still printed
	OmitKey PlainOpts = "omitKey"
)

type Simple

type Simple struct {
	Plain
}

Simple is an outputer that works exactly as Plain without any notice level output

func NewSimple

func NewSimple(config *Config) (Simple, error)

NewSimple constructs a new Simple struct

func (*Simple) Notice

func (s *Simple) Notice(value interface{})

Notice has no effect for this outputer

func (*Simple) Type

func (s *Simple) Type() Format

Type tells callers what type of outputer we are

type Spinner

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

func StartSpinner

func StartSpinner(out Outputer, msg string, interval time.Duration) *Spinner

func (*Spinner) MarshalOutput

func (d *Spinner) MarshalOutput(f Format) interface{}

func (*Spinner) Stop

func (d *Spinner) Stop(msg string)

type StructuredError

type StructuredError struct {
	Message string   `json:"error"`
	Tips    []string `json:"tips,omitempty"`
}

StructuredError communicates that an error happened due to output that was meant to be structured but wasn't.

func (StructuredError) Error

func (s StructuredError) Error() string

type StructuredMarshaller

type StructuredMarshaller interface {
	MarshalStructured(Format) interface{}
}

type Title

type Title string

func (Title) MarshalOutput

func (t Title) MarshalOutput(f Format) interface{}

func (Title) MarshalStructured

func (t Title) MarshalStructured(f Format) interface{}

func (Title) String

func (t Title) String() string

Directories

Path Synopsis
demo

Jump to

Keyboard shortcuts

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