txtfmt

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatEntity

func FormatEntity(title string, attrs []TableRow) string

FormatEntity returns a formatted string from the supplied entity title and table of attributes.

func GetEntityPadding

func GetEntityPadding(table []TableRow) (padding int)

GetEntityPadding will determine the minimum width necessary to display the entity attributes.

Types

type EntityFormatter

type EntityFormatter struct {
	Separator string
	// contains filtered or unexported fields
}

EntityFormatter can be used for neatly displaying attributes of a single entity.

func NewEntityFormatter

func NewEntityFormatter(title string, padWidth int) *EntityFormatter

NewEntityFormatter returns an initialized EntityFormatter.

func (*EntityFormatter) Format

func (f *EntityFormatter) Format(table []TableRow) string

Format generates an output string for the supplied table rows. It includes a single subject header, and each row is printed as an attribute/value pair.

func (*EntityFormatter) Init

func (f *EntityFormatter) Init(padWidth int)

Init instantiates internal variables.

type TableFormatter

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

TableFormatter is a structure that formats string output for a table with labeled columns.

func NewTableFormatter

func NewTableFormatter(columnTitles ...string) *TableFormatter

NewTableFormatter creates and instantiates a new TableFormatter.

func (*TableFormatter) Format

func (t *TableFormatter) Format(table []TableRow) string

Format generates an output string for the set of table rows provided. It includes a header with column titles, and fills only the requested columns in order.

func (*TableFormatter) Init

func (t *TableFormatter) Init()

Init instantiates internal variables.

func (*TableFormatter) SetColumnTitles

func (t *TableFormatter) SetColumnTitles(c ...string)

SetColumnTitles sets the ordered column titles for the table.

type TableRow

type TableRow map[string]string

TableRow is a map of string values to be printed, keyed by column title.

Jump to

Keyboard shortcuts

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