pretty

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2018 License: MIT Imports: 6 Imported by: 0

README

pretty

A library for formatting and printing objects to the command line in Golang. Currently, it only has support for tables.

Licensing

This library is MIT-licensed.

Example

table, err := pretty.NewPrettyTable(
  pretty.NewColumnDef("Name"),
  pretty.NewColumnDef("Type"))
if err != nil {
	return err
}

table.SetHeader("People")

table.AddRow("Noel", "Human")
table.AddRow("David", "Cyborg")
table.AddRow("Pranava", "Crusher")

table.Print()
--------
 People |
+---------+---------+
| Name    | Type    |
+---------+---------+
|    Noel |   Human |
|   David |  Cyborg |
| Pranava | Crusher |
+---------+---------+

Testing

Run go test -vet="" -short -v ./....

Get involved

We are happy to receive bug reports, fixes, documentation enhancements, and other improvements.

Please report bugs via the github issue tracker.

Contributions will be accepted only after the execution of a Contributor License Agreement.

Documentation

Overview

Package pretty provides a utility to print out organized data in a pretty manner.

Table can be used as thus: prettyTable, _ := NewPrettyTable(

NewColumnDef("Name"),
NewColumnDef("Type"))

prettyTable.AddRow("Noel", "Human") prettyTable.AddRow("David", "Cyborg") prettyTable.AddRow("Pranava", "Crusher") prettyTable.Print()

Output looks like: +---------+---------+ | Name | Type | +---------+---------+ | Noel | Human | | David | Cyborg | | Pranava | Crusher | +---------+---------+

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnDef

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

ColumnDef is a representation of a column definition with a name and a maximum width. The max width must be > 3, and the name must be shorter than the max width. Errors will happen on instantiation of the table.

func NewColumnDef

func NewColumnDef(name string) ColumnDef

NewColumnDef creates a ColumnDef with a name and no maximum width.

func NewColumnDefWithWidth

func NewColumnDefWithWidth(name string, maxWidth int) ColumnDef

NewColumnDefWithWidth creates a ColumnDef with a name and maximum width.

type Table

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

Table creates formatted tables for human readability.

func NewPrettyTable

func NewPrettyTable(columnDefs ...ColumnDef) (*Table, error)

NewPrettyTable creates a new Table.

func (*Table) AddRow

func (table *Table) AddRow(row ...string) error

AddRow adds a row to the table.

func (*Table) PrettyString

func (table *Table) PrettyString() (string, error)

PrettyString creates the pretty string representing this table.

func (*Table) Print

func (table *Table) Print() error

Print prints the table to stdout.

func (*Table) SetHeader

func (table *Table) SetHeader(header string)

SetHeader creates a header for the table.

func (*Table) SetRows

func (table *Table) SetRows(rows [][]string) error

SetRows sets the rows of the table, overriding any that might currently be there.

func (*Table) ShowRowCount

func (table *Table) ShowRowCount(showRowCount bool)

ShowRowCount is a configuration, defaulted to false, that can be toggled on to print row count when Print() is called.

Jump to

Keyboard shortcuts

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