table

package
v12.41.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 6 Imported by: 1

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       = 1
	ALIGN_RIGHT        = 2
)

Column alignment flags

Variables

View Source
var ColumnSeparatorSymbol = "|"

ColumnSeparatorSymbol is column separator symbol

View Source
var HeaderCapitalize = false

HeaderCapitalize is flag for capitalizing headers by default

View Source
var HeaderColorTag = "{*}"

HeaderColorTag is fmtc tag used for headers by default for all tables

View Source
var MaxWidth = 0

MaxWidth is a maximum table width

View Source
var SeparatorSymbol = "-"

SeparatorSymbol used for separator generation

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
	// 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.Render()
Output:

func (*Table) Add

func (t *Table) Add(data ...interface{}) *Table

Add adds given data to stack

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 ...interface{}) *Table

Print renders 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 aligment 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