tableprinter

package
Version: v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetIsTTY added in v1.17.0

func SetIsTTY(isTTY bool)

SetIsTTY sets the IsTTY variable which indicates whether terminal output is a TTY or nonTTY

func SetNonTTYSeparator added in v1.17.0

func SetNonTTYSeparator(s string)

SetNonTTYSeparator sets the separator for the columns in the table for non-ttys

func SetTTYSeparator added in v1.17.0

func SetTTYSeparator(s string)

SetTTYSeparator sets the separator for the columns in the table for TTYs

func SetTerminalWidth added in v1.12.0

func SetTerminalWidth(width int)

SetTerminalWidth sets the maximum width for the terminal

Types

type TableCell

type TableCell struct {
	// Value in the cell
	Value interface{}
	// Width is the width of the cell
	Width int
	// Wrap when true wraps the contents of the cell when the length exceeds the width
	Wrap bool
	// contains filtered or unexported fields
}

func (*TableCell) LineWidth added in v1.12.0

func (c *TableCell) LineWidth() int

LineWidth returns the max width of all the lines in a cell

func (*TableCell) String added in v1.12.0

func (c *TableCell) String() string

String returns the string formatted representation of the cell

type TablePrinter

type TablePrinter struct {
	// Total number of records. Needed if AddRowFunc is used
	TotalRows int
	// Wrap when set to true wraps the contents of the columns when the length exceeds the MaxColWidth
	Wrap bool
	// MaxColWidth is the maximum allowed width for cells in the table
	MaxColWidth int
	// TTYSeparator is the separator for columns in the table on TTYs. Default is "\t"
	TTYSeparator string
	// NonTTYSeparator is the separator for columns in the table on non-TTYs. Default is "\t"
	NonTTYSeparator string
	// Rows is the collection of rows in the table
	Rows []*TableRow
	// TerminalWidth is the max width of the terminal
	TerminalWidth int
	// IsTTY indicates whether output is a TTY or non-TTY
	IsTTY bool
}

TablePrinter represents a decorator that renders the data formatted in a tabular form.

func NewTablePrinter

func NewTablePrinter() *TablePrinter

func (*TablePrinter) AddCell

func (t *TablePrinter) AddCell(s interface{})

func (*TablePrinter) AddCellf

func (t *TablePrinter) AddCellf(s string, f ...interface{})

AddCellf formats according to a format specifier and adds cell to row

func (*TablePrinter) AddRow

func (t *TablePrinter) AddRow(str ...interface{})

func (*TablePrinter) AddRowFunc

func (t *TablePrinter) AddRowFunc(f func(int, int) string)

func (*TablePrinter) Bytes

func (t *TablePrinter) Bytes() []byte

Bytes returns the []byte value of table

func (*TablePrinter) EndRow

func (t *TablePrinter) EndRow()

func (*TablePrinter) Render

func (t *TablePrinter) Render() string

Render builds and returns the string representation of the table

func (*TablePrinter) Separator

func (t *TablePrinter) Separator() string

func (*TablePrinter) SetIsTTY added in v1.17.0

func (t *TablePrinter) SetIsTTY(isTTY bool)

func (*TablePrinter) SetNonTTYSeparator added in v1.17.0

func (t *TablePrinter) SetNonTTYSeparator(s string)

func (*TablePrinter) SetTTYSeparator added in v1.17.0

func (t *TablePrinter) SetTTYSeparator(s string)

func (*TablePrinter) SetTerminalWidth added in v1.12.0

func (t *TablePrinter) SetTerminalWidth(width int)

func (*TablePrinter) String

func (t *TablePrinter) String() string

String returns the string value of table. Alternative to Render()

type TableRow added in v1.12.0

type TableRow struct {
	Cells []*TableCell
	// Separator is the seperator for columns in the table. Default is " "
	Separator string
}

func (*TableRow) String added in v1.12.0

func (r *TableRow) String() string

String returns the string representation of the row

Jump to

Keyboard shortcuts

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