-
Notifications
You must be signed in to change notification settings - Fork 5
/
packages_panel.go
64 lines (53 loc) · 1.07 KB
/
packages_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
63
64
package main
import (
"fmt"
"sort"
"strings"
"gioui.org/widget"
. "github.com/emad-elsaid/debugger/ui"
)
type PackagesPanel struct {
Filter widget.Editor
List ClickableList
}
func NewPackagesPanel() PackagesPanel {
return PackagesPanel{
Filter: LineEditor(),
List: NewClickableList(),
}
}
func (p *PackagesPanel) Layout(d *Debugger) W {
filter := p.Filter.Text()
pkgsMap := map[string]bool{}
fs := d.Target().BinInfo().Functions
for _, i := range fs {
pkgsMap[i.PackageName()] = true
}
pkgs := make([]string, 0, len(pkgsMap))
for i := range pkgsMap {
if strings.Contains(i, filter) {
pkgs = append(pkgs, i)
}
}
sort.Strings(pkgs)
ele := func(c C, i int) D {
return Inset1(Label(pkgs[i]))(c)
}
click := func(i int) {
OpenBrowser(fmt.Sprintf("https://pkg.go.dev/%s", pkgs[i]))
}
return Rows(
RowSpacer1,
Rigid(
FormRow(
Rigid(Label(fmt.Sprintf(" %d", len(pkgs)))),
ColSpacer1,
Flexed(1, TextInput(&p.Filter, "Search Packages...")),
),
),
RowSpacer1,
Flexed(1,
p.List.Layout(len(pkgs), ele, click),
),
)
}