-
Notifications
You must be signed in to change notification settings - Fork 5
/
toolbar.go
144 lines (127 loc) · 3.03 KB
/
toolbar.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"fmt"
"os"
. "github.com/emad-elsaid/debugger/ui"
"github.com/go-delve/delve/pkg/proc"
"golang.org/x/exp/shiny/materialdesign/icons"
)
var (
IconStop = Icon(icons.AVStop, Theme.TextColor)
IconRestart = Icon(icons.NavigationRefresh, Theme.TextColor)
IconContinue = Icon(icons.AVPlayArrow, SuccessColor)
IconStepOut = Icon(icons.NavigationArrowBack, Theme.TextColor)
IconNext = Icon(icons.NavigationArrowDownward, Theme.TextColor)
IconStep = Icon(icons.NavigationArrowForward, Theme.TextColor)
IconProcess = Icon(icons.AVPlayCircleFilled, SecondaryTextColor)
)
type Toolbar struct {
RestartBtn Clickable
StopBtn Clickable
ContinueBtn Clickable
NextBtn Clickable
StepBtn Clickable
StepOutBtn Clickable
}
func (t *Toolbar) Layout(d *Debugger) W {
target := d.Target()
pid := target.Pid()
valid := d.LastState == nil || !d.LastState.Exited
showStop := d.IsRunning()
showCont := !d.IsRunning() && valid
showRestart := showStop || showCont || !valid
showStep := !d.IsRunning() && valid && d.StopReason() != proc.StopLaunched
showNext := !d.IsRunning() && valid && d.StopReason() != proc.StopLaunched
showStepOut := !d.IsRunning() && valid && d.StopReason() != proc.StopLaunched
IconSize := FontEnlarge(2)
btns := []FlexChild{
Flexed(1,
Inset1(
Columns(
Rigid(IconSize(IconFolder)),
ColSpacer1,
Rigid(
Rows(
Rigid(Bold(Label(d.Path))),
Rigid(
WidgetIf(
d.File != "",
Wrap(
Text(fmt.Sprintf("%s:%d", d.File, d.Line)),
AlignStart,
TextColor(SecondaryTextColor),
MaxLines(3),
),
),
),
),
),
ColSpacer3,
Rigid(IconSize(IconProcess)),
ColSpacer1,
Rigid(
Rows(
Rigid(Label(fmt.Sprintf("pid: %d", pid))),
Rigid(Label(fmt.Sprintf("cwd: %s", t.CWD(pid)))),
),
),
),
),
),
}
if t.StopBtn.Clicked() {
d.Stop()
}
if showStop {
btns = append(btns,
Rigid(ToolbarButton(&t.StopBtn, IconSize(IconStop), "Stop")),
)
}
if t.RestartBtn.Clicked() {
d.Restart()
}
if showRestart {
btns = append(btns,
Rigid(ToolbarButton(&t.RestartBtn, IconSize(IconRestart), "Restart")),
)
}
if t.ContinueBtn.Clicked() {
d.Continue()
}
if showCont {
btns = append(btns,
Rigid(ToolbarButton(&t.ContinueBtn, IconSize(IconContinue), "Continue")),
)
}
if t.StepOutBtn.Clicked() {
d.StepOut()
}
if showStepOut {
btns = append(btns,
Rigid(ToolbarButton(&t.StepOutBtn, IconSize(IconStepOut), "Step out")),
)
}
if t.NextBtn.Clicked() {
d.Next()
}
if showNext {
btns = append(btns,
Rigid(ToolbarButton(&t.NextBtn, IconSize(IconNext), "Next")),
)
}
if t.StepBtn.Clicked() {
d.Step()
}
if showStep {
btns = append(btns,
Rigid(ToolbarButton(&t.StepBtn, IconSize(IconStep), "Step")),
)
}
return Background(ToolbarBgColor,
ColumnsVCentered(btns...),
)
}
func (t *Toolbar) CWD(pid int) string {
cwd, _ := os.Readlink(fmt.Sprintf("/proc/%d/cwd", pid))
return string(cwd)
}