table

Go CLI Table Generator

  • 所有者: rodaine/table
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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.

主要指标

概览
名称与所有者rodaine/table
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2015-09-17 01:02:56
推送于2025-02-24 16:53:00
最后一次提交2025-02-24 08:52:55
发布数6
最新版本名称v1.3.0 (发布于 )
第一版名称v1.0.0 (发布于 )
用户参与
星数290
关注者数3
派生数32
提交数33
已启用问题?
问题数14
打开的问题数1
拉请求数24
打开的拉请求数2
关闭的拉请求数5
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?