Subject: [PATCH] allow user to force color when not a tty

From: Phil <[email-masked]>
Date: Wed, 16 Feb 2022 18:28:03 +0000

Hi,

At the moment there doesn't seem to be any way to request ANSI stdout/err
from Guix if your output is not a tty.  However when capturing Guix
output for display inside a front-end for running jobs across many
servers (eg Jenkins, Rundeck, etc) - these tools are often capable of
rendering ANSI output captured from console tools like Guix.  Other
tools (eg py-test, flake8) often allow the user to explicitly force
color output even when a tty is not detected.  The attached patch is a
trivial attempt at make such an option available in Guix too.

I've done this in the least disruptive way possible, which is to
introduce an new env var such that users of the NO_COLOR env var will
get continuity of functionality.

Cheers,
Phil

>From 010be2b6d4b1ec865a686345116deb92570636e2 Mon Sep 17 00:00:00 2001
From: "Phil.Beadling" <[email-masked]>
Date: Wed, 16 Feb 2022 17:40:32 +0000
Subject: [PATCH] allow user to force color when not a tty

---
 guix/colors.scm | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/guix/colors.scm b/guix/colors.scm
index 3031f54799..c57c139864 100644
--- a/guix/colors.scm
+++ b/guix/colors.scm
@@ -131,8 +131,9 @@ that subsequent output will not have any colors in effect."
 
 (define (color-output? port)
   "Return true if we should write colored output to PORT."
-  (and (not (getenv "NO_COLOR"))
-       (isatty?* port)))
+  (or (getenv "GUIX_COLOR_OUTPUT")
+      (and (not (getenv "NO_COLOR"))
+           (isatty?* port))))
 
 (define (coloring-procedure color)
   "Return a procedure that applies COLOR to the given string."
-- 
2.25.1