You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Print out tabular data on the command line using the ansi color esacape codes. Support for writing the ouput based on the fields in a struct and for defining and creating the table manully using the underlying object.
Support for colors on windows can be don using mattn/go-colorable to make a io.Writer that will work.
Usage
For creating a table yourself using the struct.
tab:= table.Table{
Headers: []string{"something", "another"},
Rows: [][]string{
{"1", "2"},
{"3", "4"},
{"3", "a longer piece of text that should stretch"},
{"but this one is longer", "shorter now"},
},
}
err:=tab.WriteTable(w, nil) // w is any io.Writer
With a struct slice
data:= []struct {
Namestring`table:"THE NAME"`Locationstring`table:"THE LOCATION"`
}{
{"name", "l"},
{"namgfcxe", "asfdad"},
{"namr3e", "l134151dsa"},
{"namear", "lasd2135"},
}
err:=table.MarshalTo(w, data, nil) // writes to any w = io.Writerbuf, err:=table.Marshal(data, nil) // also supports return the bytes
The nil parameter is the configuration for the table, this can be set manually, but if its left as nil the deafult config settings will be used.
typeConfigstruct {
ShowIndexbool// shows the index/row number as the first columnColorbool// use the color codes in the outputAlternateColorsbool// alternate the colors when writingTitleColorCodestring// the ansi code for the title rowAltColorCodes []string// the ansi codes to alternate between
}