Go CLI Table Generator
See the code
Package table provides a convenient way to generate tabular output of any data, primarily useful for CLI tools.
string, int, interface{}, everything!) and will use the String() string method of a type if available.io.Writer, defaulting to os.Stdout.Table implementation.WidthFunc to accomodate multi- and zero-width characters (such as runewidth)Download the package:
go get github.com/rodaine/table
Example:
package main
import (
"fmt"
"strings"
"github.com/fatih/color"
"github.com/rodaine/table"
)
func main() {
headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc()
columnFmt := color.New(color.FgYellow).SprintfFunc()
tbl := table.New("ID", "Name", "Score", "Added")
tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt)
for _, widget := range getWidgets() {
tbl.AddRow(widget.ID, widget.Name, widget.Cost, widget.Added)
}
tbl.Print()
}
Consult the documentation for further examples and usage information
table is released under the MIT License (Expat). See the full license.
1,807 followers · starred Jan 2024
43 followers · starred Feb 2023
25 followers · starred Dec 2023
500 followers · starred May 2023
Go CLI Table Generator
See the code
Package table provides a convenient way to generate tabular output of any data, primarily useful for CLI tools.
string, int, interface{}, everything!) and will use the String() string method of a type if available.io.Writer, defaulting to os.Stdout.Table implementation.WidthFunc to accomodate multi- and zero-width characters (such as runewidth)Download the package:
go get github.com/rodaine/table
Example:
package main
import (
"fmt"
"strings"
"github.com/fatih/color"
"github.com/rodaine/table"
)
func main() {
headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc()
columnFmt := color.New(color.FgYellow).SprintfFunc()
tbl := table.New("ID", "Name", "Score", "Added")
tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt)
for _, widget := range getWidgets() {
tbl.AddRow(widget.ID, widget.Name, widget.Cost, widget.Added)
}
tbl.Print()
}
Consult the documentation for further examples and usage information
table is released under the MIT License (Expat). See the full license.
1,807 followers · starred Jan 2024
43 followers · starred Feb 2023
25 followers · starred Dec 2023
500 followers · starred May 2023