Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chroma): export charm themes #195

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(ansi): register chroma themes in NewRenderContext
aymanbagabas committed Oct 17, 2022
commit 246f0ef2a3f2973ca0ccd2317f18fc02065e91d8
10 changes: 10 additions & 0 deletions ansi/chroma.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package ansi

import (
"sync"

"github.com/alecthomas/chroma/v2"
"github.com/alecthomas/chroma/v2/styles"
)

var (
// mutex for synchronizing access to the chroma style registry.
// Related https://github.com/alecthomas/chroma/pull/650
mutex = sync.Mutex{}
)

func chromaStyle(style StylePrimitive) string {
var s string

@@ -48,6 +56,7 @@ func ChromaRegister(cfg *StyleConfig) *chroma.Style {
return nil
}

mutex.Lock()
// Register the theme if it doesn't already exist.
_, ok := styles.Registry[theme]
if !ok && rules.Chroma != nil {
@@ -89,6 +98,7 @@ func ChromaRegister(cfg *StyleConfig) *chroma.Style {
),
)
}
mutex.Unlock()

return style
}
1 change: 1 addition & 0 deletions ansi/context.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ type RenderContext struct {

// NewRenderContext returns a new RenderContext.
func NewRenderContext(options Options) RenderContext {
ChromaRegister(&options.Styles)
return RenderContext{
options: options,
blockStack: &BlockStack{},