table

package
v12.110.1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

Package table contains methods and structs for rendering data in tabular format

Index

Examples

Constants

View Source
const (
	ALIGN_LEFT   uint8 = 0
	ALIGN_CENTER uint8 = 1
	ALIGN_RIGHT  uint8 = 2

	AL uint8 = 0 // Short form of ALIGN_LEFT
	AC uint8 = 1 // Short form of ALIGN_CENTER
	AR uint8 = 2 // Short form of ALIGN_RIGHT
)

Column alignment flags

Variables

View Source
var BorderColorTag = "{s}"

BorderColorTag is default fmtc tag used for separator

View Source
var BorderSymbol = "-"

SeparatorSymbol is default symbol used for borders rendering

View Source
var ColumnSeparatorSymbol = "|"

ColumnSeparatorSymbol is default column separator symbol

View Source
var FullScreen = true

FullScreen is a flag for full-screen table by default

View Source
var HeaderCapitalize = false

HeaderCapitalize is a flag for capitalizing headers by default

View Source
var HeaderColorTag = "{*}"

HeaderColorTag is default fmtc tag used for headers

View Source
var SeparatorColorTag = "{s}"

SeparatorColorTag is default fmtc tag used for separator

View Source
var SeparatorSymbol = "-"

SeparatorSymbol is default symbol used for separator rendering

Functions

This section is empty.

Types

type Table

type Table struct {
	Sizes     []int    // Custom columns sizes
	Headers   []string // Slice with headers
	Alignment []uint8  // Columns alignment

	// Width is table maximum width
	Width int

	// SeparatorSymbol is symbol used for borders rendering
	BorderSymbol string

	// SeparatorSymbol is symbol used for separator rendering
	SeparatorSymbol string

	// ColumnSeparatorSymbol is column separator symbol
	ColumnSeparatorSymbol string

	// HeaderColorTag is fmtc tag used for headers
	HeaderColorTag string

	// BorderColorTag is fmtc tag used for separator
	BorderColorTag string

	// SeparatorColorTag is fmtc tag used for separator
	SeparatorColorTag string

	// HeaderCapitalize is a flag for capitalizing headers
	HeaderCapitalize bool

	// HideTopBorder is a flag for disabling bottom border rendering
	HideTopBorder bool

	// HideBottomBorder is a flag for disabling bottom border rendering
	HideBottomBorder bool

	// FullScreen is a flag for full-screen table
	FullScreen bool

	// Processor is function used for processing and formatting input data
	Processor func(data []any) []string
	// contains filtered or unexported fields
}

Table is struct which can be used for table rendering

func NewTable

func NewTable(headers ...string) *Table

NewTable creates new table struct

Example
t := NewTable()

t.SetHeaders("id", "user", "balance")
t.SetSizes(4, 12)
t.SetAlignments(ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_LEFT)

t.Add(1, "{g}Bob{!}", 1.42)
t.Add(2, "John", 73.1)
t.Add(3, "Mary", 2.29)
t.Separator()
t.Add(4, "Bob", 6.6)
t.Add(5, "Matilda", 0.0)

t.Render()
Output:

func (*Table) Add

func (t *Table) Add(data ...any) *Table

Add adds given data to stack

func (*Table) Border added in v12.95.0

func (t *Table) Border() *Table

Border renders table border

func (*Table) HasData

func (t *Table) HasData() bool

HasData returns true if table stack has some data

func (*Table) Print

func (t *Table) Print(data ...any) *Table

Print immediately prints given data

func (*Table) Render

func (t *Table) Render() *Table

Render renders data

func (*Table) RenderHeaders

func (t *Table) RenderHeaders()

RenderHeaders renders headers

func (*Table) Separator

func (t *Table) Separator() *Table

Separator renders separator

func (*Table) SetAlignments

func (t *Table) SetAlignments(align ...uint8) *Table

SetAlignments sets alignment of columns

func (*Table) SetHeaders

func (t *Table) SetHeaders(headers ...string) *Table

SetHeaders sets headers

func (*Table) SetSizes

func (t *Table) SetSizes(sizes ...int) *Table

SetSizes sets size of columns

Jump to

Keyboard shortcuts

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