tbl is a simple way to print text tables.
go get -u github.com/alligator/tbl
package main
import (
"fmt"
"github.com/alligator/tbl"
)
type row struct {
id int
name string
}
func main() {
rows := []row{
{1, "gate"},
{2, "boop"},
}
t := tbl.NewTable()
for _, row := range rows {
t.NewRow()
t.NewCol("Id")
t.Printf("%d", row.id)
t.NewCol("Name")
t.Print(row.name)
}
fmt.Print(t.String())
}This will print this table:
| Id | Name |
| -- | ---- |
| 1 | gate |
| 2 | boop |
There is also a minimal style, with no column and row separators. Use it like so:
t := tbl.NewTable()
t.Style = tbl.StyleMinimalMinimal tables looks like this:
ID NAME
1 gate
2 boop