Documentation ¶
Index ¶
- type Column
- type Printer
- type PrinterBuilder
- type Table
- type TableBuilder
- func (b *TableBuilder) Build(ctx context.Context) (result *Table, err error)
- func (b *TableBuilder) Column(spec string) *TableBuilder
- func (b *TableBuilder) Columns(specs ...string) *TableBuilder
- func (b *TableBuilder) Digger(value *data.Digger) *TableBuilder
- func (b *TableBuilder) Learning(value bool) *TableBuilder
- func (b *TableBuilder) LearningLimit(value int) *TableBuilder
- func (b *TableBuilder) Name(value string) *TableBuilder
- func (b *TableBuilder) Value(name string, value interface{}) *TableBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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) Learn ¶ added in v0.1.55
Learn returns a flag indicating if the width of this column should be learned from the data of the table.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer knows how to write output text.
func (*Printer) Height ¶ added in v0.1.55
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.
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) Flush ¶ added in v0.1.55
Flush makes sure that all the potentially pending data in interna buffers is written out.
func (*Table) WriteHeaders ¶ added in v0.1.55
WriteHeaders writes the headers of the columns of the table.
func (*Table) WriteObject ¶ added in v0.1.55
WriteObject writes a row of a table extracting the values of the columns from the given object.
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.