tabitha is a no-frills tabular formatter for the terminal.
- 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
go test -v -race -cover ./...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)
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.
This project is licensed under Apache 2.0.