File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed
Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,16 @@ This is useful when we need to test the exact output."
222222 (is (equal (fmt " Before exec~% Unwinding happened~% exec happened" )
223223 result))))
224224
225+ (5am :test test-color
226+ (let* ((script (asdf :system-relative-pathname :kiln " test/test-color.lisp" )))
227+ (is (equal (trim-whitespace (kiln-exact-output script)) " NIL" ))
228+ (let ((cmd :*cmd-env* (acons " NO_COLOR" " 1" cmd :*cmd-env* )))
229+ (is (equal (trim-whitespace (kiln-exact-output script)) " NIL" )))
230+ (let ((cmd :*cmd-env* (acons " CLICOLOR_FORCE" " 1" cmd :*cmd-env* )))
231+ (is (equal (trim-whitespace (kiln-exact-output script)) " T" )))
232+ (let ((cmd :*cmd-env* (acons " FORCE_COLOR" " 1" cmd :*cmd-env* )))
233+ (is (equal (trim-whitespace (kiln-exact-output script)) " T" )))))
234+
225235(5am :test entry-point
226236 (with-templated-test-system (:name " kiln-entry-point-system"
227237 :path path
Original file line number Diff line number Diff line change 3030(defvar *color* :auto )
3131(declaim (type color-policy *color* ))
3232
33- (defun env-no-color-p ()
34- (uiop :getenvp " NO_COLOR" ))
35-
3633(-> stream-tty-p (stream (member :input :output ))
3734 (values (or null stream ) boolean ))
3835(defun stream-tty-p (stream direction)
@@ -86,8 +83,18 @@ if sure, NIL if unsure)."
8683 (values nil nil ))))
8784
8885(defun want-color-p (stream )
89- (and (not (env-no-color-p))
90- (stream-tty-p stream :output )))
86+ " Test if STREAM should use color.
87+ This depends on whether STREAM is a TTY stream, and the value of the
88+ environment variables NO_COLOR, CLICOLOR_FORCE, and FORCE_COLOR."
89+ (let ((no-color (uiop :getenvp " NO_COLOR" )))
90+ (if (and no-color (not (equal no-color " 0" )))
91+ nil
92+ (let ((force
93+ (or (uiop :getenv " CLICOLOR_FORCE" )
94+ (uiop :getenvp " FORCE_COLOR" ))))
95+ (if (and force (not (equal force " 0" )))
96+ t
97+ (stream-tty-p stream :output ))))))
9198
9299(defun ttyp ()
93100 " Return T if there is a controlling TTY."
You can’t perform that action at this time.
0 commit comments