summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergio Pastor Pérez <sergio.pastor-perez@inria.fr>2026-06-25 16:38:27 +0200
committerLudovic Courtès <ludo@gnu.org>2026-07-02 19:17:19 +0200
commite7be2ffdd8c5c60670aefb51dc5e10ce601dd3d9 (patch)
tree9cae3d683783fb8946fd150128b0aa033b90714e
parent664d29820d798d9a5c5f2e18c0d53688cbf15f91 (diff)
colors: Disable hyperlinks on dumb terminals.
Before this change, Emacs was being handled as a special case. By relying on the TERM variable, Emacs is covered in addition to other terminals which do not support color. Additionally this change offers some more granularity to Emacs as certain setup can support hyperlinks, in those cases the users are able to enable them by adjusting the TERM variable in their Emacs processes. * guix/colors.scm: (supports-hyperlinks?): Remove hyperlinks for dumb terminals instead of any Emacs process. (dumb-terminal?): New procedure. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Merges: #9524
-rw-r--r--guix/colors.scm19
1 files changed, 16 insertions, 3 deletions
diff --git a/guix/colors.scm b/guix/colors.scm
index 543f4c3ec50..6603642d249 100644
--- a/guix/colors.scm
+++ b/guix/colors.scm
@@ -137,6 +137,13 @@ that subsequent output will not have any colors in effect."
137 "Return true if PORT is a tty. Memoize the result." 137 "Return true if PORT is a tty. Memoize the result."
138 (isatty? port))) 138 (isatty? port)))
139 139
140(define dumb-terminal?
141 (mlambdaq ()
142 "Return #t if TERM=dumb or if TERM is not set. Memoize the result."
143 (match (getenv "TERM")
144 ((or "dumb" #f) #t)
145 (_ #f))))
146
140(define (color-output? port) 147(define (color-output? port)
141 "Return true if we should write colored output to PORT." 148 "Return true if we should write colored output to PORT."
142 (and (not (getenv "NO_COLOR")) 149 (and (not (getenv "NO_COLOR"))
@@ -236,10 +243,16 @@ documented at
236 "Return true if PORT is a terminal that supports hyperlink escapes." 243 "Return true if PORT is a terminal that supports hyperlink escapes."
237 ;; Note that terminals are supposed to ignore OSC escapes they don't 244 ;; Note that terminals are supposed to ignore OSC escapes they don't
238 ;; understand (this is the case of xterm as of version 349, for instance.) 245 ;; understand (this is the case of xterm as of version 349, for instance.)
239 ;; However, Emacs comint as of 26.3 does not ignore it and instead lets it 246 ;;
240 ;; through, hence the 'INSIDE_EMACS' special case below. 247 ;; Emacs users can add 'ansi-osc-compilation-filter' to
248 ;; 'compilation-filter-hook' to propertize the hyperlinks, in that case,
249 ;; remember to set TERM to something other than the default. For example, a
250 ;; user of 'M-x shell' that is using Bash, may create a
251 ;; '~/.emacs.d/init_bash.sh' file with 'export TERM=eterm-color'. For the
252 ;; compilation filters to affect 'M-x shell', one can enable
253 ;; 'compilation-shell-minor-mode'.
241 (and (isatty?* port) 254 (and (isatty?* port)
242 (not (getenv "INSIDE_EMACS")))) 255 (not (dumb-terminal?))))
243 256
244(define* (file-hyperlink file #:optional (text file)) 257(define* (file-hyperlink file #:optional (text file))
245 "Return TEXT with escapes for a hyperlink to FILE." 258 "Return TEXT with escapes for a hyperlink to FILE."