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