GNU bug report logs - #54029
[PATCH] allow user to force color when not a tty

Previous Next

Package: guix-patches;

Reported by: Phil <phil <at> beadling.co.uk>

Date: Wed, 16 Feb 2022 18:57:02 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 54029 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#54029; Package guix-patches. (Wed, 16 Feb 2022 18:57:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Phil <phil <at> beadling.co.uk>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Wed, 16 Feb 2022 18:57:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Phil <phil <at> beadling.co.uk>
To: guix-patches <at> gnu.org
Subject: [PATCH] allow user to force color when not a tty
Date: Wed, 16 Feb 2022 18:28:03 +0000
[Message part 1 (text/plain, inline)]
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

[0001-allow-user-to-force-color-when-not-a-tty.patch (text/x-patch, inline)]
From 010be2b6d4b1ec865a686345116deb92570636e2 Mon Sep 17 00:00:00 2001
From: "Phil.Beadling" <phil <at> beadling.co.uk>
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


This bug report was last modified 2 years and 75 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.