forked from ngaut/sqltop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
55 lines (46 loc) · 923 Bytes
/
ui.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
package main
import (
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
)
type UIController interface {
Render()
OnResize(ui.Resize)
UpdateData()
}
type TextGrid struct {
grid *ui.Grid
par *widgets.Paragraph
x, y int // top, left
height int
}
func newTextGrid(x, y, height int) *TextGrid {
termWidth, _ := ui.TerminalDimensions()
par := widgets.NewParagraph()
par.Border = false
grid := ui.NewGrid()
grid.SetRect(x, y, termWidth, y+height)
grid.Set(
ui.NewRow(1.0,
ui.NewCol(1.0, par),
),
)
return &TextGrid{
grid: grid,
par: par,
x: x,
y: y,
height: height,
}
}
// it's caller's duty to be threaded safe
func (g *TextGrid) SetText(str string) {
g.par.Text = str
}
func (g *TextGrid) OnResize(payload ui.Resize) {
g.grid.SetRect(g.x, g.y, payload.Width, g.height)
ui.Render(g.grid)
}
func (g *TextGrid) Render() {
ui.Render(g.grid)
}