Skip to content

Commit 7ea7a3d

Browse files
authored
fix: GetDynamicStyle panic (#29)
1 parent cd59e56 commit 7ea7a3d

File tree

6 files changed

+59
-8
lines changed

6 files changed

+59
-8
lines changed

.github/workflows/back-compat-pr.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ env:
1616
jobs:
1717
check-back-compat:
1818
name: build
19-
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
os: [ubuntu-latest, macos-latest]
22+
runs-on: ${{ matrix.os }}
2023
steps:
2124
- uses: actions/checkout@v4
2225
- name: Set up Go

.github/workflows/back-compat.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ env:
1313
jobs:
1414
check-back-compat:
1515
name: build
16-
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
os: [ubuntu-latest, macos-latest]
19+
runs-on: ${{ matrix.os }}
1720
steps:
1821
- uses: actions/checkout@v4
1922
with:

.github/workflows/build.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ env:
1818
jobs:
1919
build:
2020
name: build
21-
runs-on: ubuntu-latest
21+
strategy:
22+
matrix:
23+
os: [ubuntu-latest, macos-latest]
24+
runs-on: ${{ matrix.os }}
2225
steps:
2326
- uses: actions/checkout@v4
2427
- name: Set up Go
@@ -29,10 +32,6 @@ jobs:
2932
run: go build -v ./...
3033
- name: go test
3134
run: go test -v ./...
32-
- name: golangci-lint
33-
uses: golangci/golangci-lint-action@v6
34-
with:
35-
version: v1.58
3635
- name: run omm
3736
run: |
3837
go build .

.github/workflows/lint.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: lint
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
paths:
8+
- "go.*"
9+
- "**/*.go"
10+
- ".github/workflows/*.yml"
11+
12+
permissions:
13+
contents: read
14+
15+
env:
16+
GO_VERSION: '1.22.5'
17+
18+
jobs:
19+
lint:
20+
name: lint
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Set up Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: ${{ env.GO_VERSION }}
28+
- name: golangci-lint
29+
uses: golangci/golangci-lint-action@v6
30+
with:
31+
version: v1.58

internal/types/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func GetDynamicStyle(str string) lipgloss.Style {
144144
h.Write([]byte(str))
145145
hash := h.Sum32()
146146

147-
color := colors[int(hash)%len(colors)]
147+
color := colors[hash%uint32(len(colors))]
148148
return lipgloss.NewStyle().
149149
Foreground(lipgloss.Color(color))
150150
}

internal/types/types_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package types
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.GetBackground(), gotb.GetBackground())
15+
}

0 commit comments

Comments
 (0)