-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
46 lines (36 loc) · 1020 Bytes
/
example_test.go
File metadata and controls
46 lines (36 loc) · 1020 Bytes
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
package table_test
import (
"os"
"github.com/geckoboard/cli-table"
)
func Example() {
t := table.New(3)
// Add some padding
t.SetPadding(1)
// Set headers
t.SetHeader(0, "left", table.AlignLeft)
t.SetHeader(1, "center", table.AlignCenter)
t.SetHeader(2, "right", table.AlignRight)
// Optionally define header groups
t.AddHeaderGroup(2, "left group", table.AlignCenter)
t.AddHeaderGroup(1, "right group", table.AlignRight)
// Append single row
t.Append([]string{"1", "2", "3"})
// Or append a bunch of rows
t.Append(
[]string{"1", "2", "3"},
[]string{"four", "five", "six"},
)
// Render table
t.Write(os.Stdout, table.PreserveAnsi)
// output:
// +---------------+---------------+
// | left group | right group |
// +---------------+---------------+
// | left | center | right |
// +------+--------+---------------+
// | 1 | 2 | 3 |
// | 1 | 2 | 3 |
// | four | five | six |
// +------+--------+---------------+
}