output

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminal added in v0.1.57

func IsTerminal(writer io.Writer) bool

IsTerminal determines if the given writer is a terminal

Types

type Column added in v0.1.55

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

Column contains the data and logic needed to write columns.

func (*Column) Adjust added in v0.1.55

func (c *Column) Adjust(value int)

Adjust adjust the width of the column to the given value.

func (*Column) Header added in v0.1.55

func (c *Column) Header() string

Header returns the header for this column.

func (*Column) Learn added in v0.1.55

func (c *Column) Learn() bool

Learn returns a flag indicating if the width of this column should be learned from the data of the table.

func (*Column) Value added in v0.1.55

func (c *Column) Value(object interface{}) interface{}

Value extract the value of this column from the given object.

func (*Column) Width added in v0.1.55

func (c *Column) Width() int

Width returns the width for this column.

type Printer

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

Printer knows how to write output text.

func (*Printer) Close

func (p *Printer) Close() error

Close releases all the resources used by the printer.

func (*Printer) Height added in v0.1.55

func (p *Printer) Height() int

Height returns the height of the terminal. If the output isn't a terminal the result will be zero.

func (*Printer) NewTable added in v0.1.55

func (p *Printer) NewTable() *TableBuilder

NewTable creates a new builder that can then be used to configure and create a table.

func (*Printer) Terminal added in v0.1.55

func (p *Printer) Terminal() bool

Terminal returns true if the output is a terminal.

func (*Printer) Width added in v0.1.55

func (p *Printer) Width() int

Width returns the width of the terminal. If the output isn't a terminal the result will be zero.

func (*Printer) Write

func (p *Printer) Write(b []byte) (n int, err error)

Write is the implementation of the io.Writer interface.

type PrinterBuilder

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

PrinterBuilder contains the data and logic needed to create new printers.

func NewPrinter

func NewPrinter() *PrinterBuilder

NewPrinter creates a builder that can then be used to configure and create a printer.

func (*PrinterBuilder) Build

func (b *PrinterBuilder) Build(ctx context.Context) (result *Printer, err error)

Build uses the data stored in the builder to create a new printer.

func (*PrinterBuilder) Digger added in v0.1.55

func (b *PrinterBuilder) Digger(value *data.Digger) *PrinterBuilder

Digger sets the digger that will be used to extract fields from objects. This is optional. If not specified a digger with the default configuration will be automatically created.

func (*PrinterBuilder) Pager added in v0.1.55

func (b *PrinterBuilder) Pager(value string) *PrinterBuilder

Pager indicates the command that will be used to display output page by page. If empty no pager will be used.

func (*PrinterBuilder) Writer

func (b *PrinterBuilder) Writer(value io.Writer) *PrinterBuilder

Writer sets the writer where the printer will write. It will usually be a file or the standard output fo the process. This is mandatory.

type Table added in v0.1.55

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

Table contains the data and logic needed to write tabular output.

func (*Table) Close added in v0.1.55

func (t *Table) Close() error

Close releases all the resources used by the table.

func (*Table) Flush added in v0.1.55

func (t *Table) Flush() error

Flush makes sure that all the potentially pending data in interna buffers is written out.

func (*Table) WriteHeaders added in v0.1.55

func (t *Table) WriteHeaders() error

WriteHeaders writes the headers of the columns of the table.

func (*Table) WriteObject added in v0.1.55

func (t *Table) WriteObject(object interface{}) error

WriteObject writes a row of a table extracting the values of the columns from the given object.

func (*Table) WriteRow added in v0.1.55

func (t *Table) WriteRow(rowValues []interface{}) error

WriteRow writes a row of a table using the given values.

type TableBuilder added in v0.1.55

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

TableBuilder contains the data and logic needed to create a new output table.

func (*TableBuilder) Build added in v0.1.55

func (b *TableBuilder) Build(ctx context.Context) (result *Table, err error)

Build uses the configuration stored in the builder to create a table.

func (*TableBuilder) Column added in v0.1.55

func (b *TableBuilder) Column(spec string) *TableBuilder

Column adds a column to the table. The spec can be a single column identifier or a set of comma separated column identifiers.

func (*TableBuilder) Columns added in v0.1.55

func (b *TableBuilder) Columns(specs ...string) *TableBuilder

Columns adds a collection of columns to the table. Each spec can be a single column identifier or a set of comman separated column identifiers.

func (*TableBuilder) Digger added in v0.1.55

func (b *TableBuilder) Digger(value *data.Digger) *TableBuilder

Digger sets the digger that will be used to extract fields from row objects. If not specified the digger of the printer will be used.

func (*TableBuilder) Learning added in v0.1.55

func (b *TableBuilder) Learning(value bool) *TableBuilder

Learning enables or disables the mechanism that the table uses to learn how to display columns. When learning is enabled the table will use the first rows of the table to adjust the widths of the columns in order to not waste space. The default value is that learning is enabled.

Note that the results of learning are usually good, but there may be cases where they aren't. For example, if the first one hundred rows of one row have a column empty then the width of that column will be reduced to the width of the header even if there are other later rows that have very long values.

func (*TableBuilder) LearningLimit added in v0.1.55

func (b *TableBuilder) LearningLimit(value int) *TableBuilder

LearningLimit sets the number of rows (including the headers) that the table will use for learning is enabled. The default value is to use the first one hundred rows.

func (*TableBuilder) Name added in v0.1.55

func (b *TableBuilder) Name(value string) *TableBuilder

Name sets the name of the table. This is mandatory.

func (*TableBuilder) Value added in v0.1.55

func (b *TableBuilder) Value(name string, value interface{}) *TableBuilder

Value sets the value for the given column name. The value can be an object or a function. If it is a function then it will be called passing as parameter the row object and it is expected to return as first output parameter the value for the column.

Jump to

Keyboard shortcuts

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