gotable

package module
v0.0.0-...-9606065 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2021 License: MIT Imports: 7 Imported by: 1

README

gotable

Build Status Go ReportCard GoDoc

Go helper to print a table of data to stdout or an io.Writer.

Installation

go get github.com/muesli/gotable

Example

package main

import (
	"github.com/muesli/gotable"
)

func main() {
	tab := gotable.NewTable([]string{"Fruit", "Yumminess", "Color"},
		[]int64{-40, -20, 15},
		"No data in table.")

	tab.AppendRow([]interface{}{"Banana", "very", "yellow"})
	tab.AppendRow([]interface{}{"Pear", "much", "depends"})
	tab.AppendRow([]interface{}{"Pineapple", "delicious", "pineappley"})

	tab.Print()
}

What it looks like

Fruit                                     Yumminess                       Color
-------------------------------------------------------------------------------
Banana                                    very                           yellow
Pear                                      much                          depends
Pineapple                                 delicious                  pineappley

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is a helper for printing data in sheet form

func NewTable

func NewTable(headers []string, widths []int64, emptyText string) Table

NewTable returns a new table

func NewTableWithWriter

func NewTableWithWriter(headers []string, widths []int64, emptyText string, writer io.Writer) Table

NewTable returns a new table

func (*Table) AppendRow

func (t *Table) AppendRow(row []interface{})

AppendRow adds a row to the end of the table

func (*Table) Print

func (t *Table) Print() error

Print writes the entire table to stdout

func (*Table) PrintSummary

func (t *Table) PrintSummary() error

PrintSummary writes the table summary to stdout

func (*Table) SetSummary

func (t *Table) SetSummary(summary []interface{})

SetSummary sets a summary for this table, to be printed below the table

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL