diff --git a/env.go b/env.go index fc38790..2a4e355 100644 --- a/env.go +++ b/env.go @@ -161,7 +161,8 @@ func envColorProfile(env map[string]string) (p Profile) { p = ANSI } - if ti, err := terminfo.Load(term); err == nil { + ti, err := terminfo.Load(term) + if err == nil { extbools := ti.ExtBoolCapsShort() if _, ok := extbools["RGB"]; ok { p = TrueColor diff --git a/profile.go b/profile.go index 6537784..e6ed78f 100644 --- a/profile.go +++ b/profile.go @@ -12,15 +12,15 @@ import ( type Profile byte const ( - // TrueColor, 24-bit color profile + // TrueColor, 24-bit color profile. TrueColor Profile = iota - // ANSI256, 8-bit color profile + // ANSI256, 8-bit color profile. ANSI256 - // ANSI, 4-bit color profile + // ANSI, 4-bit color profile. ANSI - // Ascii, uncolored profile - Ascii // nolint: revive - // NoTTY, not a terminal profile + // Ascii, uncolored profile. + Ascii //nolint:revive + // NoTTY, not a terminal profile. NoTTY ) diff --git a/writer.go b/writer.go index 6367f06..e58fe0f 100644 --- a/writer.go +++ b/writer.go @@ -40,8 +40,13 @@ func (w *Writer) Write(p []byte) (int, error) { return w.Forward.Write(p) case NoTTY: return io.WriteString(w.Forward, ansi.Strip(string(p))) + default: + return w.downsample(p) } +} +// downsample downgrades the given text to the appropriate color profile. +func (w *Writer) downsample(p []byte) (int, error) { var buf bytes.Buffer var state byte