~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/gosuri/uitable/example_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package uitable_test
 
2
 
 
3
import (
 
4
        "fmt"
 
5
 
 
6
        "github.com/gosuri/uitable"
 
7
)
 
8
 
 
9
type hacker struct {
 
10
        Name, Birthday, Bio string
 
11
}
 
12
 
 
13
var hackers = []hacker{
 
14
        {"Ada Lovelace", "December 10, 1815", "Ada was a British mathematician and writer, chiefly known for her work on Charles Babbage's early mechanical general-purpose computer, the Analytical Engine"},
 
15
        {"Alan Turing", "June 23, 1912", "Alan was a British pioneering computer scientist, mathematician, logician, cryptanalyst and theoretical biologist"},
 
16
}
 
17
 
 
18
func Example() {
 
19
        table := uitable.New()
 
20
        table.MaxColWidth = 50
 
21
 
 
22
        fmt.Println("==> List")
 
23
        table.AddRow("NAME", "BIRTHDAY", "BIO")
 
24
        for _, hacker := range hackers {
 
25
                table.AddRow(hacker.Name, hacker.Birthday, hacker.Bio)
 
26
        }
 
27
        fmt.Println(table)
 
28
 
 
29
        fmt.Print("\n==> Details\n")
 
30
        table = uitable.New()
 
31
        table.MaxColWidth = 80
 
32
        table.Wrap = true
 
33
        for _, hacker := range hackers {
 
34
                table.AddRow("Name:", hacker.Name)
 
35
                table.AddRow("Birthday:", hacker.Birthday)
 
36
                table.AddRow("Bio:", hacker.Bio)
 
37
                table.AddRow("") // blank
 
38
        }
 
39
        fmt.Println(table)
 
40
}