Skip to content

Commit

Permalink
Enable ANSI escape sequences on CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Jan 6, 2024
1 parent eafd608 commit dda6b18
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/cli.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(:import-from #:qlot/logger
#:message
#:*logger-message-stream*
#:*terminal*
#:clear-whisper)
(:import-from #:qlot/errors
#:missing-projects
Expand Down Expand Up @@ -690,7 +691,10 @@ OPTIONS:
(uiop:quit -1))

(defun qlot-command (&optional $1 &rest argv)
(let ((*enable-color* (null (uiop:getenvp "QLOT_NO_TERMINAL"))))
(let* ((no-terminal-env (uiop:getenvp "QLOT_NO_TERMINAL"))
(*enable-color* (not no-terminal-env))
(*terminal* (or (not no-terminal-env)
(uiop:getenvp "CI"))))
(handler-bind ((qlot/errors:qlot-warning
(lambda (c)
(warn-message "WARNING: ~A" c)
Expand Down
2 changes: 2 additions & 0 deletions src/install.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#:distify)
(:import-from #:qlot/logger
#:*enable-whisper*
#:*terminal*
#:message
#:debug-log)
(:import-from #:qlot/secure-downloader
Expand Down Expand Up @@ -262,6 +263,7 @@ exec /bin/sh \"$CURRENT/../~A\" \"$@\"
(typep source 'source-local))
sources))
(bt2:*default-special-bindings* (append `((*enable-color* . ,*enable-color*)
(*terminal* . ,*terminal*)
(*enable-whisper* . nil)
(,(uiop:intern* '#:*fetch-scheme-functions* '#:ql-http) . ',(symbol-value (uiop:intern* '#:*fetch-scheme-functions* '#:ql-http))))
bt2:*default-special-bindings*))
Expand Down
10 changes: 5 additions & 5 deletions src/logger.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#:*logger-debug-stream*
#:*debug*
#:*enable-whisper*
#:*terminal*
#:whisper
#:clear-whisper
#:message
Expand All @@ -23,17 +24,16 @@

(defvar *previous-progress* "")

(defparameter *padding* "- ")
(defvar *terminal* nil)

(defun terminal-p ()
(not (uiop:getenvp "QLOT_NO_TERMINAL")))
(defparameter *padding* "- ")

(defun whisper (format-control &rest format-arguments)
(when *enable-whisper*
(let* ((out *logger-message-stream*)
(text (apply #'format nil format-control format-arguments))
(text (concatenate 'string *padding* text)))
(when (terminal-p)
(when *terminal*
(format out "~C[2K" #\Esc))
(write-char #\Return out)
(write-string (color-text :gray text) out)
Expand All @@ -43,7 +43,7 @@
(defun clear-whisper ()
(when (= 0 (length *previous-progress*))
(return-from clear-whisper))
(when (terminal-p)
(when *terminal*
(format *logger-message-stream* "~C[2K" #\Esc))
(write-char #\Return *logger-message-stream*)
(force-output *logger-message-stream*)
Expand Down
13 changes: 6 additions & 7 deletions src/progress.lisp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(defpackage #:qlot/progress
(:use #:cl)
(:import-from #:qlot/logger
#:*terminal*)
(:import-from #:qlot/color
#:color-text)
(:import-from #:bordeaux-threads)
Expand Down Expand Up @@ -73,23 +75,20 @@

(defvar *progress-output* nil)

(defun terminal-p ()
(not (uiop:getenvp "QLOT_NO_TERMINAL")))

(defun move-up (n)
(when (terminal-p)
(when *terminal*
(format *progress-output* "~C[~DA" #\Esc n)))

(defun clear-line ()
(when (terminal-p)
(when *terminal*
(format *progress-output* "~C[2K" #\Esc)))

(defmacro with-excursion ((stream) &body body)
`(let ((*progress-output* ,stream))
(when (terminal-p)
(when *terminal*
(format *progress-output* "~C[s" #\Esc))
(prog1 (progn ,@body)
(when (terminal-p)
(when *terminal*
(format *progress-output* "~C[u" #\Esc))
(force-output *progress-output*))))

Expand Down

0 comments on commit dda6b18

Please sign in to comment.