-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathwriter_test.go
71 lines (67 loc) · 1.54 KB
/
writer_test.go
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
68
69
70
71
package list
import (
"fmt"
"github.com/jedib0t/go-pretty/v6/text"
)
func Example() {
lw := NewWriter()
// append a tree
lw.AppendItem("George. R. R. Martin")
lw.Indent()
lw.AppendItem("A Song of Ice and Fire")
lw.Indent()
lw.AppendItems([]interface{}{
"Arya Stark",
"Bran Stark",
"Rickon Stark",
"Robb Stark",
"Sansa Stark",
"Jon Snow",
})
lw.UnIndent()
lw.UnIndent()
// append another tree
lw.AppendItem("Stephen King")
lw.Indent()
lw.AppendItem("The Dark Tower")
lw.Indent()
lw.AppendItems([]interface{}{
"Jake Chambers",
"Randal Flagg",
"Roland Deschain",
})
lw.UnIndent()
lw.AppendItem("the shawshank redemption")
lw.Indent()
lw.AppendItems([]interface{}{
"andy dufresne",
"byron hadley",
"ellis boyd redding",
"samuel norton",
})
// customize rendering
lw.SetStyle(StyleConnectedLight)
lw.Style().CharItemTop = "├"
lw.Style().Format = text.FormatTitle
// render it
fmt.Printf("Simple List:\n%s", lw.Render())
// Output: Simple List:
// ├ George. R. R. Martin
// │ └─ A Song Of Ice And Fire
// │ ├─ Arya Stark
// │ ├─ Bran Stark
// │ ├─ Rickon Stark
// │ ├─ Robb Stark
// │ ├─ Sansa Stark
// │ └─ Jon Snow
// └─ Stephen King
// ├─ The Dark Tower
// │ ├─ Jake Chambers
// │ ├─ Randal Flagg
// │ └─ Roland Deschain
// └─ The Shawshank Redemption
// ├─ Andy Dufresne
// ├─ Byron Hadley
// ├─ Ellis Boyd Redding
// └─ Samuel Norton
}