Skip to content

Commit 8a86865

Browse files
committed
fix(config): remove mutex outright
1 parent d6ace20 commit 8a86865

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

internal/config/style.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"os"
77
"strings"
8-
"sync"
98

109
"github.com/alecthomas/chroma/v2"
1110
chromaStyles "github.com/alecthomas/chroma/v2/styles"
@@ -23,8 +22,6 @@ const (
2322
chromaStyleTheme = "kyma"
2423
)
2524

26-
var chromaMutex = sync.RWMutex{}
27-
2825
type Properties struct {
2926
Title string `yaml:"title"`
3027
Style StyleConfig `yaml:"style"`
@@ -317,19 +314,9 @@ func ChromaStyle(style ansi.StylePrimitive) string {
317314
func GetChromaStyle(themeName string) *chroma.Style {
318315
customThemeName := chromaStyleTheme + "-" + themeName
319316

320-
switch themeName {
321-
case "dracula":
322-
return chromaStyles.Get("dracula")
323-
case "tokyo-night", "tokyonight":
324-
return chromaStyles.Get("tokyo-night")
325-
}
326-
327-
chromaMutex.RLock()
328317
if chromaStyle, ok := chromaStyles.Registry[customThemeName]; ok {
329-
chromaMutex.RUnlock()
330318
return chromaStyle
331319
}
332-
chromaMutex.RUnlock()
333320

334321
styleConfig := getTheme(themeName)
335322
style := styleConfig.Style
@@ -370,16 +357,19 @@ func GetChromaStyle(themeName string) *chroma.Style {
370357
chroma.Background: ChromaStyle(style.CodeBlock.Chroma.Background),
371358
})
372359

373-
chromaMutex.Lock()
374-
375360
if existingStyle, ok := chromaStyles.Registry[customThemeName]; ok {
376-
chromaMutex.Unlock()
377361
return existingStyle
378362
}
379363
chromaStyles.Register(newStyle)
380-
chromaMutex.Unlock()
381364
return newStyle
382365
}
383366

384-
return chromaStyles.Fallback
367+
switch themeName {
368+
case "dracula":
369+
return chromaStyles.Get("dracula")
370+
case "tokyo-night", "tokyonight":
371+
return chromaStyles.Get("tokyo-night")
372+
default:
373+
return chromaStyles.Fallback
374+
}
385375
}

0 commit comments

Comments
 (0)