tables

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AlignmentLeft aligns the column to the left.
	AlignmentLeft = -1

	// AlignmentRight aligns the column to the right.
	AlignmentRight = 1

	// AlignmentCenter aligns the column to the center.
	AlignmentCenter = 0
)

Variables

This section is empty.

Functions

func AlignText

func AlignText(text string, width int, alignment int) string

AlignText aligns a string to a given width and alignment. This is used to manage columns once the contents are formatted. This is Unicode-safe.

func CsvSplit

func CsvSplit(data string) []string

CsvSplit takes a line that is comma-separated and splits it into an array of strings. Quoted commas are ignored as separators. The values are trimmed of extra spaces.

Types

type Table

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

Table is the wrapper object around a table to be printed.

func New

func New(headings []string) (*Table, error)

New creates a new table object, given a list of headings.

func NewCSV

func NewCSV(h string) (*Table, error)

NewCSV creates a new table using a single string with comma-separated heading names. These typically correspond to the first row in a CSV data file.

func (*Table) AddCSVRow

func (t *Table) AddCSVRow(items string) error

AddCSVRow addsa row to an existing table, where the row is expressed as a string with comma-separated values.

func (*Table) AddRow

func (t *Table) AddRow(row []string) error

AddRow adds a row to an existing table using an array of string objects, where each object represents a column of the data.

func (*Table) AddRowItems

func (t *Table) AddRowItems(items ...interface{}) error

AddRowItems adds a row to an existing table using individual parameters. Each parameter is converted to a string representation, and the set of all formatted values are added to the table as a row.

func (*Table) Column

func (t *Table) Column(name string) (int, bool)

Column returns the column number for a named column. The boolean return value indicates if the value was found, if true then the integer result is a zero-based column number.

func (*Table) FormatJSON

func (t *Table) FormatJSON() string

FormatJSON will produce the text of the table as JSON.

func (*Table) FormatText

func (t *Table) FormatText() []string

FormatText will output a table using current rows and format specifications.

func (*Table) GetHeadings

func (t *Table) GetHeadings() []string

GetHeadings returns an array of the headings already stored in the table. This can be used to validate a name against the list of headings, for example.

func (*Table) Print

func (t *Table) Print(format string) error

Print will output a table using current rows and format specifications.

func (*Table) RowLimit

func (t *Table) RowLimit(limit int) *Table

RowLimit sets the row limit for output (<0 means all rows).

func (*Table) SetAlignment

func (t *Table) SetAlignment(column int, alignment int) error

SetAlignment sets the alignment for a given column. Column numbers are zero-based.

func (*Table) SetColumnOrder

func (t *Table) SetColumnOrder(order []int) error

SetColumnOrder accepts a list of column positions and uses it to set the order in which columns of output are printed.

func (*Table) SetColumnOrderByName

func (t *Table) SetColumnOrderByName(order []string) error

SetColumnOrderByName accepts a list of column positions and uses it to set the order in which columns of output are printed.

func (*Table) SetIndent

func (t *Table) SetIndent(s int) error

SetIndent specifies the spaces to indent each heading and row.

func (*Table) SetMinimumWidth

func (t *Table) SetMinimumWidth(n int, w int) error

SetMinimumWidth specifies the minimum width of a column. The column number is always zero-based.

func (*Table) SetOrderBy

func (t *Table) SetOrderBy(name string) error

SetOrderBy sets the name of the column that should be used for sorting the output data.

func (*Table) SetPagination

func (t *Table) SetPagination(height, width int)

func (*Table) SetSpacing

func (t *Table) SetSpacing(s int) error

SetSpacing specifies the spaces between columns in output.

func (*Table) SetStartingRow

func (t *Table) SetStartingRow(s int) error

SetStartingRow specifies the first row of the table to be printed. A value less than zero is an error.

func (*Table) SetWhere

func (t *Table) SetWhere(clause string) *Table

SetWhere sets an expression to be used as a "where" clause to select table rows.

func (*Table) ShowHeadings

func (t *Table) ShowHeadings(flag bool) *Table

ShowHeadings disables printing of column headings when the parameter is true.

func (*Table) ShowRowNumbers

func (t *Table) ShowRowNumbers(flag bool) *Table

ShowRowNumbers enables printing of column headings when the parameter is true.

func (*Table) ShowUnderlines

func (t *Table) ShowUnderlines(flag bool) *Table

ShowUnderlines enables underlining of column headings when the parameter is true.

func (*Table) SortRows

func (t *Table) SortRows(column int, ascending bool) error

SortRows sorts the existing table rows. The column to sort by is specified by ordinal position (zero-based). The ascending flag is true if the sort is to be in ascending order, and false if a descending sort is required.

func (*Table) String

func (t *Table) String(format string) (string, error)

String will output a table using current rows and format specifications.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳