on main help sign in
fix(style): heartbit in --version
598e2f6Carlos Alexandro Becker
internal/cmd/root.go+36
@@ -1,6 +1,7 @@
1package cmd
1package cmd
2
2
3import (
3import (
4+ "bytes"
4 "context"
5 "context"
5 "fmt"
6 "fmt"
6 "io"
7 "io"
@@ -10,6 +11,7 @@ import (
10 "strconv"
11 "strconv"
11
12
12 tea "github.com/charmbracelet/bubbletea/v2"
13 tea "github.com/charmbracelet/bubbletea/v2"
14+ "github.com/charmbracelet/colorprofile"
13 "github.com/charmbracelet/crush/internal/app"
15 "github.com/charmbracelet/crush/internal/app"
14 "github.com/charmbracelet/crush/internal/config"
16 "github.com/charmbracelet/crush/internal/config"
15 "github.com/charmbracelet/crush/internal/db"
17 "github.com/charmbracelet/crush/internal/db"
@@ -17,6 +19,8 @@ import (
17 "github.com/charmbracelet/crush/internal/tui"
19 "github.com/charmbracelet/crush/internal/tui"
18 "github.com/charmbracelet/crush/internal/version"
20 "github.com/charmbracelet/crush/internal/version"
19 "github.com/charmbracelet/fang"
21 "github.com/charmbracelet/fang"
22+ "github.com/charmbracelet/lipgloss/v2"
23+ "github.com/charmbracelet/x/exp/charmtone"
20 "github.com/charmbracelet/x/term"
24 "github.com/charmbracelet/x/term"
21 "github.com/spf13/cobra"
25 "github.com/spf13/cobra"
22)
26)
@@ -93,7 +97,39 @@ crush -y
93 },
97 },
94}
98}
95
99
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+
96func Execute() {
118func 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+ }
97 if err := fang.Execute(
133 if err := fang.Execute(
98 context.Background(),
134 context.Background(),
99 rootCmd,
135 rootCmd,