table

package module
v0.0.0-...-68a841c Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2018 License: MIT Imports: 5 Imported by: 11

README

go-table

Travis CI

A small library for formatting fluid tables for the CLI.

Usage

You start with a table.NewTable(), to define your headers:

t := table.NewTable("#", "Name", "Notes", "Status")

Then, for each thing you want to tabularize, just call t.Row(), passing it a nil first argument and the values for each column:

t.Row(nil, 1, "Foo", "lorem ipsum dolor sit amet...", "GOOD")
t.Row(nil, 2, "Bar", "you can even have\nembedded newlines...", "GOOD")

Finally, to print it, call t.Output(), passing it the io.Writer you want it to print to (like os.Stdout):

t.Output(os.Stdout)

Those four lines render the following table, effortlessly:

#  Name  Notes                          Status
=  ====  =====                          ======
1  Foo   lorem ipsum dolor sit amet...  GOOD
2  Bar   you can even have              GOOD
         embedded newlines...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell []string

func ParseCell

func ParseCell(s string) Cell

func (Cell) Height

func (c Cell) Height() int

func (Cell) Line

func (c Cell) Line(i int) string

func (Cell) Width

func (c Cell) Width() int

type Grid

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

func NewGrid

func NewGrid(header ...string) Grid

func NewIndexedGrid

func NewIndexedGrid(header ...string) Grid

func (*Grid) Columns

func (t *Grid) Columns() int

func (Grid) Height

func (t Grid) Height() int

func (*Grid) Line

func (t *Grid) Line(n int) string

func (*Grid) Lines

func (t *Grid) Lines() []string

func (*Grid) Row

func (t *Grid) Row(vv ...interface{})

type Row

type Row []Cell

func ParseRow

func ParseRow(ss ...string) Row

func (Row) Height

func (r Row) Height() int

func (Row) Width

func (r Row) Width() int

type Table

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

func NewTable

func NewTable(header ...string) Table

func (*Table) Object

func (t *Table) Object(i int) interface{}

func (*Table) Output

func (t *Table) Output(out io.Writer)

func (*Table) OutputWithIndices

func (t *Table) OutputWithIndices(out io.Writer)

func (*Table) Row

func (t *Table) Row(object interface{}, cells ...interface{})

func (*Table) Rows

func (t *Table) Rows() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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