-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlinecolumn.go
101 lines (88 loc) · 2.33 KB
/
linecolumn.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
package main
import (
"github.com/ilmari-h/dlvtui/nav"
"fmt"
"strconv"
"github.com/rivo/tview"
)
type LineColumn struct {
width int
navState *nav.Nav
textView *tview.TextView
}
func getMaxLineColWidth(maxLine int) int {
return len(strconv.Itoa(maxLine)) + 3
}
func NewLineColumn(navState *nav.Nav) *LineColumn {
return &LineColumn{
navState: navState,
textView: tview.NewTextView(),
}
}
func (lc *LineColumn) SetWidth(nw int) {
lc.width = nw
}
func (lc *LineColumn) Render(lineStart, lineEnd, current int) {
lc.textView.SetBackgroundColor(iToColorTcell(gConfig.Colors.LineColumnBg))
if lc.navState == nil || lc.navState.CurrentFile == nil {
return
}
// Set line numbers in gutter.
lineNumbers := ""
breakpoints := lc.navState.Breakpoints[lc.navState.CurrentFile.Path]
for i := lineStart; i <= lineEnd; i++ {
bp := " "
if fbp, ok := breakpoints[i]; ok && fbp.ID >= 0 {
if breakpoints[i].Disabled {
bp = fmt.Sprintf("[%s]%s[-::-]",
iToColorS(gConfig.Colors.BpFg),
gConfig.Icons.BpDisabled,
)
} else if i == lc.navState.CurrentDebuggerPos.Line &&
lc.navState.CurrentFile.Path == lc.navState.CurrentDebuggerPos.File {
bp = fmt.Sprintf("[%s:%s]%s[-::-]",
iToColorS(gConfig.Colors.BpActiveFg),
iToColorS(gConfig.Colors.LineActiveBg),
gConfig.Icons.BpActive,
)
} else {
bp = fmt.Sprintf("[%s]%s[-::-]",
iToColorS(gConfig.Colors.BpFg),
gConfig.Icons.Bp,
)
}
}
// TODO: Also: if some stack frame has this line
if i == lc.navState.CurrentDebuggerPos.Line &&
lc.navState.CurrentFile.Path == lc.navState.CurrentDebuggerPos.File {
lineNumbers += fmt.Sprintf(`[%s:%s]%s[%s]%*d [-:-:-]`,
iToColorS(gConfig.Colors.LineSelectedFg),
iToColorS(gConfig.Colors.LineActiveBg),
bp,
iToColorS(gConfig.Colors.LineSelectedFg),
lc.width-2,
i,
)
} else if i == current {
lineNumbers += fmt.Sprintf(`[%s:%s]%s[%s]%*d [-:-:-]`,
iToColorS(gConfig.Colors.LineSelectedFg),
iToColorS(gConfig.Colors.LineSelectedBg),
bp,
iToColorS(gConfig.Colors.LineSelectedFg),
lc.width-2,
i,
)
} else {
lineNumbers += fmt.Sprintf(`[%s]%s%*d `,
iToColorS(gConfig.Colors.LineFg),
bp,
lc.width-2,
i,
)
}
}
lc.textView.SetText(lineNumbers)
}
func (lc *LineColumn) GetTextView() *tview.TextView {
return lc.textView
}