cmd/mbf: enable output colouring
Test / Create distribution (push) Successful in 58s
Test / Sandbox (push) Successful in 3m36s
Test / Hakurei (push) Successful in 6m11s
Test / Sandbox (race detector) (push) Successful in 7m44s
Test / Hakurei (race detector) (push) Successful in 9m57s
Test / ShareFS (push) Successful in 10m35s
Test / Flake checks (push) Successful in 1m30s

This respects the de facto standards, on top of checking stderr.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
cat
2026-07-30 05:16:39 +09:00
parent 6fb2065a51
commit 869820ec6d
3 changed files with 12 additions and 2 deletions
+5
View File
@@ -28,6 +28,8 @@ type cache struct {
idle bool idle bool
// Unset [pkg.CSuppressInit]. // Unset [pkg.CSuppressInit].
verboseInit bool verboseInit bool
// Whether to enable output colours.
color bool
// Unset [pkg.CExternShallow]. // Unset [pkg.CExternShallow].
deep bool deep bool
// Loaded artifact of [rosa.QEMU]. // Loaded artifact of [rosa.QEMU].
@@ -61,6 +63,9 @@ func (cache *cache) open() (err error) {
if !cache.deep { if !cache.deep {
cache.attr.Flags |= pkg.CExternShallow cache.attr.Flags |= pkg.CExternShallow
} }
if cache.color {
cache.attr.Flags |= pkg.CColourOutput
}
done := make(chan struct{}) done := make(chan struct{})
defer close(done) defer close(done)
+5
View File
@@ -92,6 +92,11 @@ func main() {
var cm cache var cm cache
defer func() { cm.Close() }() defer func() { cm.Close() }()
if cm.color = ext.Isatty(syscall.Stderr) &&
os.Getenv("NO_COLOR") == "" &&
os.Getenv("TERM") != "dumb"; cm.color {
log.SetPrefix("\x1b[2mmbf: \x1b[0m")
}
var ( var (
flagQuiet bool flagQuiet bool
+2 -2
View File
@@ -58,11 +58,11 @@ func getCache(t *testing.T) *pkg.Cache {
ctx, buildTestCacheCancel = signal.NotifyContext(context.Background(), ctx, buildTestCacheCancel = signal.NotifyContext(context.Background(),
syscall.SIGINT, syscall.SIGTERM) syscall.SIGINT, syscall.SIGTERM)
msg := message.New(log.New(os.Stderr, "rosa: ", 0)) msg := message.New(log.New(os.Stderr, "\x1b[2mrosa: \x1b[0m", 0))
msg.SwapVerbose(true) msg.SwapVerbose(true)
if buildTestCache, err = pkg.Open(ctx, msg, a, &pkg.CacheAttr{ if buildTestCache, err = pkg.Open(ctx, msg, a, &pkg.CacheAttr{
Flags: pkg.CSuppressInit, Flags: pkg.CSuppressInit | pkg.CColourOutput,
}); err != nil { }); err != nil {
t.Fatal(err) t.Fatal(err)
} }