posh/pkg/util/prints/code.go
Kevin Franklin Kim 7af80a3351 feat: add utils
2023-01-06 10:27:11 +01:00

19 lines
385 B
Go

package prints
import (
"os"
"strings"
"github.com/alecthomas/chroma/quick"
"github.com/foomo/posh/pkg/log"
)
func Code(l log.Logger, title, code, lexer string) {
border := strings.Repeat("-", 80)
l.Infof("\n%s\n%s\n%s", border, title, border)
if err := quick.Highlight(os.Stdout, code, lexer, "terminal", "monokai"); err != nil {
l.Debug(err.Error())
l.Print(code)
}
}