Documentation ¶
Overview ¶
Package uitable provides a decorator for formating data as a table
Example ¶
package main import ( "fmt" "github.com/gosuri/uitable" ) type hacker struct { Name, Birthday, Bio string } var hackers = []hacker{ {"Ada Lovelace", "December 10, 1815", "Ada was a British mathematician and writer, chiefly known for her work on Charles Babbage's early mechanical general-purpose computer, the Analytical Engine"}, {"Alan Turing", "June 23, 1912", "Alan was a British pioneering computer scientist, mathematician, logician, cryptanalyst and theoretical biologist"}, } func main() { table := uitable.New() table.MaxColWidth = 50 fmt.Println("==> List") table.AddRow("NAME", "BIRTHDAY", "BIO") for _, hacker := range hackers { table.AddRow(hacker.Name, hacker.Birthday, hacker.Bio) } fmt.Println(table) fmt.Print("\n==> Details\n") table = uitable.New() table.MaxColWidth = 80 table.Wrap = true for _, hacker := range hackers { table.AddRow("Name:", hacker.Name) table.AddRow("Birthday:", hacker.Birthday) table.AddRow("Bio:", hacker.Bio) table.AddRow("") // blank } fmt.Println(table) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Separator = "\t"
Separator is the default column seperator
Functions ¶
This section is empty.
Types ¶
type Cell ¶
type Cell struct { // Width is the width of the cell Width uint // Wrap when true wraps the contents of the cell when the lenght exceeds the width Wrap bool // RightAlign when true aligns contents to the right RightAlign bool // Data is the cell data Data interface{} }
Cell represents a column in a row
type Row ¶
type Row struct { // Cells is the group of cell for the row Cells []*Cell // Separator for tabular columns Separator string }
Row represents a row in a table
type Table ¶
type Table struct { // Rows is the collection of rows in the table Rows []*Row // MaxColWidth is the maximum allowed width for cells in the table MaxColWidth uint // Wrap when set to true wraps the contents of the columns when the length exceeds the MaxColWidth Wrap bool // Separator is the seperator for columns in the table. Default is "\t" Separator string // contains filtered or unexported fields }
Table represents a decorator that renders the data in formatted in a table
func (*Table) RightAlign ¶
Directories ¶
Path | Synopsis |
---|---|
util
|
|
strutil
Package strutil provides various utilities for manipulating strings
|
Package strutil provides various utilities for manipulating strings |
wordwrap
Package wordwrap provides methods for wrapping the contents of a string
|
Package wordwrap provides methods for wrapping the contents of a string |
Click to show internal directories.
Click to hide internal directories.