tablewriter

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2020 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Overview

Package tablewriter provides a basic ASCII table writer with customization options for: headers, label levels, cell alignment, handling overly-wide cells (truncate vs wrap), and auto-merging repeat values in the same column.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeDefaults added in v0.2.0

func ChangeDefaults(defaults Defaults)

ChangeDefaults changes the library's global variable settings for any field supplied. Fields with unsupported changes are ignored.

Types

type Alignment

type Alignment int

An Alignment configures how text is aligned in a cell.

const (
	// AlignCenter centers the cell.
	AlignCenter Alignment = iota
	// AlignRight right-justifies the cell
	AlignRight
	// AlignLeft left-justifies the cell
	AlignLeft
)

type Defaults added in v0.2.0

type Defaults struct {
	BorderEdge, BorderLabelEdge, BorderFiller string
	HeaderEdge, HeaderLabelEdge, HeaderFiller string
	ContentEdge, ContentLabelEdge             string
	MaxColWidth                               int
}

Defaults may be supplied to ChangeDefaults() to change the library's global variable settings. All edge and filler symbols must be 1-rune wide, except for label edges which must be 2-runes wide. MaxColWidth must be > 0. Unsupported field values are ignored.

type Table

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

A Table can be rendered into a stringified representation of content rows and dividing rows with the results written into an io.Writer.

func NewTable

func NewTable(w io.Writer) *Table

NewTable creates a default table writing to `w`.

func (*Table) AppendHeaderRow

func (tbl *Table) AppendHeaderRow(row []string) error

AppendHeaderRow appends a header row to the table.

func (*Table) AppendRow

func (tbl *Table) AppendRow(row []string) error

AppendRow appends a non-header row to the table.

func (*Table) AppendRows

func (tbl *Table) AppendRows(rows [][]string) error

AppendRows appends one or more non-header rows to the table.

func (*Table) DisableHeaderAutoCentering added in v0.2.0

func (tbl *Table) DisableHeaderAutoCentering()

DisableHeaderAutoCentering causes header cells to be aligned based on the underlying table alignment (default: headers are auto-centered).

func (*Table) MergeRepeats added in v0.1.2

func (tbl *Table) MergeRepeats()

MergeRepeats merges all repeated values in a column together.

func (*Table) Render

func (tbl *Table) Render() error

Render creates a stringified representation of content rows and dividing rows and writes the results into the table's io.Writer.

func (*Table) SetAlignment added in v0.1.3

func (tbl *Table) SetAlignment(alignment Alignment)

SetAlignment sets the alignment of cells in content rows to `alignment`.

func (*Table) SetLabelLevelCount added in v0.1.4

func (tbl *Table) SetLabelLevelCount(n int)

SetLabelLevelCount sets the number of label levels to `n`. "Label levels" are the leftmost columns in the table, and typically have values that help identify ("label") specific rows. They are often analogous to a table index. Setting `n` > 0 will visually separate the label levels from the other columns in the table. (Default: 0 label levels).

func (*Table) TruncateWideCells added in v0.1.2

func (tbl *Table) TruncateWideCells()

TruncateWideCells handles overly wide cells by truncating them (default: wrap cell remainder onto new one or more new lines).

Jump to

Keyboard shortcuts

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