Documentation ¶
Overview ¶
package table prettifies tab/line text tables to aligned/formatted/sorted/rearranged and justified text tables.
Index ¶
- Constants
- Variables
- func Centred(c string, w int)
- func Fprint(w io.Writer, tabulated string, cellPrinters ...func(string, int))
- func Fprintf(w io.Writer, s string, tabulated string, cellPrinters ...func(string, int))
- func LeftJustified(c string, w int)
- func MinWidth(form func(string, int), min uint) func(string, int)
- func MoveToLeftEdge(column uint) func(int) int
- func NumbersBoolJustified(c string, w int)
- func NumbersRightJustified(c string, w int)
- func Print(tabulated string, cellPrinters ...func(string, int))
- func Printf(s string, tabulated string, cellPrinters ...func(string, int))
- func RightJustified(c string, w int)
Examples ¶
Constants ¶
const ( ASCIIStyle string = "+-++| ||" ASCIIBoxStyle string = "+-+++-++| ||+-++" MarkdownStyle string = "|-||| ||" BoxStyle string = "┌─┬┐├─┼┤│ ││└─┴┘" DoubleBoxStyle string = "╔═╦╗╠═╬╣║ ║║╚═╩╝" ThickHeaderDivideBoxStyle string = "┌─┬┐┝━┿┥│ ││└─┴┘" DoubleBorderBoxStyle string = "╔═╤╗╟─┼╢║ │║╚═╧╝" DoubleVerticalBoxStyle string = "╓─╥╖╟─╫╢║ ║║╙─╨╜" DoubleHorizontalBoxStyle string = "╒═╤╕╞═╪╡│ ││╘═╧╛" DoubleSingleHorizontalBoxStyle string = "╔═╤╗╠═╪╣║ │║╚═╧╝" DoubleTopBottomBoxStyle string = "╒═╤╕├─┼┤│ ││╘═╧╛" DoubleSidesBoxStyle string = "╓─┬╖╟─┼╢║ │║╙─┴╜" DoubleTopBoxStyle string = "╒═╤╕├─┼┤│ ││└─┴┘" DoubleDivideBoxStyle string = "┌─┬┐╞═╪╡│ ││└─┴┘" DoubleBottomBoxStyle string = "┌─┬┐├─┼┤│ ││╘═╧╛" DoubleRightBoxStyle string = "┌─┬╖├─┼┤│ ││└─┴╜" DoubleLeftBoxStyle string = "╓─┬┐╟─┼┤║ ││╙─┴┘" DoubleInsideBoxStyle string = "┌─╥┐╞═╬╡│ ║│└─╨┘" DoubleInsideVerticalBoxStyle string = "┌─╥┐├─╫┤│ ║│└─╨┘" DoubleInsideHorizontalBoxStyle string = "┌─┬┐╞═╪╡│ ││└─┴┘" RoundedBoxStyle string = "╭─┬╮├─┼┤│ ││╰─┴╯" RoundedDoubleInsideBoxStyle string = "╭─╥╮╞═╬╡│ ║│╰─╨╯" RoundedDoubleInsideHorizontalBoxStyle string = "╭─┬╮╞═╪╡│ ││╰─┴╯" RoundedDoubleInsideVerticalBoxStyle string = "╭─╥╮├─╫┤│ ║│╰─╨╯" )
built-in Styles
Variables ¶
var ( Writer io.Writer HeaderRows = 1 Style = MarkdownStyle ColumnMapper func(int) int // rearrange columns SortColumn int NumericNotAlphaSort bool DefaultCellPrinter = Centred DividerEvery int FormfeedWithDivider bool )
global options
Functions ¶
func Fprint ¶
set global var 'Writer' then call Print.
Example ¶
Fprint(os.Stdout, "**Firstname**\t**Lastname**\t**Age**\nJill\tSmith\t50\nEve\tJackson\t45")
Output: |**Firstname**|**Lastname**|**Age**| |-------------|------------|-------| | Jill | Smith | 50 | | Eve | Jackson | 45 |
func Fprintf ¶
set the global var's 'Writer' and 'Style' then call Print.
Example ¶
Fprintf(os.Stdout, BoxStyle, "**Firstname**\t**Lastname**\t**Age**\nJill\tSmith\t50\nEve\tJackson\t45")
Output: ┌─────────────┬────────────┬───────┐ │**Firstname**│**Lastname**│**Age**│ ├─────────────┼────────────┼───────┤ │ Jill │ Smith │ 50 │ │ Eve │ Jackson │ 45 │ └─────────────┴────────────┴───────┘
func MoveToLeftEdge ¶
returns a column mapper func, that puts a particular column first, (columns start from 1), otherwise preserves order.
func NumbersBoolJustified ¶
centre print if a boolean, right justify if a number, default otherwise.
func Print ¶
Write 'tabulated' string as text table, rows coming from lines, columns separated by the tab character. Mono-spaced font required for alignment. cellPrinters - applied to columns: * missing - use default * len=1 - use for all cells * len=n - use n'th for n'th column, use default if column count>n Not thread safe, uses globals for options (see variables), however can be used multiple, fixed count, times by using multiple imports and different aliases. Unicode supporting.
Example ¶
Writer = os.Stdout Style = RoundedDoubleInsideBoxStyle ColumnMapper = MoveToLeftEdge(3) SortColumn = 1 Print("**Firstname**\t**Lastname**\t**Age**\nJill\tSmith\t50\nEve\tJackson\t45", RightJustified, Centred)
Output: ╭───────╥─────────────╥────────────╮ │**Age**║**Firstname**║**Lastname**│ ╞═══════╬═════════════╬════════════╡ │ 45║ Eve ║ Jackson │ │ 50║ Jill ║ Smith │ ╰───────╨─────────────╨────────────╯
Types ¶
This section is empty.