1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
# uitable [](https://godoc.org/github.com/gosuri/uitable) [](https://travis-ci.org/gosuri/uitable)
uitable is a go library for representing data as tables for terminal applications. It provides primitives for sizing and wrapping columns to improve readability.
## Example Usage
Full source code for the example is available at [example/main.go](example/main.go)
```go
table := uitable.New()
table.MaxColWidth = 50
table.AddRow("NAME", "BIRTHDAY", "BIO")
for _, hacker := range hackers {
table.AddRow(hacker.Name, hacker.Birthday, hacker.Bio)
}
fmt.Println(table)
```
Will render the data as:
```sh
NAME BIRTHDAY BIO
Ada Lovelace December 10, 1815 Ada was a British mathematician and writer, chi...
Alan Turing June 23, 1912 Alan was a British pioneering computer scientis...
```
For wrapping in two columns:
```go
table = uitable.New()
table.MaxColWidth = 80
table.Wrap = true // wrap columns
for _, hacker := range hackers {
table.AddRow("Name:", hacker.Name)
table.AddRow("Birthday:", hacker.Birthday)
table.AddRow("Bio:", hacker.Bio)
table.AddRow("") // blank
}
fmt.Println(table)
```
Will render the data as:
```
Name: Ada Lovelace
Birthday: December 10, 1815
Bio: Ada was a British mathematician and writer, chiefly known for her work on
Charles Babbage's early mechanical general-purpose computer, the Analytical
Engine
Name: Alan Turing
Birthday: June 23, 1912
Bio: Alan was a British pioneering computer scientist, mathematician, logician,
cryptanalyst and theoretical biologist
```
## Installation
```
$ go get -v github.com/gosuri/uitable
```
[](https://bitdeli.com/free "Bitdeli Badge")
|