clitable

package module
v2.0.0-...-8b9fa48 Latest Latest
Warning

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

Go to latest
Published: May 19, 2018 License: MIT Imports: 5 Imported by: 2

README

cli-table Build Status

cli-table is a Go 1.10 library for easy table-formatted output for CLIs.

Get it

go get -u gopkg.in/benweidig/cli-table.v2

Example

Please see example/main.go for a full example.

table := clitable.New()
table.AddRow("COL1", "COL2", "COL3", "COL4")
table.AddRow("This is", "the first", "row?", 42)
table.AddRow("A", "shorter", "row")
table.AddRow("And an even", "longer", "one", "with", "more", "columns than the first")

fmt.Println(table.String())

Output:

COL1        | COL2      | COL3 | COL4 |      |
This is     | the first | row? | 42   |      |
A           | shorter   | row  |      |      |
And an even | longer    | one  | with | more | columns than the first

Options

You can configure the output by modifying the table struct:

Option Type Default Description
ColSeparator string " | " Vertical separator between columns
Padding int 0 Adds an additional padding to the next column
RightBorder bool false Enable the outer right border
HeaderSeparator byte 0 The byte used for header separator, default is "no value" so no separator is added

Inspired by

This library was created after using https://github.com/gosuri/uitable. First I wanted to fork it and change it to my needs but then I decided I wanted to go another way and startet my own library.

License

MIT. See LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Table

type Table struct {

	// The column separator
	ColSeparator string

	// Add an additional horizontal padding to the right of the content to cells
	Padding int

	// Print the border at the right outer side of the table
	RightBorder bool

	// Header separator for border under the first row, if empty no header line will be added
	HeaderSeparator byte
	// contains filtered or unexported fields
}

func New

func New() *Table

Creates a new Table with sensible defaults

func (*Table) AddRow

func (t *Table) AddRow(contents ...interface{})

Adds a row of data to the table. Col count doesn't matter.

func (*Table) String

func (t *Table) String() string

Returns string representation of the table

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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