Documentation
¶
Overview ¶
Package table offers an easy way to generate tables similar to Taskwarrior, featuring 256-color support, automatic text wrapping and Markdown rendering.
tbl := table.NewTableWithStyle(&table.TableStyle{
DefaultWidth: 80,
FitToTerminal: false,
WrapText: true,
Markdown: true,
HideEmpty: true,
OuterPadding: 0,
InnerPadding: 1,
})
bgGreen := text.BgGreen.Sprint("BgGreen")
bgBlue := text.BgBlue.Sprint("BgBlue")
fgRed := text.FgRed.Sprint("FgRed")
tbl.AddHeader("Feature", "Example", "Example")
tbl.AddRow(table.Row{"**Color-256**", bgGreen + " " + bgBlue, fgRed})
tbl.AddRow(table.Row{"**Wrap Text**", strings.Repeat("Hello World! ", 20), "Hello World!"})
tbl.AddRow(table.Row{"Markdown", "[link](http://example.com)", "**Bold** _Italic_ `inline Code`"})
tbl.SetHeaderStyle(&table.CellStyle{
CellAttrs: text.Colors{text.FgGreen, text.Underline},
})
fmt.Print(tbl.Render())
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cell ¶ added in v0.1.5
type Cell struct {
Content string
// Prefix defines the prefix of the cell.
Prefix string
// PrefixFunc defines the prefix function of the cell.
PrefixFunc func(isFirst, isLast bool) string
// Suffix defines the suffix of the cell.
Suffix string
// SuffixFunc defines the suffix function of the cell.
SuffixFunc func(isFirst, isLast bool) string
// contains filtered or unexported fields
}
type CellStyle ¶ added in v0.1.2
type CellStyle struct {
// Align defines the alignment of the text.
Align text.Align
// WrapText defines if the text should be wrapped.
WrapText *bool
// Markdown defines if the text should be rendered as markdown.
Markdown *bool
// TextAttrs defines the text attributes.
TextAttrs text.Colors
// CellAttrs defines the cell attributes.
CellAttrs text.Colors
}
CellStyle is the style of a cell in the table
type Table ¶
type Table interface {
AddHeader(header ...string)
AddRow(row Row)
AddRows(rows []Row)
Length() int
SetStyle(style *TableStyle)
SetHeaderStyle(style *CellStyle)
SetRowStyle(row int, style *CellStyle)
SetColStyle(col int, style *CellStyle)
Render() string
}
func NewTableWithStyle ¶ added in v0.1.2
func NewTableWithStyle(style *TableStyle) Table
type TableStyle ¶ added in v0.1.2
type TableStyle struct {
// DefaultWidth defines the default width of the table.
DefaultWidth int
// FitToTerminal defines if the table should fit to the terminal width.
FitToTerminal bool
// WrapText defines if the text should be wrapped.
WrapText bool
// Markdown defines if the text should be rendered as markdown.
Markdown bool
// HideEmpty defines if empty rows should be hidden.
HideEmpty bool
// OuterPadding defines the padding around the table.
OuterPadding int
// InnerPadding defines the padding between the cells.
InnerPadding int
}
Click to show internal directories.
Click to hide internal directories.