table

Go CLI Table Generator

  • Owner: rodaine/table
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

table GoDoc Build Status

Example Table Output With ANSI Colors

Package table provides a convenient way to generate tabular output of any data, primarily useful for CLI tools.

Features

  • Accepts all data types (string, int, interface{}, everything!) and will use the String() string method of a type if available.
  • Can specify custom formatting for the header and first column cells for better readability.
  • Columns are left-aligned and sized to fit the data, with customizable padding.
  • The printed output can be sent to any io.Writer, defaulting to os.Stdout.
  • Built to an interface, so you can roll your own Table implementation.
  • Works well with ANSI colors (fatih/color in the example)!
  • Can provide a custom WidthFunc to accomodate multi- and zero-width characters (such as runewidth)

Usage

Download the package:

go get -u 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

Contributing

Please feel free to submit an issue or PR to this repository for features or bugs. All submitted code must pass the scripts specified within .travis.yml and should include tests to back up the changes.

License

table is released under the MIT License (Expat). See the full license.

Main metrics

Overview
Name With Ownerrodaine/table
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2015-09-17 01:02:56
Pushed At2025-02-24 16:53:00
Last Commit At2025-02-24 08:52:55
Release Count6
Last Release Namev1.3.0 (Posted on )
First Release Namev1.0.0 (Posted on )
用户参与
Stargazers Count290
Watchers Count3
Fork Count32
Commits Count33
Has Issues Enabled
Issues Count14
Issue Open Count1
Pull Requests Count24
Pull Requests Open Count2
Pull Requests Close Count5
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private