-
Notifications
You must be signed in to change notification settings - Fork 4
/
goroutinepage.go
118 lines (103 loc) · 3.06 KB
/
goroutinepage.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
111
112
113
114
115
116
117
118
package main
import (
"fmt"
"strings"
"github.com/gdamore/tcell/v2"
"github.com/go-delve/delve/service/api"
"github.com/rivo/tview"
)
type GoroutinePage struct {
renderedGoroutines []*api.Goroutine
commandHandler *CommandHandler
listView *tview.List
widget *tview.Frame
}
func NewGoroutinePage() *GoroutinePage {
listView := tview.NewList()
listView.SetBackgroundColor(tcell.ColorDefault)
listView.ShowSecondaryText(false)
selectedStyle := tcell.StyleDefault.
Foreground(iToColorTcell(gConfig.Colors.LineFg)).
Background(iToColorTcell(gConfig.Colors.ListSelectedBg)).
Attributes(tcell.AttrBold)
listView.SetSelectedStyle(selectedStyle)
listView.SetInputCapture(listInputCaptureC)
pageFrame := tview.NewFrame(listView).
SetBorders(0, 0, 0, 0, 0, 0).
AddText("[::b]Goroutines:", true, tview.AlignLeft, iToColorTcell(gConfig.Colors.HeaderFg))
pageFrame.SetBackgroundColor(tcell.ColorDefault)
gp := GoroutinePage{
listView: listView,
widget: pageFrame,
}
return &gp
}
func (page *GoroutinePage) SetCommandHandler(ch *CommandHandler) {
page.commandHandler = ch
}
func (page *GoroutinePage) RenderGoroutines(grs []*api.Goroutine, currId int) {
// Filter out external goroutines.
projectGrs := []*api.Goroutine{}
for _, gor := range grs {
if strings.HasPrefix(gor.CurrentLoc.File, page.commandHandler.view.navState.ProjectPath) ||
strings.HasPrefix(gor.GoStatementLoc.File, page.commandHandler.view.navState.ProjectPath) ||
strings.HasPrefix(gor.StartLoc.File, page.commandHandler.view.navState.ProjectPath) {
projectGrs = append(projectGrs, gor)
}
}
page.listView.Clear()
selectedI := 0
page.renderedGoroutines = grs
for i, gor := range projectGrs {
label := fmt.Sprintf(" [%s]%d.[%s] %s[%s]:%d",
iToColorS(gConfig.Colors.VarTypeFg),
gor.ID,
iToColorS(gConfig.Colors.VarNameFg),
gor.CurrentLoc.File,
iToColorS(gConfig.Colors.VarValueFg),
gor.CurrentLoc.Line,
)
if gor.ID == currId {
selectedI = i
label = fmt.Sprintf("> [%s::b]%d. [%s]%s[%s]:%d",
iToColorS(gConfig.Colors.VarTypeFg),
gor.ID,
iToColorS(gConfig.Colors.VarNameFg),
gor.CurrentLoc.File,
iToColorS(gConfig.Colors.VarValueFg),
gor.CurrentLoc.Line,
)
}
page.listView.AddItem(
label,
"",
rune(48+i),
nil).
SetSelectedFunc(func(i int, s1, s2 string, r rune) {
page.commandHandler.RunCommand(&SwitchGoroutines{
Id: page.renderedGoroutines[i].ID,
})
})
}
page.listView.SetCurrentItem(selectedI)
}
func (sp *GoroutinePage) GetWidget() tview.Primitive {
return sp.widget
}
func (sp *GoroutinePage) GetName() string {
return "goroutines"
}
func (sp *GoroutinePage) HandleKeyEvent(event *tcell.EventKey) *tcell.EventKey {
if keyPressed(event, gConfig.Keys.LineDown) {
sp.listView.SetCurrentItem(sp.listView.GetCurrentItem() + 1)
return nil
}
if keyPressed(event, gConfig.Keys.LineUp) {
if sp.listView.GetCurrentItem() > 0 {
sp.listView.SetCurrentItem(sp.listView.GetCurrentItem() - 1)
}
return nil
}
sp.listView.InputHandler()(event, func(p tview.Primitive) {})
return nil
}