-
Notifications
You must be signed in to change notification settings - Fork 59
/
dialog.go
110 lines (93 loc) · 1.8 KB
/
dialog.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
ui "github.com/bcicen/termui"
)
func TraceDialog() {
ui.ResetHandlers()
defer ui.ResetHandlers()
var offset int
items := grid.rows[grid.cursorPos].trace.Items
l := ui.NewList()
l.X = 1
l.Border = false
var redraw = func() {
l.Items = items[offset:]
ui.Render(l)
}
var resize = func() {
l.Height = ui.TermHeight()
l.Width = ui.TermWidth()
redraw()
}
ui.Clear()
resize()
HandleKeys("up", func() {
if offset > 0 {
offset--
redraw()
}
})
HandleKeys("down", func() {
if l.Height+offset < len(items) {
offset++
redraw()
}
})
ui.Handle("/sys/kbd/", func(ui.Event) { ui.StopLoop() })
ui.Handle("/sys/wnd/resize", func(ui.Event) { resize() })
ui.Loop()
}
func HelpDialog() {
ui.ResetHandlers()
defer ui.ResetHandlers()
p := ui.NewList()
p.X = 1
p.Height = 10
p.Width = 45
p.BorderLabel = "help"
p.Items = []string{
" r - manual refresh",
" p - pause/unpause automatic updates",
" s - toggle sort column and refresh",
" f - filter by keyword",
" <up>,<down>,j,k - move cursor position",
" <enter>,o - expand trace under cursor",
" t - open trace in full screen",
" <esc>,q - exit grmon",
}
ui.Clear()
ui.Render(p)
ui.Handle("/sys/kbd/", func(ui.Event) {
ui.StopLoop()
})
ui.Loop()
}
func FilterDialog() {
ui.ResetHandlers()
defer ui.ResetHandlers()
i := NewInput()
i.BorderLabel = "Filter"
i.SetY(ui.TermHeight() - i.Height)
i.Data = filter
ui.Render(i)
// refresh container rows on input
stream := i.Stream()
go func() {
for s := range stream {
filter = s
RebuildRows()
ui.Render(i)
}
}()
i.InputHandlers()
ui.Handle("/sys/kbd/<escape>", func(ui.Event) {
filter = ""
ui.StopLoop()
})
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
filter = i.Data
ui.StopLoop()
})
ui.Loop()
RebuildRows()
}