Skip to content

Commit e16a500

Browse files
committed
fix: potential panic when getting dynamic styles
1 parent c049ac6 commit e16a500

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

internal/ui/styles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ var (
140140
h.Write([]byte(str))
141141
hash := h.Sum32()
142142

143-
color := taskColors[int(hash)%len(taskColors)]
143+
color := taskColors[hash%uint32(len(taskColors))]
144144
return lipgloss.NewStyle().
145145
Foreground(lipgloss.Color(color))
146146
}

internal/ui/styles_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ui
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestGetDynamicStyle(t *testing.T) {
10+
input := "abcdefghi"
11+
gota := getDynamicStyle(input)
12+
gotb := getDynamicStyle(input)
13+
// assert same style returned for the same string
14+
assert.Equal(t, gota.GetForeground(), gotb.GetForeground())
15+
}

0 commit comments

Comments
 (0)