Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomlazar/table
pretty colorfull tables in go with less effort
https://github.com/tomlazar/table
Last synced: 12 days ago
JSON representation
pretty colorfull tables in go with less effort
- Host: GitHub
- URL: https://github.com/tomlazar/table
- Owner: tomlazar
- License: mit
- Created: 2020-09-22T05:42:34.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-19T15:58:46.000Z (over 1 year ago)
- Last Synced: 2024-10-11T03:16:32.862Z (28 days ago)
- Language: Go
- Size: 119 KB
- Stars: 50
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - table - Small library for terminal color based tables. (Command Line / Advanced Console UIs)
- fucking-awesome-go - table - Small library for terminal color based tables. (Command Line / Advanced Console UIs)
- awesome-go - table - Small library for terminal color based tables. (Command Line / Advanced Console UIs)
- awesome-go - table - Small library for terminal color based tables . (Command Line / Advanced Console UIs)
- awesome-go-extra - table - 09-22T05:42:34Z|2022-06-29T15:29:38Z| (Build Automation / Advanced Console UIs)
- awesome-go-with-stars - table - Small library for terminal color based tables. (Command Line / Advanced Console UIs)
- awesome-go-plus - table - Small library for terminal color based tables. ![stars](https://img.shields.io/badge/stars-50-blue) ![forks](https://img.shields.io/badge/forks-3-blue) (Command Line / Advanced Console UIs)
- awesome-go-plus - table - Small library for terminal color based tables. (Command Line / Advanced Console UIs)
README
# Table
![Go](https://github.com/tomlazar/table/workflows/Go/badge.svg)
[![codecov](https://codecov.io/gh/tomlazar/table/branch/main/graph/badge.svg?token=F96DTCC4MC)](undefined)
[![GoDoc](https://godoc.org/github.com/tomlazar/table?status.svg)](http://godoc.org/github.com/tomlazar/table)
[![Go Report Card](https://goreportcard.com/badge/github.com/tomlazar/table)](https://goreportcard.com/report/github.com/tomlazar/table)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Ftomlazar%2Ftable.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Ftomlazar%2Ftable?ref=badge_shield)Print out tabular data on the command line using the ansi color esacape codes. Support for writing the ouput based on the fields in a struct and for defining and creating the table manully using the underlying object.
Support for colors on windows can be don using [mattn/go-colorable](https://github.com/mattn/go-colorable) to make a `io.Writer` that will work.
## Usage
For creating a table yourself using the struct.
```go
tab := table.Table{
Headers: []string{"something", "another"},
Rows: [][]string{
{"1", "2"},
{"3", "4"},
{"3", "a longer piece of text that should stretch"},
{"but this one is longer", "shorter now"},
},
}
err := tab.WriteTable(w, nil) // w is any io.Writer
```
![simple example](_examples/simple.png)With a struct slice
```go
data := []struct {
Name string `table:"THE NAME"`
Location string `table:"THE LOCATION"`
}{
{"name", "l"},
{"namgfcxe", "asfdad"},
{"namr3e", "l134151dsa"},
{"namear", "lasd2135"},
}err := table.MarshalTo(w, data, nil) // writes to any w = io.Writer
buf, err := table.Marshal(data, nil) // also supports return the bytes
```
![reflection](_examples/reflection.png)The nil parameter is the configuration for the table, this can be set manually, but if its left as nil the deafult config settings will be used.
```go
type Config struct {
ShowIndex bool // shows the index/row number as the first column
Color bool // use the color codes in the output
AlternateColors bool // alternate the colors when writing
TitleColorCode string // the ansi code for the title row
AltColorCodes []string // the ansi codes to alternate between
}
```## Installation
Go makes this part easy.
```bash
$ go get github.com/mattn/go-colorable
```## License
MIT
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Ftomlazar%2Ftable.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Ftomlazar%2Ftable?ref=badge_large)
## Author
Tom Lazar