This repository has been archived by the owner on May 13, 2021. It is now read-only.
/
main.go
58 lines (51 loc) · 2.07 KB
/
main.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
package main
import (
"os"
"sort"
"github.com/kataras/tablewriter"
"github.com/lensesio/tableprinter"
)
type person struct {
Firstname string `header:"first name"`
Lastname string `header:"last name"`
}
func main() {
printer := tableprinter.New(os.Stdout)
persons := []person{
{"Chris", "Doukas"},
{"Georgios", "Callas"},
{"Ioannis", "Christou"},
{"Nikolaos", "Doukas"},
{"Dimitrios", "Dellis"},
}
sort.Slice(persons, func(i, j int) bool {
return persons[j].Firstname > persons[i].Firstname
})
/*
│─────────────────│───────────│
│ FIRST NAME (5) │ LAST NAME │ <- Green letters, black background header box.
│─────────────────│───────────│
│ Chris │ Doukas │
│ Dimitrios │ Dellis │
│ Georgios │ Callas │
│ Ioannis │ Christou │
│ Nikolaos │ Doukas │
│─────────────────│───────────│
*/
// printer.HeaderLine = false // to disable headers.
// printer.DefaultAlignment to change the alignment of cells.
// printer.HeaderAlignment to change the alignment of header text.
// printer.HeaderColors to set colors for each header manually, must match the number of headers.
// printer.RowLengthTitle = func(n int) bool {
// return n > 4
// } // to change if and when the number of total rows should be shown after the first header, defaults to > 3.
// printer.AutoWrapText = true // to enable cell's text wrap.
// printer.NewLine = "\n" // to modify the new line for cells.
printer.BorderTop, printer.BorderBottom, printer.BorderLeft, printer.BorderRight = true, true, true, true
printer.CenterSeparator = "│"
printer.ColumnSeparator = "│"
printer.RowSeparator = "─"
printer.HeaderBgColor = tablewriter.BgBlackColor // set header background color for all headers.
printer.HeaderFgColor = tablewriter.FgGreenColor // set header foreground color for all headers.
printer.Print(persons)
}