-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtui.go
46 lines (41 loc) · 838 Bytes
/
tui.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
package mkrg
import (
"fmt"
"time"
)
type tui struct {
height, width int
column, maxColumn int
until time.Time
lines []string
}
func newTui(height, width, maxColumn int, until time.Time) *tui {
return &tui{height, width, 0, maxColumn, until, make([]string, height)}
}
func (ui *tui) output(graph graph, ms metricsByName) error {
v := newViewer(graph, ui.height, ui.width)
for i, l := range v.GetLines(ms, ui.until) {
ui.lines[i] += l
if ui.column < ui.maxColumn-1 {
ui.lines[i] += " "
}
}
if ui.column == ui.maxColumn-1 {
for i := range ui.lines {
fmt.Println(ui.lines[i])
ui.lines[i] = ""
}
ui.column = 0
} else {
ui.column++
}
return nil
}
func (ui *tui) cleanup() error {
if ui.column > 0 {
for _, l := range ui.lines {
fmt.Println(l)
}
}
return nil
}