gg/display.go

55 lines
1.0 KiB
Go

package main
import (
"fmt"
"github.com/logrusorgru/aurora/v4"
"golang.org/x/sys/unix"
)
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) TruncatedBytes(byteCount int) aurora.Value {
return d.a.Faint(fmt.Sprintf("(%d bytes)", byteCount))
}
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(`·`)
}