txtfmt

package
v0.0.0-...-b364e49 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: BSD-2-Clause-Patent Imports: 4 Imported by: 4

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 ErrWriter

type ErrWriter struct {
	Err error
	// contains filtered or unexported fields
}

ErrWriter eliminates repetitive error handling by capturing an error and ignoring subsequent writes. The original error is available to be used by the caller.

https://dave.cheney.net/2019/01/27/eliminate-error-handling-by-eliminating-errors

func NewErrWriter

func NewErrWriter(w io.Writer) *ErrWriter

NewErrWriter returns an initialized ErrWriter.

func (*ErrWriter) Write

func (w *ErrWriter) Write(data []byte) (int, error)

type IndentWriter

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

IndentWriter indents every line written to it.

func NewIndentWriter

func NewIndentWriter(w io.Writer, opts ...IndentWriterOption) *IndentWriter

NewIndentWriter returns an initialized IndentWriter.

func (*IndentWriter) Write

func (w *IndentWriter) Write(data []byte) (int, error)

type IndentWriterOption

type IndentWriterOption func(*IndentWriter)

IndentWriterOption configures the IndentWriter.

func WithPadCount

func WithPadCount(count uint) IndentWriterOption

WithPadCount sets the indent width.

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) InitWriter

func (t *TableFormatter) InitWriter(w io.Writer)

InitWriter optionally sets up the tabwriter to use the supplied io.Writer instead of the internal buffer.

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