Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
99 lines (85 loc) · 2.29 KB
/
Copy pathmain.go
File metadata and controls
99 lines (85 loc) · 2.29 KB
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
package main
import (
"flag"
"fmt"
"image"
"log"
"os"
"runtime/pprof"
"strconv"
"gioui.org/app"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget/material"
"loov.dev/lensm/internal/gui"
"loov.dev/lensm/internal/mcp"
)
func main() {
if len(os.Args) > 1 && os.Args[1] == "mcp" {
os.Exit(mcp.RunCommand(os.Args[2:]))
}
cpuprofile := flag.String("cpuprofile", "", "enable cpu profiling")
defaults := DefaultAppSettings()
textSize := flag.Int("text-size", defaults.TextSize, "default font size")
filter := flag.String("filter", "", "filter the functions by regexp")
watch := flag.Bool("watch", false, "auto reload executable, or rebuild a package on change")
context := flag.Int("context", 3, "source line context")
comments := flag.String("comments", "", "comments sidecar path")
font := flag.String("font", "", "user font")
profilePath := flag.String("profile", "", "pprof profile of the binary to show")
flag.Parse()
exePath := flag.Arg(0)
explicitTextSize := false
flag.Visit(func(f *flag.Flag) {
switch f.Name {
case "text-size":
explicitTextSize = true
}
})
if flag.NArg() > 1 {
fmt.Fprintln(os.Stderr, "lensm [exePath | packageDir]")
flag.Usage()
os.Exit(2)
}
windows := &gui.Windows{}
theme := material.NewTheme()
theme.Shaper = text.NewShaper(text.WithCollection(gui.LoadFonts(*font)))
theme.TextSize = unit.Sp(*textSize)
ui := NewFileUI(windows, theme)
if explicitTextSize {
ui.SettingsDialog.TextSize.SetText(strconv.Itoa(*textSize))
} else {
theme.TextSize = unit.Sp(ui.Settings.TextSize)
}
if exePath == "" {
exePath = ui.Settings.LastPath
}
ui.Config = FileUIConfig{
Path: exePath,
Watch: *watch,
Context: *context,
CommentsPath: *comments,
ProfilePath: *profilePath,
}
ui.Funcs.SetFilter(*filter)
// With its own title bar the window is not decorated, which on
// macOS puts the content under a transparent title bar.
windows.Open("lensm", image.Pt(1400, 900), ui.Run, app.Decorated(!customTitleBar))
go func() {
profile(*cpuprofile, windows.Wait)
os.Exit(0)
}()
// This starts Gio main.
app.Main()
}
func profile(cpuprofile string, fn func()) {
if cpuprofile != "" {
f, err := os.Create(cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
fn()
}