Documentation ¶
Overview ¶
Package simpletable allows to generate and display ascii tables in the terminal, f.e.:
+----+------------------+--------------+-----------------------------+------+ | # | NAME | PHONE | EMAIL | QTTY | +----+------------------+--------------+-----------------------------+------+ | 1 | Newton G. Goetz | 252-585-5166 | NewtonGGoetz@dayrep.com | 10 | | 2 | Rebecca R. Edney | 865-475-4171 | RebeccaREdney@armyspy.com | 12 | | 3 | John R. Jackson | 810-325-1417 | JohnRJackson@armyspy.com | 15 | | 4 | Ron J. Gomes | 217-450-8568 | RonJGomes@rhyta.com | 25 | | 5 | Penny R. Lewis | 870-794-1666 | PennyRLewis@rhyta.com | 5 | | 6 | Sofia J. Smith | 770-333-7379 | SofiaJSmith@armyspy.com | 3 | | 7 | Karlene D. Owen | 231-242-4157 | KarleneDOwen@jourrapide.com | 12 | | 8 | Daniel L. Love | 978-210-4178 | DanielLLove@rhyta.com | 44 | | 9 | Julie T. Dial | 719-966-5354 | JulieTDial@jourrapide.com | 8 | | 10 | Juan J. Kennedy | 908-910-8893 | JuanJKennedy@dayrep.com | 16 | +----+------------------+--------------+-----------------------------+------+ | Subtotal | 150 | +----+------------------+--------------+-----------------------------+------+
There are the following key features:
* Declarative style. Have to write more code, and hell with it.
* Styling. With 6 predefined styles: MySql-like (default), compact, compact lite, markdown, rounded and unicode. And you can change it.
* Header and footer. Separeted from table body.
* Multiline cells support. See https://github.com/alexeyco/simpletable/blob/master/_example/04-multiline/main.go for example.
* cellInterface content alignment. Left, right or center.
* Row spanning. By analogy with the way it is done in HTML. See Cell.Span attribute description.
* Fast! Really fast, see https://github.com/alexeyco/simpletable/blob/master/_example/03-benchmarks-with-others
Examples: https://github.com/alexeyco/simpletable/tree/master/_example
Index ¶
Constants ¶
const ( // AlignLeft sets cell left alignment (default) AlignLeft = 0 // AlignCenter sets cell center alignment AlignCenter = 1 // AlignRight sets cell right alignment AlignRight = 2 )
Variables ¶
var ( // StyleDefault - MySql-like table style: // // +---+------------------+------------+ // | # | NAME | TAX | // +---+------------------+------------+ // | 1 | Newton G. Goetz | $ 532.70 | // | 2 | Rebecca R. Edney | $ 1423.25 | // | 3 | John R. Jackson | $ 7526.12 | // | 4 | Ron J. Gomes | $ 123.84 | // | 5 | Penny R. Lewis | $ 3221.11 | // +---+------------------+------------+ // | | Subtotal | $ 12827.02 | // +---+------------------+------------+ StyleDefault = &Style{ Border: &BorderStyle{ TopLeft: "+", Top: "-", TopRight: "+", Right: "|", BottomRight: "+", Bottom: "-", BottomLeft: "+", Left: "|", TopIntersection: "+", BottomIntersection: "+", }, Divider: &DividerStyle{ Left: "+", Center: "-", Right: "+", Intersection: "+", }, Cell: "|", } // StyleCompact - compact table style: // // # NAME TAX // === ================== ============ // 1 Newton G. Goetz $ 532.70 // 2 Rebecca R. Edney $ 1423.25 // 3 John R. Jackson $ 7526.12 // 4 Ron J. Gomes $ 123.84 // 5 Penny R. Lewis $ 3221.11 // === ================== ============ // Subtotal $ 12827.02 StyleCompact = &Style{ Border: &BorderStyle{ TopLeft: "", Top: "", TopRight: "", Right: "", BottomRight: "", Bottom: "", BottomLeft: "", Left: "", TopIntersection: "", BottomIntersection: "", }, Divider: &DividerStyle{ Left: "", Center: "=", Right: "", Intersection: " ", }, Cell: " ", } // StyleCompactLite - compact lite table style: // // # NAME TAX // --- ------------------ ------------ // 1 Newton G. Goetz $ 532.70 // 2 Rebecca R. Edney $ 1423.25 // 3 John R. Jackson $ 7526.12 // 4 Ron J. Gomes $ 123.84 // 5 Penny R. Lewis $ 3221.11 // --- ------------------ ------------ // Subtotal $ 12827.02 StyleCompactLite = &Style{ Border: &BorderStyle{ TopLeft: "", Top: "", TopRight: "", Right: "", BottomRight: "", Bottom: "", BottomLeft: "", Left: "", TopIntersection: "", BottomIntersection: "", }, Divider: &DividerStyle{ Left: "", Center: "-", Right: "", Intersection: " ", }, Cell: " ", } // StyleCompactClassic - compact classic table style: // // # NAME TAX // 1 Newton G. Goetz $ 532.70 // 2 Rebecca R. Edney $ 1423.25 // 3 John R. Jackson $ 7526.12 // 4 Ron J. Gomes $ 123.84 // 5 Penny R. Lewis $ 3221.11 // Subtotal $ 12827.02 StyleCompactClassic = &Style{ Border: &BorderStyle{ TopLeft: "", Top: "", TopRight: "", Right: "", BottomRight: "", Bottom: "", BottomLeft: "", Left: "", TopIntersection: "", BottomIntersection: "", }, Divider: &DividerStyle{ Left: "", Center: "", Right: "", Intersection: " ", }, Cell: " ", } // StyleMarkdown - markdown table style: // // | # | NAME | TAX | // |---|------------------|------------| // | 1 | Newton G. Goetz | $ 532.70 | // | 2 | Rebecca R. Edney | $ 1423.25 | // | 3 | John R. Jackson | $ 7526.12 | // | 4 | Ron J. Gomes | $ 123.84 | // | 5 | Penny R. Lewis | $ 3221.11 | // |---|------------------|------------| // | | Subtotal | $ 12827.02 | StyleMarkdown = &Style{ Border: &BorderStyle{ TopLeft: "", Top: "", TopRight: "", Right: "|", BottomRight: "", Bottom: "", BottomLeft: "", Left: "|", TopIntersection: "", BottomIntersection: "", }, Divider: &DividerStyle{ Left: "|", Center: "-", Right: "|", Intersection: "|", }, Cell: "|", } // StyleRounded - rounded table style: // // .---.------------------.------------. // | # | NAME | TAX | // +---+------------------+------------+ // | 1 | Newton G. Goetz | $ 532.70 | // | 2 | Rebecca R. Edney | $ 1423.25 | // | 3 | John R. Jackson | $ 7526.12 | // | 4 | Ron J. Gomes | $ 123.84 | // | 5 | Penny R. Lewis | $ 3221.11 | // +---+------------------+------------+ // | | Subtotal | $ 12827.02 | // '---'------------------'------------' StyleRounded = &Style{ Border: &BorderStyle{ TopLeft: ".", Top: "-", TopRight: ".", Right: "|", BottomRight: "'", Bottom: "-", BottomLeft: "'", Left: "|", TopIntersection: ".", BottomIntersection: "'", }, Divider: &DividerStyle{ Left: "+", Center: "-", Right: "+", Intersection: "+", }, Cell: "|", } // StyleUnicode - unicode (awesome!!!) table style: StyleUnicode = &Style{ Border: &BorderStyle{ TopLeft: "╔", Top: "═", TopRight: "╗", Right: "║", BottomRight: "╝", Bottom: "═", BottomLeft: "╚", Left: "║", TopIntersection: "╤", BottomIntersection: "╧", }, Divider: &DividerStyle{ Left: "╟", Center: "━", Right: "╢", Intersection: "┼", }, Cell: "│", } )
Functions ¶
This section is empty.
Types ¶
type BorderStyle ¶
type BorderStyle struct { TopLeft string Top string TopRight string Right string BottomRight string Bottom string BottomLeft string Left string TopIntersection string BottomIntersection string }
BorderStyle defines table border style
type Cell ¶
type Cell struct { Align int // Cell alignment Span int // span cell to right (1 - default) Text string // Cell raw text // contains filtered or unexported fields }
Cell is a table cell
type DividerStyle ¶
DividerStyle defines table divider style
type Style ¶
type Style struct { Border *BorderStyle Divider *DividerStyle Cell string // Symbol between cells }
Style is a table style (borders, dividers etc)