github.com/alligator/tbl

A simple way to print tables


License
MIT
Install
go get github.com/alligator/tbl

Documentation

tbl

tbl is a simple way to print text tables.

Go Reference

Installing

go get -u github.com/alligator/tbl

Example

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.StyleMinimal

Minimal tables looks like this:

ID  NAME
1   gate
2   boop