AT Protocol IPLD-CAR Repository toolkit (CLI)
1package cli
2
3import (
4 "io"
5
6 "github.com/alecthomas/chroma"
7 "github.com/alecthomas/chroma/formatters"
8 "github.com/alecthomas/chroma/lexers"
9 "github.com/alecthomas/chroma/styles"
10)
11
12func Highlight(style string) func(w io.Writer, source string) {
13 // Determine lexer.
14 l := lexers.Get("json")
15 l = chroma.Coalesce(l)
16
17 // Determine formatter.
18 f := formatters.Get("terminal")
19 if f == nil {
20 f = formatters.Fallback
21 }
22 // Determine style.
23 s := styles.Get(style)
24 if s == nil {
25 s = styles.Fallback
26 }
27 return func(w io.Writer, source string) {
28 it, _ := l.Tokenise(nil, source)
29 f.Format(w, s, it)
30 }
31}