Documentation ¶
Overview ¶
Package table contains methods and structs for rendering data in tabular format
Index ¶
- Constants
- Variables
- type Table
- func (t *Table) Add(data ...any) *Table
- func (t *Table) Border() *Table
- func (t *Table) HasData() bool
- func (t *Table) Print(data ...any) *Table
- func (t *Table) Render() *Table
- func (t *Table) RenderHeaders()
- func (t *Table) Separator() *Table
- func (t *Table) SetAlignments(align ...uint8) *Table
- func (t *Table) SetHeaders(headers ...string) *Table
- func (t *Table) SetSizes(sizes ...int) *Table
Examples ¶
Constants ¶
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 ¶
var BorderColorTag = "{s}"
BorderColorTag is default fmtc tag used for separator
var BorderSymbol = "-"
SeparatorSymbol is default symbol used for borders rendering
var ColumnSeparatorSymbol = "|"
ColumnSeparatorSymbol is default column separator symbol
var FullScreen = true
FullScreen is a flag for full-screen table by default
var HeaderCapitalize = false
HeaderCapitalize is a flag for capitalizing headers by default
var HeaderColorTag = "{*}"
HeaderColorTag is default fmtc tag used for headers
var SeparatorColorTag = "{s}"
SeparatorColorTag is default fmtc tag used for separator
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 ¶
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) SetAlignments ¶
SetAlignments sets alignment of columns
func (*Table) SetHeaders ¶
SetHeaders sets headers