internal/pkg: highlight cache verbose output
Test / Create distribution (push) Successful in 53s
Test / Sandbox (push) Successful in 2m49s
Test / Hakurei (push) Successful in 4m33s
Test / Sandbox (race detector) (push) Successful in 5m50s
Test / Hakurei (race detector) (push) Successful in 7m11s
Test / ShareFS (push) Successful in 7m34s
Test / Flake checks (push) Successful in 1m21s

This highlights sections of messages, increasing readability in some cases.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
cat
2026-07-30 17:35:49 +09:00
parent aa9952cd9e
commit 1567a3e582
+56 -16
View File
@@ -779,6 +779,8 @@ type Cache struct {
wg sync.WaitGroup wg sync.WaitGroup
// Reports new cures and passed to [Artifact]. // Reports new cures and passed to [Artifact].
msg message.Msg msg message.Msg
// Select graphics rendition sequences, populated by Open.
sgrRes, sgrIdent, sgrWarn, sgrErr string
// Directory where all [Cache] related files are placed. // Directory where all [Cache] related files are placed.
base *check.Absolute base *check.Absolute
@@ -1511,10 +1513,10 @@ func (c *Cache) openFile(
id := c.Ident(f) id := c.Ident(f)
if c.msg.IsVerbose() { if c.msg.IsVerbose() {
rn := reportName(f, id) rn := reportName(f, id)
c.msg.Verbosef("curing %s in memory...", rn) c.msg.Verbosef("curing %s%s%s in memory...", c.sgrIdent, rn, c.sgrRes)
defer func() { defer func() {
if err == nil { if err == nil {
c.msg.Verbosef("opened %s for reading", rn) c.msg.Verbosef("opened %s%s%s for reading", c.sgrIdent, rn, c.sgrRes)
} }
}() }()
} }
@@ -1893,7 +1895,10 @@ func (mr *measuredReader) Close() (err error) {
} }
if n > 0 { if n > 0 {
mr.c.msg.Verbosef("missed %d bytes on measured reader", n) mr.c.msg.Verbosef(
"%smissed %d bytes on measured reader%s",
mr.c.sgrWarn, n, mr.c.sgrRes,
)
} }
if err = mr.r.Close(); err != nil { if err = mr.r.Close(); err != nil {
@@ -2154,8 +2159,9 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) (
) )
if errors.Is(err, os.ErrExist) { if errors.Is(err, os.ErrExist) {
c.msg.Verbosef( c.msg.Verbosef(
"creating alternative over %s for artifact %s", "creating alternative over %s%s%s for artifact %s%s%s",
Encode(substitute.Value()), ids, c.sgrIdent, Encode(substitute.Value()), c.sgrRes,
c.sgrIdent, ids, c.sgrRes,
) )
err = nil err = nil
} }
@@ -2198,15 +2204,18 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) (
whence = WNew whence = WNew
if c.msg.IsVerbose() { if c.msg.IsVerbose() {
rn := reportName(a, id) rn := reportName(a, id)
c.msg.Verbosef("curing %s...", rn) c.msg.Verbosef("curing %s%s%s...", c.sgrIdent, rn, c.sgrRes)
defer func() { defer func() {
if err != nil { if err != nil {
return return
} }
if checksums != "" { if checksums != "" {
c.msg.Verbosef("cured %s checksum %s", rn, checksums) c.msg.Verbosef(
"cured %s%s%s checksum %s%s%s",
c.sgrIdent, rn, c.sgrRes,
c.sgrIdent, checksums, c.sgrRes)
} else { } else {
c.msg.Verbosef("cured %s", rn) c.msg.Verbosef("cured %s%s%s", c.sgrIdent, rn, c.sgrRes)
} }
}() }()
} }
@@ -2301,7 +2310,11 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) (
c.exitCure(a, curesExempt) c.exitCure(a, curesExempt)
if err != nil { if err != nil {
if c.msg.IsVerbose() { if c.msg.IsVerbose() {
c.msg.Verbosef("cure file %s: %v", reportName(f, id), err) c.msg.Verbosef(
"cure file %s%s%s: %s%v%s",
c.sgrIdent, reportName(f, id), c.sgrRes,
c.sgrErr, err, c.sgrRes,
)
} }
return return
} }
@@ -2348,7 +2361,11 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) (
c.exitCure(a, curesExempt) c.exitCure(a, curesExempt)
if err != nil { if err != nil {
if c.msg.IsVerbose() { if c.msg.IsVerbose() {
c.msg.Verbosef("cure trivial %s: %v", reportName(ca, id), err) c.msg.Verbosef(
"cure trivial %s%s%s: %s%v%s",
c.sgrIdent, reportName(ca, id), c.sgrRes,
c.sgrErr, err, c.sgrRes,
)
} }
return return
} }
@@ -2358,7 +2375,11 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) (
var externChecksum unique.Handle[Checksum] var externChecksum unique.Handle[Checksum]
if externChecksum, err = c.tryExtern(ctx, id); err != nil { if externChecksum, err = c.tryExtern(ctx, id); err != nil {
if c.msg.IsVerbose() { if c.msg.IsVerbose() {
c.msg.Verbosef("extern %s: %v", reportName(ca, id), err) c.msg.Verbosef(
"extern %s%s%s: %s%v%s",
c.sgrIdent, reportName(ca, id), c.sgrRes,
c.sgrErr, err, c.sgrRes,
)
} }
return return
} }
@@ -2398,8 +2419,8 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) (
if sum == zeroChecksum { if sum == zeroChecksum {
if c.msg.IsVerbose() { if c.msg.IsVerbose() {
c.msg.Verbosef( c.msg.Verbosef(
"input %s not available", "input %s%s%s not available",
reportName(d, did), c.sgrIdent, reportName(d, did), c.sgrRes,
) )
} }
err = HangingInputError(did) err = HangingInputError(did)
@@ -2463,7 +2484,11 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) (
if checksum != zeroChecksum && externChecksum != checksum { if checksum != zeroChecksum && externChecksum != checksum {
err = &ChecksumMismatchError{externChecksum.Value(), checksum.Value()} err = &ChecksumMismatchError{externChecksum.Value(), checksum.Value()}
if c.msg.IsVerbose() { if c.msg.IsVerbose() {
c.msg.Verbosef("extern %s: %v", reportName(ca, id), err) c.msg.Verbosef(
"extern %s%s%s: %s%v%s",
c.sgrIdent, reportName(ca, id), c.sgrRes,
c.sgrErr, err, c.sgrRes,
)
} }
return return
} }
@@ -2512,7 +2537,11 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) (
} }
if err != nil { if err != nil {
if c.msg.IsVerbose() { if c.msg.IsVerbose() {
c.msg.Verbosef("cure %s: %v", reportName(ca, id), err) c.msg.Verbosef(
"cure %s%s%s: %s%v%s",
c.sgrIdent, reportName(ca, id), c.sgrRes,
c.sgrErr, err, c.sgrRes,
)
} }
return return
} }
@@ -2563,7 +2592,11 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) (
Want: checksum.Value(), Want: checksum.Value(),
} }
if c.msg.IsVerbose() { if c.msg.IsVerbose() {
c.msg.Verbosef("validate %s: %v", reportName(a, id), err) c.msg.Verbosef(
"validate %s%s%s: %s%v%s",
c.sgrIdent, reportName(a, id), c.sgrRes,
c.sgrErr, err, c.sgrRes,
)
} }
return return
} }
@@ -2898,6 +2931,13 @@ func Open(
return nil, UnsupportedVariantError(s) return nil, UnsupportedVariantError(s)
} }
if a.Flags&CColourOutput != 0 {
c.sgrRes = "\x1b[0m"
c.sgrIdent = "\x1b[1m"
c.sgrWarn = "\x1b[35m"
c.sgrErr = "\x1b[1;31m"
}
return &c, nil return &c, nil
} }