Documentation ¶
Overview ¶
Package tabulator provides a generic interface for tabulating data (to CSV, to tabwriter, etc).
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CsvLineWriter ¶
CsvLineWriter wraps a csv.Writer to make it a LineWriter.
func (*CsvLineWriter) Flush ¶
func (c *CsvLineWriter) Flush() error
func (*CsvLineWriter) Write ¶
func (c *CsvLineWriter) Write(cells []string) error
type LineTabulator ¶
type LineTabulator struct {
// contains filtered or unexported fields
}
LineTabulator uses a LineWriter to tabulate a table.
func NewLineTabulator ¶
func NewLineTabulator(w LineWriter) *LineTabulator
NewLineTabulator constructs a new tabulator using a LineWriter w.
func (*LineTabulator) Cell ¶
func (t *LineTabulator) Cell(value interface{}) RowTabulator
func (*LineTabulator) EndRow ¶
func (t *LineTabulator) EndRow() Tabulator
func (LineTabulator) Flush ¶
func (t LineTabulator) Flush() error
func (*LineTabulator) Header ¶
func (t *LineTabulator) Header(labels ...string)
type LineWriter ¶
type LineWriter interface { // Write writes a single row with the given cells. Write(cells []string) error // Flush commits any lines written to the writer. Flush() error }
LineWriter can write table lines to some underlying flushable writer.
type RowTabulator ¶
type RowTabulator interface { // Cell adds some representation of the given cell value to the table's current row. Cell(value interface{}) RowTabulator // EndRow ends the current row. EndRow() Tabulator }
RowTabulator is the interface of things that can tabulate a row. Each method should return the current or parent tabulator for method chaining.
type TabLineWriter ¶
TabLineWriter wraps a tabwriter.Writer to make it a LineWriter.
func (*TabLineWriter) Flush ¶
func (t *TabLineWriter) Flush() error
func (*TabLineWriter) Write ¶
func (t *TabLineWriter) Write(cells []string) error
type Tabulator ¶
type Tabulator interface { // Header adds a header to the current table, if one has not yet been set. // Tabulators should silently ignore attempts to install a duplicate header; this means that sub-table functions // can call Header even if the parent table calls Header. Header(labels ...string) RowTabulator // Flush commits the table to the underlying writer, returning any error that occurred during tabulation. Flush() error }
Tabulator is the interface of things that can create tables.
func NewCsv ¶
NewCsv constructs a Tabulator that outputs CSV to w.
Example ¶
ExampleNewCsv is a runnable example for NewCsv.
package main import ( "fmt" "os" "github.com/c4-project/c4t/internal/tabulator" ) func main() { w := tabulator.NewCsv(os.Stdout) w.Header("Country", "Code") w.Cell("USA").Cell(1).EndRow() w.Cell("UK").Cell(int64(44)).EndRow() if err := w.Flush(); err != nil { fmt.Println(err) } }
Output: Country,Code USA,1 UK,44
func NewTab ¶
NewTab constructs a Tabulator that outputs elastic-tabbed human-readable output to w.
Example ¶
ExampleNewTab is a runnable example for NewTab.
package main import ( "fmt" "os" "github.com/c4-project/c4t/internal/tabulator" ) func main() { w := tabulator.NewTab(os.Stdout) w.Header("Country", "Code") w.Cell("USA").Cell(1).EndRow() w.Cell("UK").Cell(int64(44)).EndRow() if err := w.Flush(); err != nil { fmt.Println(err) } }
Output: Country Code USA 1 UK 44