Documentation
¶
Overview ¶
Package table renders a result table as an ansi box-drawing table on a terminal and as markdown everywhere else. The style constants are shared so every command that prints a table looks like the same program.
Index ¶
Constants ¶
const ( BoxTopLeft = "╭" BoxTopRight = "╮" BoxBottomLeft = "╰" BoxBottomRight = "╯" BoxHorizontal = "─" BoxVertical = "│" BoxTeeDown = "┬" BoxTeeUp = "┴" BoxTeeRight = "├" BoxTeeLeft = "┤" BoxCross = "┼" )
Box drawing characters of the ansi table.
const ( ColorReset = "\033[0m" ColorSeparator = "\033[38;5;238m" ColorHeader = "\033[38;5;146m" ColorAmber = "\033[38;5;214m" ColorGreen = "\033[38;5;114m" ColorWhite = "\033[38;5;255m" ColorRed = "\033[38;5;167m" ColorDim = "\033[38;5;244m" )
Colors of the ansi table. They are 256-color codes rather than the basic eight, so a row keeps the same shade whatever palette the terminal ships.
Variables ¶
This section is empty.
Functions ¶
func IsTerminal ¶
IsTerminal reports whether w is a tty, which is what decides between the box-drawing table and markdown when the caller has not said which it wants.
Types ¶
type Cell ¶
Cell is one value and the color it is printed in. The color is dropped in markdown, so a caller sets it once rather than branching per output format.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table buffers rows and renders them once the widest cell of every column is known. A check that collects its findings before reporting them gains nothing from streaming, and a buffered table sizes its columns from the data rather than guessing at them up front.
func New ¶
New returns a table writing to w. Markdown is what a redirected stdout and a report file get; a terminal gets the box-drawing table.
func (*Table) Flush ¶
func (t *Table) Flush()
Flush writes the table. It is called once: the rows are kept so the columns can be sized, not so the table can be reprinted.
func (*Table) Row ¶
Row appends a row. Cells past the last column are dropped and missing ones are left empty, so a caller never has to pad a short row itself.