package main import ( "fmt" "github.com/logrusorgru/aurora/v4" "golang.org/x/sys/unix" ) // TODO: // - bold of escaped output doesn't work. // - could use direct ANSI codes rather than aurora package. // - configurable colours. type Display struct { a *aurora.Aurora } func NewDisplay(noColour bool) *Display { if _, err := unix.IoctlGetTermios(1, unix.TCGETS); err != nil { noColour = true } a := aurora.New(aurora.WithColors(!noColour)) return &Display{ a: a, } } func (d *Display) Filename(name string) aurora.Value { return d.a.BgBlue(d.a.White(name)) } func (d *Display) LineNumber(lineNum int) aurora.Value { return d.a.Green(lineNum) } func (d *Display) Match(text string) aurora.Value { return d.a.Bold(text) } func (d *Display) TruncatedMarker() aurora.Value { return d.a.Magenta("…") } func (d *Display) TruncatedChars(charCount int) aurora.Value { return d.a.Faint(fmt.Sprintf("(%d chars)", charCount)) } func (d *Display) BadUTF8Char() aurora.Value { return d.a.Magenta("\uFFFD") } func (d *Display) CarriageReturn() aurora.Value { return d.a.Magenta(`\r`) } func (d *Display) UnprintableChar() aurora.Value { return d.a.Magenta(`·`) }