-
Notifications
You must be signed in to change notification settings - Fork 787
/
table.go
72 lines (60 loc) · 1.78 KB
/
table.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
72
// Copyright 2017 Zack Guo <[email protected]>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
// +build ignore
package main
import (
"log"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
)
func main() {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()
table1 := widgets.NewTable()
table1.Rows = [][]string{
[]string{"header1", "header2", "header3"},
[]string{"你好吗", "Go-lang is so cool", "Im working on Ruby"},
[]string{"2016", "10", "11"},
}
table1.TextStyle = ui.NewStyle(ui.ColorWhite)
table1.SetRect(0, 0, 60, 10)
ui.Render(table1)
table2 := widgets.NewTable()
table2.Rows = [][]string{
[]string{"header1", "header2", "header3"},
[]string{"Foundations", "Go-lang is so cool", "Im working on Ruby"},
[]string{"2016", "11", "11"},
}
table2.TextStyle = ui.NewStyle(ui.ColorWhite)
table2.TextAlignment = ui.AlignCenter
table2.RowSeparator = false
table2.SetRect(0, 10, 20, 20)
ui.Render(table2)
table3 := widgets.NewTable()
table3.Rows = [][]string{
[]string{"header1", "header2", "header3"},
[]string{"AAA", "BBB", "CCC"},
[]string{"DDD", "EEE", "FFF"},
[]string{"GGG", "HHH", "III"},
}
table3.TextStyle = ui.NewStyle(ui.ColorWhite)
table3.RowSeparator = true
table3.BorderStyle = ui.NewStyle(ui.ColorGreen)
table3.SetRect(0, 30, 70, 20)
table3.FillRow = true
table3.RowStyles[0] = ui.NewStyle(ui.ColorWhite, ui.ColorBlack, ui.ModifierBold)
table3.RowStyles[2] = ui.NewStyle(ui.ColorWhite, ui.ColorRed, ui.ModifierBold)
table3.RowStyles[3] = ui.NewStyle(ui.ColorYellow)
ui.Render(table3)
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return
}
}
}