File: styles.go

package info (click to toggle)
usql 0.19.19-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,652 kB
  • sloc: sql: 1,115; sh: 643; ansic: 191; makefile: 60
file content (42 lines) | stat: -rw-r--r-- 975 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Package styles provides chroma styles based on the chroma styles but removing
// the backgrounds.
package styles

import (
	"sync"

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

// styles is the set of styles with their background colors removed.
var styles = struct {
	styles map[string]*chroma.Style
	sync.Mutex
}{
	styles: make(map[string]*chroma.Style),
}

// Get retrieves the equivalent chroma style.
func Get(name string) *chroma.Style {
	styles.Lock()
	defer styles.Unlock()
	if _, ok := styles.styles[name]; !ok {
		// get original style
		s := cstyles.Get(name)
		// create new entry map
		m := make(chroma.StyleEntries)
		for _, typ := range s.Types() {
			// skip background
			if typ == chroma.Background {
				continue
			}
			z := s.Get(typ)
			// unset background
			z.Background = chroma.Colour(0)
			m[typ] = z.String()
		}
		styles.styles[name] = chroma.MustNewStyle(s.Name, m)
	}
	return styles.styles[name]
}