github.com/tomwright/dasel@v1.27.3/storage/colourise.go (about)

     1  package storage
     2  
     3  import (
     4  	"bytes"
     5  	"github.com/alecthomas/chroma/quick"
     6  )
     7  
     8  // ColouriseStyle is the style used when colourising output.
     9  const ColouriseStyle = "solarized-dark256"
    10  
    11  // ColouriseFormatter is the formatter used when colourising output.
    12  const ColouriseFormatter = "terminal"
    13  
    14  // ColouriseBuffer colourises the given buffer in-place.
    15  func ColouriseBuffer(content *bytes.Buffer, lexer string) error {
    16  	contentString := content.String()
    17  	content.Reset()
    18  	return quick.Highlight(content, contentString, lexer, ColouriseFormatter, ColouriseStyle)
    19  }
    20  
    21  // Colourise colourises the given string.
    22  func Colourise(content string, lexer string) (*bytes.Buffer, error) {
    23  	buf := new(bytes.Buffer)
    24  	return buf, quick.Highlight(buf, content, lexer, ColouriseFormatter, ColouriseStyle)
    25  }