1package main
2
3import (
4 "fmt"
5 "log/slog"
6 "net/http"
7 "os"
8 "runtime"
9
10 _ "net/http/pprof" // profiling
11
12 _ "github.com/joho/godotenv/autoload" // automatically load .env files
13
14 "github.com/charmbracelet/crush/internal/cmd"
15 "github.com/charmbracelet/crush/internal/log"
16 "github.com/charmbracelet/lipgloss/v2"
17)
18
19func main() {
20 if runtime.GOOS == "windows" {
21 showWindowsWarning()
22 }
23
24 defer log.RecoverPanic("main", func() {
25 slog.Error("Application terminated due to unhandled panic")
26 })
27
28 if os.Getenv("CRUSH_PROFILE") != "" {
29 go func() {
30 slog.Info("Serving pprof at localhost:6060")
31 if httpErr := http.ListenAndServe("localhost:6060", nil); httpErr != nil {
32 slog.Error(fmt.Sprintf("Failed to pprof listen: %v", httpErr))
33 }
34 }()
35 }
36
37 cmd.Execute()
38}
39
40func showWindowsWarning() {
41 content := lipgloss.JoinVertical(lipgloss.Left,
42 lipgloss.NewStyle().Bold(true).Render("WARNING:")+" Crush is experimental on Windows!",
43 "While we work on it, we recommend WSL2 for a better experience.",
44 lipgloss.NewStyle().Italic(true).Render("Press Enter to continue..."),
45 )
46 fmt.Print(content)
47
48 var input string
49 fmt.Scanln(&input)
50}