Documentation ¶
Index ¶
- Variables
- type BorderMask
- type BorderRune
- type BorderRunes
- type Option
- func WithAlignment(alignment text.Alignment) Option
- func WithBorderMask(mask BorderMask) Option
- func WithBorderRunes(runes BorderRunes) Option
- func WithBorderStyle(style *style.Style) Option
- func WithColumnAlignment(alignment ...text.Alignment) Option
- func WithColumnStyle(style ...*style.Style) Option
- func WithColumnWordWrap(wrap ...bool) Option
- func WithMargin(margin int) Option
- func WithMaxWidth(maxWidth int) Option
- func WithPadding(padding int) Option
- func WithStyle(style *style.Style) Option
- func WithWordWrap(wrap bool) Option
- type Table
Constants ¶
This section is empty.
Variables ¶
var DefaultBorderRunes = BorderRunes{ BorderRuneHorizontal: '─', BorderRuneVertical: '│', BorderRuneCornerTopLeft: '┌', BorderRuneCornerTopRight: '┐', BorderRuneCornerBottomLeft: '└', BorderRuneCornerBottomRight: '┘', BorderRuneIntersectionTop: '┬', BorderRuneIntersectionBottom: '┴', BorderRuneIntersectionLeft: '├', BorderRuneIntersectionRight: '┤', BorderRuneIntersectionCenter: '┼', BorderRuneSectionHorizontal: '═', BorderRuneSectionIntersectionLeft: '╞', BorderRuneSectionIntersectionRight: '╡', BorderRuneSectionIntersectionCenter: '╪', }
DefaultBorderRunes are the runes that will be used to draw table borders if not explicitly overridden via table options. This is an exported variable to allow overriding table borders globally.
Functions ¶
This section is empty.
Types ¶
type BorderMask ¶
type BorderMask int
BorderMask controls which borders should be displayed.
const ( BorderNone BorderMask = 1 << iota BorderLeft BorderColumn BorderRight BorderTop BorderRow BorderBottom BorderSection BorderAllHorizontal = BorderTop | BorderRow | BorderBottom | BorderSection BorderAllVertical = BorderLeft | BorderColumn | BorderRight BorderAll = BorderAllHorizontal | BorderAllVertical )
BorderMask options.
func (BorderMask) Has ¶
func (b BorderMask) Has(mask BorderMask) bool
Has returns true if b has the bits of mask set.
type BorderRune ¶
type BorderRune int
BorderRune indicates the type of rune used for a border.
const ( BorderRuneHorizontal BorderRune = iota // ─ BorderRuneVertical // │ BorderRuneCornerTopLeft // ┌ BorderRuneCornerTopRight // ┐ BorderRuneCornerBottomLeft // └ BorderRuneCornerBottomRight // └ BorderRuneIntersectionTop // ┬ BorderRuneIntersectionBottom // ┴ BorderRuneIntersectionLeft // ├ BorderRuneIntersectionRight // ┤ BorderRuneIntersectionCenter // ┼ BorderRuneSectionHorizontal // ═ BorderRuneSectionIntersectionLeft // ╞ BorderRuneSectionIntersectionRight // ╡ BorderRuneSectionIntersectionCenter // ╪ )
BorderRune elements that are needed to draw a table with corners, intersections, row separators (horizontal) and column separators (vertical borders). Can be configured on a table via the WithBorderRunes table option. See DefaultBorderRunes for a mapping of these constants to actual runes.
type BorderRunes ¶
type BorderRunes map[BorderRune]rune
BorderRunes is a map of the BorderRune type to the actual rune that should be displayed.
type Option ¶
type Option func(t *Table)
Option is a func for configuring a *Table.
func WithAlignment ¶
WithAlignment sets the default alignment for all table cells. Can be overridden per table column via WithColumnAlignment. The alignment is ignored for console.Renderable values passed to table.AddRow as these may have their own alignment rules. See the documentation of table.AddRow.
func WithBorderMask ¶
func WithBorderMask(mask BorderMask) Option
WithBorderMask controls the borders that should be displayed using a bit mask.
func WithBorderRunes ¶
func WithBorderRunes(runes BorderRunes) Option
WithBorderRunes sets the runes that should be rendered for the individual border elements, e.g. corners, vertical and horizontal lines and junctions. See the documentation of DefaultBorderRunes for an example. It is valid to pass a rune mapping for a subset of the required border runes. Missing runes will be filled with the corresponding runes from DefaultBorderRunes.
func WithBorderStyle ¶
WithBorderStyle sets the style the should be applied to each border element. The default is to not apply any style.
func WithColumnAlignment ¶
WithColumnAlignment configures the cell alignment per column. See documentation of WithAlignment.
func WithColumnStyle ¶
WithColumnStyle configures the cell style per column. See documentation of WithStyle.
func WithColumnWordWrap ¶
WithWordWrap configures the cell word wrapping behaviour per column. See documentation of WithWordWrap.
func WithMargin ¶
WithMargin sets the left and right margin of table rows. Defaults to 0.
func WithMaxWidth ¶
WithMaxWidth sets the maximum table width. If maxWidth is <= 0, maxWidth is inferred from the table's underlying io.Writer if it is a console.FileWriter, otherwise a default of 80 is used.
func WithPadding ¶
WithPadding sets the horizontal padding between adjacent table cells. Defaults to 1.
func WithStyle ¶
WithAlignment sets the default style for all table cells. Can be overridden per table column via WithColumnStyle. The style is ignored for console.Renderable values passed to table.AddRow as these may have their own style rules. See the documentation of table.AddRow.
func WithWordWrap ¶
WithWordWrap sets the default word wrapping behaviour for all table cells. If true, cells are word wrapped if width constraints make this necessary. Otherwise, cells are not word wrapped but may be truncated if they exceed the width constraints. Can be overridden per table column via WithColumnWordWrap. The word wrap config is ignored for console.Renderable values passed to table.AddRow as these may have their own word wrapping rules. See the documentation of table.AddRow.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table can render properly aligned columns and rows of information.
func (*Table) AddFooter ¶
AddFooter adds a footer row to the table. Panics if the number of columns does not align with the number of columns of already existing table rows.
Columns implementing console.Renderable are NOT formatted using the cell and column specific options (e.g. style, alignment, word wrap) configured via the table.With* and table.WithColumn* option funcs. This allows users to add custom cell behaviour if needed.
func (*Table) AddHeader ¶
AddHeader adds a header row to the table. Panics if the number of columns does not align with the number of columns of already existing table rows or if AddHeader is called after rows were added via AddRow or AddFooter.
Columns implementing console.Renderable are NOT formatted using the cell and column specific options (e.g. style, alignment, word wrap) configured via the table.With* and table.WithColumn* option funcs. This allows users to add custom cell behaviour if needed.
func (*Table) AddRow ¶
AddRow adds a row to the table. Panics if the number of columns does not align with the number of columns of already existing table rows or if AddRow is called after rows were added via AddFooter.
Columns implementing console.Renderable are NOT formatted using the cell and column specific options (e.g. style, alignment, word wrap) configured via the table.With* and table.WithColumn* option funcs. This allows users to add custom cell behaviour if needed.
func (*Table) Render ¶
Render renders the table to the underlying io.Writer. Returns an error if rendering failed.
func (*Table) RenderLines ¶
Render renders the table to the underlying io.Writer. Returns the number of lines rendered and an error if rendering failed.