1
0
mirror of https://github.com/TomWright/dasel.git synced 2022-05-22 02:32:45 +03:00
Files
dasel-data-selector/storage/colourise.go
2022-03-28 13:46:44 +01:00

26 lines
784 B
Go

package storage
import (
"bytes"
"github.com/alecthomas/chroma/quick"
)
// ColouriseStyle is the style used when colourising output.
const ColouriseStyle = "solarized-dark256"
// ColouriseFormatter is the formatter used when colourising output.
const ColouriseFormatter = "terminal"
// ColouriseBuffer colourises the given buffer in-place.
func ColouriseBuffer(content *bytes.Buffer, lexer string) error {
contentString := content.String()
content.Reset()
return quick.Highlight(content, contentString, lexer, ColouriseFormatter, ColouriseStyle)
}
// Colourise colourises the given string.
func Colourise(content string, lexer string) (*bytes.Buffer, error) {
buf := new(bytes.Buffer)
return buf, quick.Highlight(buf, content, lexer, ColouriseFormatter, ColouriseStyle)
}