tableprinter

Fast and easy-to-use table printer written in Go. Parse and print anywhere go values such as structs, slices, maps or any compatible value type as a table with ease.

Github星跟踪图

TablePrinter

tableprinter is an intelligent value-to-table formatter and writer. It uses a customized version of olekukonko/tablewriter to render a result table.

It checks every in data and transforms those data(structure values, slices, maps, single lists that may contain different type of values such as go standard values like int, string even a value that implements the fmt.Stringer interface) to a table formatted text and outputs it to an io.Writer. Like encoding/json#Encode but for tables.

build status report card godoc
examples

Installation

The only requirement is the Go Programming Language, at least version 1.10.

$ go get -u github.com/landoop/tableprinter
package main

import (
    "os"
    "sort"

    "github.com/kataras/tablewriter"
    "github.com/landoop/tableprinter"
)

type person struct {
    Firstname string `header:"first name"`
    Lastname  string `header:"last name"`
}

func main() {
    printer := tableprinter.New(os.Stdout)
    persons := []person{
        {"Chris", "Doukas"},
        {"Georgios", "Callas"},
        {"Ioannis", "Christou"},
        {"Nikolaos", "Doukas"},
        {"Dimitrios", "Dellis"},
    }

    sort.Slice(persons, func(i, j int) bool {
        return persons[j].Firstname > persons[i].Firstname
    })

    // Optionally, customize the table, import of the underline 'tablewriter' package is required for that.
    printer.BorderTop, printer.BorderBottom, printer.BorderLeft, printer.BorderRight = true, true, true, true
    printer.CenterSeparator = "│"
    printer.ColumnSeparator = "│"
    printer.RowSeparator = "─"
    printer.HeaderBgColor = tablewriter.BgBlackColor
    printer.HeaderFgColor = tablewriter.FgGreenColor

    // Print the slice of structs as table, as shown above.
    printer.Print(persons)
}

Examples

Versioning

Current: v0.0.3

Read more about Semantic Versioning 2.0.0

License

Distributed under Apache Version 2.0, see LICENSE for more information.

主要指标

概览
名称与所有者lensesio/tableprinter
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证Apache License 2.0
所有者活动
创建于2018-06-16 23:09:10
推送于2020-11-25 13:58:49
最后一次提交2020-11-25 15:58:48
发布数2
最新版本名称0.0.3 (发布于 )
第一版名称0.0.2 (发布于 )
用户参与
星数78
关注者数22
派生数19
提交数49
已启用问题?
问题数5
打开的问题数4
拉请求数3
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?