v0.1.1 true color extracted to a standalone package, lut256 lazy build
This commit is contained in:
@@ -48,6 +48,10 @@ func New(w io.Writer) *Printer {
|
||||
}
|
||||
p.color = p.tty != nil && os.Getenv("NO_COLOR") == ""
|
||||
p.mode = terminal.DetectColorMode()
|
||||
// Keep the LUT build out of the first Paint call
|
||||
if p.color && p.mode == terminal.ColorMode256 {
|
||||
terminal.WarmPalette256()
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -7,22 +7,23 @@ import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/lixenwraith/color"
|
||||
"github.com/lixenwraith/terminal"
|
||||
)
|
||||
|
||||
// Style describes text appearance; zero value is unstyled.
|
||||
// Composable: inline.Fg(terminal.Amber).Attr(terminal.AttrBold)
|
||||
type Style struct {
|
||||
fg, bg terminal.RGB
|
||||
fg, bg color.RGB
|
||||
hasFg, hasBg bool
|
||||
attr terminal.Attr
|
||||
}
|
||||
|
||||
// Fg starts a style with foreground color
|
||||
func Fg(c terminal.RGB) Style { return Style{fg: c, hasFg: true} }
|
||||
func Fg(c color.RGB) Style { return Style{fg: c, hasFg: true} }
|
||||
|
||||
// Bg sets background color
|
||||
func (s Style) Bg(c terminal.RGB) Style { s.bg, s.hasBg = c, true; return s }
|
||||
func (s Style) Bg(c color.RGB) Style { s.bg, s.hasBg = c, true; return s }
|
||||
|
||||
// Attr adds attribute bits
|
||||
func (s Style) Attr(a terminal.Attr) Style { s.attr |= a; return s }
|
||||
|
||||
Reference in New Issue
Block a user