Documentation ¶
Overview ¶
The decoration package provides controls for how text tables are decorated for rendering. Unfortunately, this is a mix of functions which need to be accessible to package API callers and functions which should be internal to tabular. Tabular pre-dates the `internal/` system of Go and needs some refactoring.
The symbols from registry.go and styles.go are stable and part of the public API. The rest should probably move to become internal. If you find yourself using one of those, and know about it and have read this documentation, please consider opening an issue so that a future change for v2 will better support you.
Sorry about this mess.
Index ¶
Constants ¶
const ( D_ASCII_SIMPLE = "ascii-simple" D_NONE = "none" D_UTF8_LIGHT = "utf8-light" D_UTF8_LIGHT_CURVED = "utf8-light-curved" D_UTF8_HEAVY = "utf8-heavy" D_UTF8_DOUBLE = "utf8-double" )
The const-style names provide for language error-checking for those who explicitly import this package. Both this and just passing a string are supported. Package clients are allowed to register their own names, for which no const will be available here. Which to use is a trade-off for the client to choose.
Variables ¶
var EmptyDecoration = Decoration{}
EmptyDecoration is a non-decoration and is returned for named lookups for an unknown name.
Functions ¶
func RegisterDecorationName ¶
func RegisterDecorationName(name string, decor Decoration)
RegisterDecorationName declares a given name to provide a given style. Existing entries may be overwritten.
func RegisteredDecorationNames ¶
func RegisteredDecorationNames() []string
RegisteredDecorationNames returns a sorted list of registered decoration names.
Types ¶
type Decoration ¶
type Decoration struct { /* Our model tables: Minimal table: ┏━━━┳━━━━━━━┳━━━┓ +---+-------+---+ TopLeft HOuter HTopDown HOuter HTopDown HOuter TopRight ┃ C ┃ Name ┃ N ┃ | | | | VHeader ┣━━━╇━━━━━━━╇━━━┫ +---+-------+---+ HBLeft HOuter HBCross HOuter HBCross HOuter HBRight ┃ a │ Funky │ 1 ┃ | | | | VBodyBorder VBodyInner VBodyInner VBodyBorder ┃ b │ Hello │ 2 ┃ | | | | ┠───┼───────┼───┨ +---+-------+---+ LeftBodyRule HRule CrossPiece HRule CrossPiece HRule RightBodyRule ┃ c │ Final │ 3 ┃ | | | | ┗━━━┷━━━━━━━┷━━━┛ +---+-------+---+ BottomLeft HOuter BBottomUp HOuter BBottomUp HOuter BottomRight ┏━━━┯━━━━━━━┯━━━┓ +---+-------+---+ TopLeft HOuter BTopDown HOuter BTopDown HOuter TopRight ┃ o │ Only │ 0 ┃ | | | | ┗━━━┷━━━━━━━┷━━━┛ +---+-------+---+ No header-only tables; degenerate to: ┏━━━┳━━━━━━━┳━━━┓ ┃ C ┃ Name ┃ N ┃ ┣━━━╇━━━━━━━╇━━━┫ ┗━━━┷━━━━━━━┷━━━┛ */ Horizontal string // unused-for-render Vertical string // unused-for-render CrossPiece string TopDown string // unused-for-render VBorder string // unused-for-render HOuter string HRule string VHeader string VBodyBorder string VBodyInner string TopLeft string TopRight string BottomLeft string BottomRight string LeftBodyRule string RightBodyRule string HTopDown string BTopDown string BBottomUp string HBCross string HBLeft string HBRight string // contains filtered or unexported fields }
A Decoration holds the rules for drawing a table's lines. Some fields can be inferred from others if left empty. We currently use "string" rather than "rune"; if non-empty, the contents _must_ render as one terminal cell width. Multiple runes are allowed (combining chars, etc). TODO (low priority): measure width, handle non-one-cell-width characters.
func ASCIIBoxSimple ¶
func ASCIIBoxSimple() Decoration
ASCIIBoxSimple provides traditionalist boxes drawn with ASCII characters.
func Named ¶
func Named(n string) Decoration
Named returns the named decoration, or EmptyDecoration if the name is not known. The name is a simple string instead of typed, so as part of the point of this API is that callers don't need to explicitly import this package.
func UTF8BoxDouble ¶
func UTF8BoxDouble() Decoration
UTF8BoxDouble is similar to UTF8BoxHeavy but uses doubled lines instead of heavy lines. Note though that because of a missing character in Unicode, this should probably not be used for tables with headers (the interior cross-piece along the header/body boundary will not match up).
func UTF8BoxHeavy ¶
func UTF8BoxHeavy() Decoration
UTF8BoxHeavy provides boxes with a combination of heavy and light lines around borders and rules.
func UTF8BoxLight ¶
func UTF8BoxLight() Decoration
UTF8BoxLight provides boxes drawn from the BOX DRAWINGS LIGHT characters.
func UTF8BoxLightCurved ¶
func UTF8BoxLightCurved() Decoration
UTF8BoxLightCurved is very similar to UTF8BoxLight but rounds the corners.
func (*Decoration) ForColumnWidths ¶
func (d *Decoration) ForColumnWidths(widths []int) emitter
ForColumnWidths returns an emitter object with methods for getting table lines as strings.
func (*Decoration) Populate ¶
func (d *Decoration) Populate()
Populate fills in a table given some key points.
type DividerSet ¶
DividerSet provides the characters to use for vertical line-drawing when putting content into cells.
type WidthString ¶
func (WidthString) WithinWidth ¶
func (ws WidthString) WithinWidth(available int) string
func (WidthString) WithinWidthAligned ¶ added in v1.1.0
func (ws WidthString) WithinWidthAligned(available int, howAlign align.Alignment) string