tabulate

package
v0.0.0-...-b6fc690 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MIN_PADDING = 5

Minimum padding that will be applied

View Source
var TableFormats = map[string]TableFormat{
	"simple": {
		LineTop:         Line{"", "-", "  ", ""},
		LineBelowHeader: Line{"", "-", "  ", ""},
		LineBottom:      Line{"", "-", "  ", ""},
		HeaderRow:       Row{"", "  ", ""},
		DataRow:         Row{"", "  ", ""},
		TitleRow:        Row{"", "  ", ""},
		Padding:         1,
	},
	"plain": {
		HeaderRow: Row{"", "  ", ""},
		DataRow:   Row{"", "  ", ""},
		TitleRow:  Row{"", "  ", ""},
		Padding:   1,
	},
	"grid": {
		LineTop:         Line{"+", "-", "+", "+"},
		LineBelowHeader: Line{"+", "=", "+", "+"},
		LineBetweenRows: Line{"+", "-", "+", "+"},
		LineBottom:      Line{"+", "-", "+", "+"},
		HeaderRow:       Row{"|", "|", "|"},
		DataRow:         Row{"|", "|", "|"},
		TitleRow:        Row{"|", " ", "|"},
		Padding:         1,
	},
}

Table Formats that are available to the user The user can define his own format, just by adding an entry to this map and calling it with Render function e.g t.Render("customFormat")

Functions

This section is empty.

Types

type Line

type Line struct {
	Begin string
	Hline string
	Sep   string
	End   string
}

Represents a Line

type Row

type Row struct {
	Begin string
	Sep   string
	End   string
}

Represents a Row

type TableFormat

type TableFormat struct {
	LineTop         Line
	LineBelowHeader Line
	LineBetweenRows Line
	LineBottom      Line
	HeaderRow       Row
	DataRow         Row
	TitleRow        Row
	Padding         int
	HeaderHide      bool
	FitScreen       bool
}

Basic Structure of TableFormat

type Tabulate

type Tabulate struct {
	Data          []*TabulateRow
	Title         string
	TitleAlign    string
	Headers       []string
	FloatFormat   byte
	TableFormat   TableFormat
	Align         string
	EmptyVar      string
	HideLines     []string
	MaxSize       int
	WrapStrings   bool
	WrapDelimiter rune
	SplitConcat   string
}

Main Tabulate structure

func Create

func Create(data interface{}) *Tabulate

Create a new Tabulate Object Accepts 2D String Array, 2D Int Array, 2D Int64 Array, 2D Bool Array, 2D Float64 Array, 2D interface{} Array, Map map[strig]string, Map map[string]interface{},

func (*Tabulate) Render

func (t *Tabulate) Render(format ...interface{}) string

Render the data table

func (*Tabulate) SetAlign

func (t *Tabulate) SetAlign(align string)

Set Align Type, Available options: left, right, center

func (*Tabulate) SetEmptyString

func (t *Tabulate) SetEmptyString(empty string)

Set how an empty cell will be represented

func (*Tabulate) SetFloatFormat

func (t *Tabulate) SetFloatFormat(format byte) *Tabulate

Set Float Formatting will be used in strconv.FormatFloat(element, format, -1, 64)

func (*Tabulate) SetHeaders

func (t *Tabulate) SetHeaders(headers []string) *Tabulate

Set Headers of the table If Headers count is less than the data row count, the headers will be padded to the right

func (*Tabulate) SetHideLines

func (t *Tabulate) SetHideLines(hide []string)

Set which lines to hide. Can be: top - Top line of the table, belowheader - Line below the header, bottom - Bottom line of the table

func (*Tabulate) SetMaxCellSize

func (t *Tabulate) SetMaxCellSize(max int)

Sets the maximum size of cell If WrapStrings is set to true, then the string inside the cell will be split up into multiple cell

func (*Tabulate) SetSplitConcat

func (t *Tabulate) SetSplitConcat(r string)

SetSplitConcat assigns the character that will be used when a WrapDelimiter is set but the renderer cannot abide by the desired split. This may happen when the WrapDelimiter is a space ' ' but a single word is longer than the width of a cell

func (*Tabulate) SetTitle

func (t *Tabulate) SetTitle(title ...string) *Tabulate

SetTitle sets the title of the table can also accept a second string to define an alignment for the title

func (*Tabulate) SetWrapDelimiter

func (t *Tabulate) SetWrapDelimiter(r rune)

SetWrapDelimiter assigns the character ina string that the rednderer will attempt to split strings on when a cell must be wrapped

func (*Tabulate) SetWrapStrings

func (t *Tabulate) SetWrapStrings(wrap bool)

type TabulateRow

type TabulateRow struct {
	Elements  []string
	Continuos bool
}

Represents normalized tabulate Row

Jump to

Keyboard shortcuts

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