table

package module
v0.0.0-...-af7769a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2018 License: MIT Imports: 6 Imported by: 0

README

table

Overview/docs: GoDoc

from:-

**Firstname**   **Lastname**    **Age**
Jill    Smith   50
Eve Jackson 45

to:-

╭─────────────╥────────────╥───────╮
│**Firstname**║**Lastname**║**Age**│
╞═════════════╬════════════╬═══════╡
│     Eve     ║   Jackson  ║   45  │
│     Jill    ║    Smith   ║   50  │
╰─────────────╨────────────╨───────╯

Notice: markdown tables can be simply converted, find/replace, to tab based sources for this package.

Documentation

Overview

package table prettifies tab/line text tables to aligned/formatted/sorted/rearranged and justified text tables.

Index

Examples

Constants

View Source
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

View Source
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 Centred

func Centred(c string, w int)

centre printer

func Fprint

func Fprint(w io.Writer, tabulated string, cellPrinters ...func(string, int))

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

func Fprintf(w io.Writer, s string, tabulated string, cellPrinters ...func(string, int))

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 LeftJustified

func LeftJustified(c string, w int)

left justifier printer

func MinWidth

func MinWidth(form func(string, int), min uint) func(string, int)

modify a cellPrinter to have a minimum width

func MoveToLeftEdge

func MoveToLeftEdge(column uint) func(int) int

returns a column mapper func, that puts a particular column first, (columns start from 1), otherwise preserves order.

func NumbersBoolJustified

func NumbersBoolJustified(c string, w int)

centre print if a boolean, right justify if a number, default otherwise.

func NumbersRightJustified

func NumbersRightJustified(c string, w int)

right justify if a number

func Print

func Print(tabulated string, cellPrinters ...func(string, int))

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   │
╰───────╨─────────────╨────────────╯

func Printf

func Printf(s string, tabulated string, cellPrinters ...func(string, int))

set global var 'Style' then call Print.

func RightJustified

func RightJustified(c string, w int)

right justifier printer

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL