esxlib/pkg/pprint/human.go

33 lines
613 B
Go

package pprint
import (
"fmt"
"text/tabwriter"
)
// HumanPrinter prints tabulated data as a table
type HumanPrinter struct {
writer *tabwriter.Writer
fields int
}
// Headers specify the table headers
func (p *HumanPrinter) Headers(headers ...string) {
for _, header := range headers {
fmt.Fprintf(p.writer, "%s\t", header)
}
fmt.Fprintf(p.writer, "\n")
}
func (p *HumanPrinter) Fields(fields ...interface{}) {
for _, header := range fields {
fmt.Fprintf(p.writer, "%v\t", header)
}
fmt.Fprintf(p.writer, "\n")
}
// Flush prints the data set
func (p *HumanPrinter) Flush() {
p.writer.Flush()
}