unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#54029] [PATCH] allow user to force color when not a tty
@ 2022-02-16 18:28 Phil
  0 siblings, 0 replies; only message in thread
From: Phil @ 2022-02-16 18:28 UTC (permalink / raw)
  To: 54029

[-- Attachment #1: Type: text/plain, Size: 737 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-allow-user-to-force-color-when-not-a-tty.patch --]
[-- Type: text/x-patch, Size: 871 bytes --]

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(-)

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-16 20:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 18:28 [bug#54029] [PATCH] allow user to force color when not a tty Phil

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).