internal

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package tablewriter creates & generates text based table

Index

Constants

View Source
const (
	// BorderCenterChar defines char at center of border
	BorderCenterChar = "+"
	// BorderRowChar defines char of row border
	BorderRowChar = "-"
	// BorderColumnChar defines char of column border
	BorderColumnChar = "|"
	// Empty defines no padding space or border
	Empty = ""
	// Space defines space char for padding and borders
	Space = " "
)
View Source
const (
	AlignDefault = iota
	AlignLeft
	AlignCenter
	AlignRight
)

AlignDefault and other alignment constants

View Source
const (
	MaxRowWidth = 30
)

MaxRowWidth defines maximum row width

Variables

This section is empty.

Functions

func ConditionString

func ConditionString(cond bool, valid, inValid string) string

ConditionString returns valid or invalid string based on condition

func DisplayWidth

func DisplayWidth(str string) int

DisplayWidth returns display width

func Pad

func Pad(s, pad string, width int) string

Pad string Attempts to play string in the center

func PadLeft

func PadLeft(s, pad string, width int) string

PadLeft paces string at the right side fo the screen

func PadRight

func PadRight(s, pad string, width int) string

PadRight paces string at the left side fo the screen

func Title

func Title(name string) string

Title format table header, replaces _ , . and spaces

func WrapString

func WrapString(s string, lim int) ([]string, int)

WrapString wraps s into a paragraph of lines of length lim, with minimal raggedness.

func WrapWords

func WrapWords(words []string, spc, lim, pen int) [][]string

WrapWords is the low-level line-breaking algorithm, useful if you need more control over the details of the text wrapping process. For most uses, WrapString will be sufficient and more convenient.

WrapWords splits a list of words into lines with minimal "raggedness", treating each rune as one unit, accounting for spc units between adjacent words on each line, and attempting to limit lines to lim units. Raggedness is the total error over all lines, where error is the square of the difference of the length of the line and lim. Too-long lines (which only happen when a single word is longer than lim units) have pen penalty units added to the error.

Types

type Border

type Border struct {
	Left   bool
	Right  bool
	Top    bool
	Bottom bool
}

Border struct

type Table

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

Table struct

func NewTable

func NewTable(writer io.Writer) *Table

NewTable returns a new table that writes to writer.

func (*Table) Append

func (t *Table) Append(row []string)

Append row to table

func (*Table) AppendBulk

func (t *Table) AppendBulk(rows [][]string)

AppendBulk allows support for Bulk Append Eliminates repeated for loops

func (*Table) RenderAll

func (t *Table) RenderAll()

RenderAll table output

func (*Table) SetAlignment

func (t *Table) SetAlignment(align int)

SetAlignment sets Table Alignment

func (*Table) SetAutoFormatHeaders

func (t *Table) SetAutoFormatHeaders(auto bool)

SetAutoFormatHeaders turns header autoformatting on/off. Default is on (true).

func (*Table) SetAutoWrapText

func (t *Table) SetAutoWrapText(auto bool)

SetAutoWrapText turns automatic multiline text adjustment on/off. Default is on (true).

func (*Table) SetBorder

func (t *Table) SetBorder(border bool)

SetBorder enable / disable line around the table

func (*Table) SetBorders

func (t *Table) SetBorders(border Border)

SetBorders sets borders

func (*Table) SetCellTrans

func (t *Table) SetCellTrans(row, col int, trans textTransFunc)

SetCellTrans sets the cell transformer.

REVISIT: does this even work? How does it interact with SetColTrans?

func (*Table) SetCenterSeparator

func (t *Table) SetCenterSeparator(sep string)

SetCenterSeparator sets the center Separator

func (*Table) SetColTrans

func (t *Table) SetColTrans(col int, trans textTransFunc)

SetColTrans sets the column transformer.

func (*Table) SetColWidth

func (t *Table) SetColWidth(width int)

SetColWidth sets the default column width

func (*Table) SetColumnSeparator

func (t *Table) SetColumnSeparator(sep string)

SetColumnSeparator sets the Column Separator

func (*Table) SetFooter

func (t *Table) SetFooter(keys []string)

SetFooter sets table Footer

func (*Table) SetFooterAlignment

func (t *Table) SetFooterAlignment(fAlign int)

SetFooterAlignment sets Footer Alignment

func (*Table) SetHeader

func (t *Table) SetHeader(keys []string)

SetHeader sets table header

func (*Table) SetHeaderAlignment

func (t *Table) SetHeaderAlignment(hAlign int)

SetHeaderAlignment sets Header Alignment

func (*Table) SetHeaderDisable

func (t *Table) SetHeaderDisable(disable bool)

SetDisableHeader enable / disable printing of headers

func (*Table) SetHeaderLine

func (t *Table) SetHeaderLine(line bool)

SetHeaderLine enable / disable a line after the header

func (*Table) SetHeaderTrans

func (t *Table) SetHeaderTrans(trans textTransFunc)

SetHeaderTrans sets the transformer for the header row.

func (*Table) SetRowLine

func (t *Table) SetRowLine(line bool)

SetRowLine enable / disable a line on each row of the table

func (*Table) SetRowSeparator

func (t *Table) SetRowSeparator(sep string)

SetRowSeparator sets the Row Separator

Jump to

Keyboard shortcuts

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