v0.1.9 inline: ansi 16 colors, terminals without size

This commit is contained in:
lixen committed 2026-10-04 02:56:31 -04:00
1 parent aa004f3aba
commit 070131c7fd
3 files changed
+11 -9

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ module github.com/lixenwraith/terminal
go 1.27.1 go 1.27.1
require ( require (
github.com/lixenwraith/color v0.0.0-20260719094342-615e11bc7897 github.com/lixenwraith/color v0.1.3
golang.org/x/sys v0.48.0 golang.org/x/sys v0.48.0
golang.org/x/term v0.46.0 golang.org/x/term v0.46.0
) )
+4 -2
View File
@@ -1,5 +1,7 @@
github.com/lixenwraith/color v0.0.0-20260719094342-615e11bc7897 h1:YkTK1vIzG6sqKRKaeUdkPyMT2laithY1d8tCqyId77U= github.com/lixenwraith/color v0.0.0-20261004042426-912b93708f95 h1:64BAixbU3RAsDacvCDgxMKKddPuMxL0h2KKsqsG9iWU=
github.com/lixenwraith/color v0.0.0-20260719094342-615e11bc7897/go.mod h1:p02MsAGqlmZu3sc6BPYCKmaedF+lqBoijnuu5cOrYeo= github.com/lixenwraith/color v0.0.0-20261004042426-912b93708f95/go.mod h1:p02MsAGqlmZu3sc6BPYCKmaedF+lqBoijnuu5cOrYeo=
github.com/lixenwraith/color v0.1.3 h1:vSuvtU4zh1mIZS/7UGHmMdsTr+a7eCjUYGbou7kzFn4=
github.com/lixenwraith/color v0.1.3/go.mod h1:L/I3Vxp6pqslAIzWyZGgKCm2lyStHCA4vKaUoMUm7bU=
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo= golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE= golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE=
+6 -6
View File
@@ -23,6 +23,7 @@ import (
"sync" "sync"
"github.com/lixenwraith/color" "github.com/lixenwraith/color"
"golang.org/x/term"
) )
// Internal color capability representation // Internal color capability representation
@@ -53,14 +54,13 @@ type Printer struct {
drawn int // lines currently on screen (may be clamped below len(live)) drawn int // lines currently on screen (may be clamped below len(live))
} }
// New creates a Printer for w. Terminal detection via size probe; // New creates a Printer for w. A terminal that reports no size, a serial
// styling defaults on for terminals with NO_COLOR unset and TERM not dumb. // line, is still one, at 80x24; styling defaults on for terminals with
// NO_COLOR unset and TERM not dumb.
func New(w io.Writer) *Printer { func New(w io.Writer) *Printer {
p := &Printer{w: bufio.NewWriter(w)} p := &Printer{w: bufio.NewWriter(w)}
if f, isFile := w.(*os.File); isFile { if f, isFile := w.(*os.File); isFile && term.IsTerminal(int(f.Fd())) {
if _, _, ok := windowSize(f); ok { p.tty = f
p.tty = f
}
} }
p.color = p.tty != nil && os.Getenv("NO_COLOR") == "" && os.Getenv("TERM") != "dumb" p.color = p.tty != nil && os.Getenv("NO_COLOR") == "" && os.Getenv("TERM") != "dumb"
p.mode = detectColorMode() p.mode = detectColorMode()