main.go

 1package main
 2
 3import (
 4	"fmt"
 5	"math/rand/v2"
 6	"os"
 7
 8	"charm.land/lipgloss/v2"
 9	"github.com/charmbracelet/crush/internal/ui/logo"
10	"github.com/charmbracelet/crush/internal/ui/styles"
11	"github.com/charmbracelet/x/exp/slice"
12	"github.com/charmbracelet/x/term"
13)
14
15func renderLetterforms(stretch bool) string {
16	letterFuncs := []func(bool) string{
17		logo.LetterH,
18		logo.LetterY,
19		logo.LetterYAlt,
20		logo.LetterP,
21		logo.LetterE,
22		logo.LetterEAlt,
23		logo.LetterR,
24		logo.LetterC,
25		logo.LetterR,
26		logo.LetterU,
27		logo.LetterSAlt,
28		logo.LetterH,
29	}
30
31	// Which letter to stretch, if we're stretching.
32	stretchIndex := -1
33	if stretch {
34		stretchIndex = rand.IntN(len(letterFuncs))
35	}
36
37	// Build letterforms.
38	letterforms := make([]string, len(letterFuncs))
39	for i, f := range letterFuncs {
40		letterforms[i] = f(stretch && i == stretchIndex)
41	}
42	letterforms = slice.Intersperse(letterforms, " ")
43
44	return lipgloss.JoinHorizontal(lipgloss.Top, letterforms...)
45}
46
47func main() {
48	w, _, err := term.GetSize(os.Stdout.Fd())
49	if err != nil {
50		fmt.Fprintf(os.Stderr, "Could not get terminal size: %s", err)
51	}
52
53	s := styles.DefaultStyles()
54	opts := logo.Opts{
55		FieldColor:   s.LogoFieldColor,
56		TitleColorA:  s.LogoTitleColorA,
57		TitleColorB:  s.LogoTitleColorB,
58		CharmColor:   s.LogoCharmColor,
59		VersionColor: s.LogoVersionColor,
60		Width:        w,
61	}
62
63	lipgloss.Println(logo.Render(s.Base, "v1.0.0", false, opts))
64	lipgloss.Println(logo.Render(s.Base, "v1.0.0", true, opts))
65
66	fmt.Println(renderLetterforms(false))
67	for range 5 {
68		fmt.Println(renderLetterforms(true))
69	}
70}