https://github.com/jimschubert/tabitha
tabitha is a no-frills tabular formatter for the terminal.
https://github.com/jimschubert/tabitha
go golang tables
Last synced: 4 months ago
JSON representation
tabitha is a no-frills tabular formatter for the terminal.
- Host: GitHub
- URL: https://github.com/jimschubert/tabitha
- Owner: jimschubert
- License: apache-2.0
- Created: 2021-10-20T23:54:58.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-15T17:24:25.000Z (almost 3 years ago)
- Last Synced: 2025-04-09T12:11:12.613Z (6 months ago)
- Topics: go, golang, tables
- Language: Go
- Homepage: https://pkg.go.dev/github.com/jimschubert/tabitha
- Size: 15.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# tabitha
tabitha is a no-frills tabular formatter for the terminal.
[](./LICENSE)

[](https://github.com/jimschubert/tabitha/actions/workflows/build.yml)
[](https://goreportcard.com/report/github.com/jimschubert/tabitha)## Features
* Supports padding output to the longest _display_ text, honoring ANSI colors
* Simple API to add a single header and 0..n lines
* Add "spacer" lines anywhere in the table. Character output is automatically calculated based on width of other text.
* Customize line separator, padding character, disable padding or honoring ansi## Build/Test
```shell
go test -v -race -cover ./...
```## Example
The following example demonstrates usage (sans error handling).
```
tt := tabitha.NewWriter()
tt.Header("First", "Second", "Third", "Fourth")
tt.SpacerLine()
tt.AddLine("I'm first", "I'm second", "I'm third", "I'm fourth")
tt.SpacerLine()
tt.WriteTo(os.Stdout)
```## Why not text/tabwriter?
This is a little different from `text/tabwriter`; a main difference being that tabwriter assumes all runes are the same size and includes ANSI codes in width calculations while `tabitha` does not.
In `tabitha`, rune width is evaluated using `utf8.RuneCountInString`. When ANSI support is enabled, `tabitha` will extract non-ANSI text (the "displayable text") using regex. Since `tabitha` collects all tabular text before writing out to a target `io.Writer`, it is not expected to perform as well as `tabwriter`.
## License
This project is [licensed](./LICENSE) under Apache 2.0.