/
sources_panel.go
62 lines (52 loc) · 1.04 KB
/
sources_panel.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
package main
import (
"fmt"
"log"
"strings"
"gioui.org/widget"
. "github.com/emad-elsaid/debugger/ui"
)
type SourcesPanel struct {
List ClickableList
Filter widget.Editor
}
func NewSourcesPanel() SourcesPanel {
return SourcesPanel{
List: NewClickableList(),
Filter: LineEditor(),
}
}
func (s *SourcesPanel) Layout(d *Debugger) W {
f := s.Filter.Text()
ss := d.Target().BinInfo().Sources
filtered := []string{}
for i := range ss {
if strings.Contains(ss[i], f) {
filtered = append(filtered, ss[i])
}
}
ele := func(c C, i int) D {
w := Inset1(Label(filtered[i]))
if filtered[i] == d.File {
w = Background(HighlightColor, w)
}
return w(c)
}
click := func(i int) {
f := filtered[i]
log.Printf("Switching file: %s", f)
d.SetFileLine(f, 0)
}
return Rows(
RowSpacer1,
Rigid(
FormRow(
Rigid(Label(fmt.Sprintf(" %d", len(filtered)))),
ColSpacer1,
Flexed(1, TextInput(&s.Filter, "Search Sources...")),
),
),
Rigid(HSpacer1),
Flexed(1, s.List.Layout(len(filtered), ele, click)),
)
}