on main help sign in
fix(ux): fix crush logo flicker on window resizes (#1338)
commit04bc0154c1209b9a1dede09795a0b145cfa58a42 authorAndrey Nering <andreynering@users.noreply.github.com> dateThu 30 Oct 2025, 15:32 (1 year ago) parentae70537
2 files changed+26−3
internal/tui/components/logo/logo.go+2−3 internal/tui/components/logo/rand.go+24
internal/tui/components/logo/logo.go+2−3
@@ -4,7 +4,6 @@ package logo
44import (
55 "fmt"
66 "image/color"
7− "math/rand/v2"
87 "strings"
98
109 "github.com/MakeNowJust/heredoc"
@@ -53,7 +52,7 @@ func Render(version string, compact bool, o Opts) string {
5352 }
5453 stretchIndex := -1 // -1 means no stretching.
5554 if !compact {
56− stretchIndex = rand.IntN(len(letterforms))
55+ stretchIndex = cachedRandN(len(letterforms))
5756 }
5857
5958 crush := renderWord(spacing, stretchIndex, letterforms...)
@@ -337,7 +336,7 @@ func stretchLetterformPart(s string, p letterformProps) string {
337336 }
338337 n := p.width
339338 if p.stretch {
340− n = rand.IntN(p.maxStretch-p.minStretch) + p.minStretch //nolint:gosec
339+ n = cachedRandN(p.maxStretch-p.minStretch) + p.minStretch //nolint:gosec
341340 }
342341 parts := make([]string, n)
343342 for i := range parts {
internal/tui/components/logo/rand.gonew file+24
@@ -0,0 +1,24 @@
1+package logo
2+
3+import (
4+ "math/rand/v2"
5+ "sync"
6+)
7+
8+var (
9+ randCaches = make(map[int]int)
10+ randCachesMu sync.Mutex
11+)
12+
13+func cachedRandN(n int) int {
14+ randCachesMu.Lock()
15+ defer randCachesMu.Unlock()
16+
17+ if n, ok := randCaches[n]; ok {
18+ return n
19+ }
20+
21+ r := rand.IntN(n)
22+ randCaches[n] = r
23+ return r
24+}