MCPcopy
hub / github.com/cheat/cheat / Colorize

Method Colorize

internal/sheet/colorize.go:12–37  ·  view source on GitHub ↗

Colorize applies syntax-highlighting to a cheatsheet's Text.

(conf config.Config)

Source from the content-addressed store, hash-verified

10
11// Colorize applies syntax-highlighting to a cheatsheet's Text.
12func (s *Sheet) Colorize(conf config.Config) {
13
14 // if the syntax was not specified, default to bash
15 lex := s.Syntax
16 if lex == "" {
17 lex = "bash"
18 }
19
20 // write colorized text into a buffer
21 var buf bytes.Buffer
22 err := quick.Highlight(
23 &buf,
24 s.Text,
25 lex,
26 conf.Formatter,
27 conf.Style,
28 )
29
30 // if colorization somehow failed, do nothing
31 if err != nil {
32 return
33 }
34
35 // otherwise, swap the cheatsheet's Text with its colorized equivalent
36 s.Text = buf.String()
37}

Callers 5

TestColorizeFunction · 0.95
cmdViewFunction · 0.80
cmdSearchFunction · 0.80

Calls

no outgoing calls

Tested by 3

TestColorizeFunction · 0.76