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

  • Open
  • quality assurance status badge
Details
One participant
  • Phil
Owner
unassigned
Submitted by
Phil
Severity
normal
P
(address . guix-patches@gnu.org)
87wnhuekek.fsf@beadling.co.uk
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" <phil@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(-)

Toggle diff (18 lines)
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
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 54029@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 54029
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch