frp/vendor/github.com/rodaine/table
fatedier dd8f788ca4 use dep instead of glide 2018-05-08 02:40:11 +08:00
..
.travis.yml packages: add package github.com/rodaine/table 2018-01-17 01:15:34 +08:00
license packages: add package github.com/rodaine/table 2018-01-17 01:15:34 +08:00
makefile packages: add package github.com/rodaine/table 2018-01-17 01:15:34 +08:00
readme.md packages: add package github.com/rodaine/table 2018-01-17 01:15:34 +08:00
table.go packages: add package github.com/rodaine/table 2018-01-17 01:15:34 +08:00

readme.md

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.