aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-07-30 05:16:39 +0900
committerOphestra <cat@gensokyo.uk>2026-07-30 05:16:39 +0900
commit869820ec6de3bc26d98e5e7420500d0fbde9408d (patch)
tree297bc6e252cbeacb2af8779b684a14dc5bc16d1f
parent6fb2065a517f00dc6f6270b9310e48586b902e26 (diff)
cmd/mbf: enable output colouring
This respects the de facto standards, on top of checking stderr. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--cmd/mbf/cache.go5
-rw-r--r--cmd/mbf/main.go5
-rw-r--r--internal/rosa/rosa_test.go4
3 files changed, 12 insertions, 2 deletions
diff --git a/cmd/mbf/cache.go b/cmd/mbf/cache.go
index 7134e5d2..b4bc7126 100644
--- a/cmd/mbf/cache.go
+++ b/cmd/mbf/cache.go
@@ -28,6 +28,8 @@ type cache struct {
idle bool
// Unset [pkg.CSuppressInit].
verboseInit bool
+ // Whether to enable output colours.
+ color bool
// Unset [pkg.CExternShallow].
deep bool
// Loaded artifact of [rosa.QEMU].
@@ -61,6 +63,9 @@ func (cache *cache) open() (err error) {
if !cache.deep {
cache.attr.Flags |= pkg.CExternShallow
}
+ if cache.color {
+ cache.attr.Flags |= pkg.CColourOutput
+ }
done := make(chan struct{})
defer close(done)
diff --git a/cmd/mbf/main.go b/cmd/mbf/main.go
index d464fd54..db6c1a0a 100644
--- a/cmd/mbf/main.go
+++ b/cmd/mbf/main.go
@@ -92,6 +92,11 @@ func main() {
var cm cache
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 (
flagQuiet bool
diff --git a/internal/rosa/rosa_test.go b/internal/rosa/rosa_test.go
index c2a6451c..8d0917bb 100644
--- a/internal/rosa/rosa_test.go
+++ b/internal/rosa/rosa_test.go
@@ -58,11 +58,11 @@ func getCache(t *testing.T) *pkg.Cache {
ctx, buildTestCacheCancel = signal.NotifyContext(context.Background(),
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)
if buildTestCache, err = pkg.Open(ctx, msg, a, &pkg.CacheAttr{
- Flags: pkg.CSuppressInit,
+ Flags: pkg.CSuppressInit | pkg.CColourOutput,
}); err != nil {
t.Fatal(err)
}