Skip to content

Commit

Permalink
fix: use mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jul 5, 2022
1 parent 8880d86 commit d44902c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ansi/codeblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ansi

import (
"io"
"sync"

"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma/quick"
Expand All @@ -13,6 +14,7 @@ import (
type CodeBlockElement struct {
Code string
Language string
mutex sync.Mutex
}

func chromaStyle(style StylePrimitive) string {
Expand Down Expand Up @@ -65,6 +67,7 @@ func (e *CodeBlockElement) Render(w io.Writer, ctx RenderContext) error {

if rules.Chroma != nil && ctx.options.ColorProfile > 1 {
theme = "charm"
e.mutex.Lock()
// Don't register the style if it's already registered.
_, ok := styles.Registry[theme]
if !ok {
Expand Down Expand Up @@ -103,6 +106,7 @@ func (e *CodeBlockElement) Render(w io.Writer, ctx RenderContext) error {
chroma.Background: chromaStyle(rules.Chroma.Background),
}))
}
e.mutex.Unlock()
}

iw := indent.NewWriterPipe(w, indentation+margin, func(wr io.Writer) {
Expand Down

0 comments on commit d44902c

Please sign in to comment.