-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.go
81 lines (68 loc) · 2.2 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
const placeholderSelectCellText = "Select a cell to view latency and time"
type uIBundle struct {
app *tview.Application
heatmap *tview.Table
infoCenterLeftCell *tview.TableCell
infoCenterRightCell *tview.TableCell
}
func prepareUI(samplesPerSecond, timeWindowSeconds int) *uIBundle {
yAxisLabels := tview.NewTable()
xAxisLabels := tview.NewTable()
heatmap := tview.NewTable().
SetBorders(false).
SetSelectable(true, true)
infoCenter := tview.NewTable()
infoCenterLeftCell := tview.NewTableCell(placeholderSelectCellText).SetExpansion(1)
infoCenterRightCell := tview.NewTableCell("")
infoCenter.SetCell(0, 0, infoCenterLeftCell).
SetCell(0, 1, infoCenterRightCell)
rootGrid := tview.NewGrid().
SetRows(0, 1, 1).
SetColumns(8, 0).
SetBorders(true).
AddItem(yAxisLabels, 0, 0, 1, 1, 0, 0, false).
AddItem(xAxisLabels, 1, 1, 1, 1, 0, 0, false).
AddItem(heatmap, 0, 1, 1, 1, 0, 0, true).
AddItem(infoCenter, 2, 1, 1, 1, 0, 0, false)
app := tview.NewApplication().
SetRoot(rootGrid, true).
EnableMouse(true)
for row := 0; row < samplesPerSecond; row++ {
offsetMs := int(1000.0 * float64(row) / float64(samplesPerSecond))
cell := tview.NewTableCell(fmt.Sprintf("%d ms", offsetMs)).
SetAlign(tview.AlignRight).
SetTextColor(tcell.ColorWhite).
SetExpansion(1)
yAxisLabels.SetCell(row, 0, cell)
}
for col := 0; col < timeWindowSeconds; col++ {
cell := tview.NewTableCell(fmt.Sprintf("%02d", col)).
SetAlign(tview.AlignCenter).
SetTextColor(tcell.ColorWhite).
SetExpansion(1)
xAxisLabels.SetCell(0, col, cell)
}
for row := 0; row < samplesPerSecond; row++ {
for col := 0; col < timeWindowSeconds; col++ {
cell := tview.NewTableCell("").
SetExpansion(1).
SetAlign(tview.AlignCenter)
heatmap.SetCell(row, col, cell)
}
}
// Placeholder cell for nothing-is-selected state
heatmap.SetCell(samplesPerSecond+1, 0, tview.NewTableCell(""))
heatmap.Select(samplesPerSecond+1, 0)
return &uIBundle{
app: app,
heatmap: heatmap,
infoCenterLeftCell: infoCenterLeftCell,
infoCenterRightCell: infoCenterRightCell,
}
}