@@ -1,6 +1,7 @@
11package cmd
22
33import (
4+ "bytes"
45 "context"
56 "fmt"
67 "io"
@@ -10,6 +11,7 @@ import (
1011 "strconv"
1112
1213 tea "github.com/charmbracelet/bubbletea/v2"
14+ "github.com/charmbracelet/colorprofile"
1315 "github.com/charmbracelet/crush/internal/app"
1416 "github.com/charmbracelet/crush/internal/config"
1517 "github.com/charmbracelet/crush/internal/db"
@@ -17,6 +19,8 @@ import (
1719 "github.com/charmbracelet/crush/internal/tui"
1820 "github.com/charmbracelet/crush/internal/version"
1921 "github.com/charmbracelet/fang"
22+ "github.com/charmbracelet/lipgloss/v2"
23+ "github.com/charmbracelet/x/exp/charmtone"
2024 "github.com/charmbracelet/x/term"
2125 "github.com/spf13/cobra"
2226)
@@ -93,7 +97,39 @@ crush -y
9397 },
9498}
9599
100+var heartbit = lipgloss.NewStyle().Foreground(charmtone.Dolly).SetString(`
101+ ▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄
102+ ███████████ ███████████
103+████████████████████████████
104+████████████████████████████
105+██████████▀██████▀██████████
106+██████████ ██████ ██████████
107+▀▀██████▄████▄▄████▄██████▀▀
108+ ████████████████████████
109+ ████████████████████
110+ ▀▀██████████▀▀
111+ ▀▀▀▀▀▀
112+`)
113+
114+// copied from cobra:
115+const defaultVersionTemplate = `{{with .DisplayName}}{{printf "%s " .}}{{end}}{{printf "version %s" .Version}}
116+`
117+
96118func Execute() {
119+ // NOTE: very hacky: we create a colorprofile writer with STDOUT, then make
120+ // it forward to a bytes.Buffer, write the colored heartbit to it, and then
121+ // finally prepend it in the version template.
122+ // Unfortunately cobra doesn't give us a way to set a function to handle
123+ // printing the version, and PreRunE runs after the version is already
124+ // handled, so that doesn't work either.
125+ // This is the only way I could find that works relatively well.
126+ if term.IsTerminal(os.Stdout.Fd()) {
127+ var b bytes.Buffer
128+ w := colorprofile.NewWriter(os.Stdout, os.Environ())
129+ w.Forward = &b
130+ _, _ = w.WriteString(heartbit.String())
131+ rootCmd.SetVersionTemplate(b.String() + "\n" + defaultVersionTemplate)
132+ }
97133 if err := fang.Execute(
98134 context.Background(),
99135 rootCmd,