internal/pkg: optionally colour output
Test / Create distribution (push) Successful in 53s
Test / Sandbox (push) Successful in 2m55s
Test / Hakurei (push) Successful in 5m2s
Test / Sandbox (race detector) (push) Successful in 6m19s
Test / ShareFS (push) Successful in 8m41s
Test / Hakurei (race detector) (push) Successful in 8m49s
Test / Flake checks (push) Successful in 1m29s

This increases readability in some cases.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
cat
2026-07-30 05:15:19 +09:00
parent 698fd2d66a
commit 6fb2065a51
2 changed files with 18 additions and 4 deletions
+15 -4
View File
@@ -444,7 +444,7 @@ func scanVerbose(
msg message.Msg, msg message.Msg,
cancel context.CancelFunc, cancel context.CancelFunc,
done chan<- struct{}, done chan<- struct{},
prefix string, prefix, suffix string,
r io.Reader, r io.Reader,
) { ) {
defer close(done) defer close(done)
@@ -454,7 +454,7 @@ func scanVerbose(
bufio.MaxScanTokenSize<<12, bufio.MaxScanTokenSize<<12,
) )
for s.Scan() { for s.Scan() {
msg.Verbose(prefix, s.Text()) msg.Verbose(prefix, s.Text()+suffix)
} }
if err := s.Err(); err != nil && !errors.Is(err, os.ErrClosed) { if err := s.Err(); err != nil && !errors.Is(err, os.ErrClosed) {
cancel() cancel()
@@ -728,14 +728,25 @@ func (a *execArtifact) cure(f *FContext, hostNet bool) (err error) {
brStdout, brStderr := f.cache.getReader(stdout), f.cache.getReader(stderr) brStdout, brStderr := f.cache.getReader(stdout), f.cache.getReader(stderr)
stdoutDone, stderrDone := make(chan struct{}), make(chan struct{}) stdoutDone, stderrDone := make(chan struct{}), make(chan struct{})
var suffix, prefixO, prefixE string
if f.cache.attr.Flags&CColourOutput != 0 {
suffix = "\x1b[0m"
prefixO = "\x1b[1;37m(" + a.name + ")\x1b[0m"
prefixE = "\x1b[1;97m(" + a.name + ")\x1b[0m"
} else {
prefixO = "(" + a.name + ":1)"
prefixE = "(" + a.name + ":2)"
}
go scanVerbose( go scanVerbose(
msg, cancel, stdoutDone, msg, cancel, stdoutDone,
"("+a.name+":1)", prefixO, suffix,
io.TeeReader(brStdout, status), io.TeeReader(brStdout, status),
) )
go scanVerbose( go scanVerbose(
msg, cancel, stderrDone, msg, cancel, stderrDone,
"("+a.name+":2)", prefixE, suffix,
io.TeeReader(brStderr, status), io.TeeReader(brStderr, status),
) )
defer func() { defer func() {
+3
View File
@@ -721,6 +721,9 @@ const (
// CExternShallow arranges for only non-flood inputs to be fetched when // CExternShallow arranges for only non-flood inputs to be fetched when
// curing an [Artifact] available via the external cache. // curing an [Artifact] available via the external cache.
CExternShallow CExternShallow
// CColourOutput enables output colouring via ANSI control sequences.
CColourOutput
) )
// toplevel holds [context.WithCancel] over caller-supplied context, where all // toplevel holds [context.WithCancel] over caller-supplied context, where all