Documentation
¶
Overview ¶
Package tabular implements a simple tabular formatter for text.
The package is an alternative to text/tabwriter for some use cases. In comparison with text/tabwriter, this package:
- Is oriented around rows and cells, not tab-delimited text
- Inserts padding between cells, not after each cell
- Does not count padding toward min-width
- Does not insert any padding after the last cell of each row
- Allows for per-cell right-alignment
- Omits several lesser-used features of tabwriter
- Attempts to guess the width of multibyte code points
- Ignores ANSI CSI sequences
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
A Buffer stores rows of text and prints them as a table.
To calculate the width of a table cell, it strips out any ANSI CSI sequences from the text and then uses go-runewidth to guess the width of the resulting text.
Example ¶
package main
import (
"os"
"github.com/cespare/tabular"
)
func main() {
b := tabular.New(tabular.Options{Padding: 2, PadChar: ' ', AlignRight: true})
b.AddRow("x", "x²", "x³")
for _, x := range []float64{0, 4, 8, 12} {
b.AddRow(x, x*x, x*x*x)
}
b.WriteTo(os.Stdout)
}
Output: x x² x³ 0 0 0 4 16 64 8 64 512 12 144 1728
Click to show internal directories.
Click to hide internal directories.