fix: wrap CSI terminal query in with-timeout 0.3s

The blocking read-char in %query-terminal-size could hang if the
terminal doesn't respond to CSI 18 t. Wrapped in
sb-ext:with-timeout 0.3 to abort if no response.
This commit is contained in:
2026-05-14 10:17:59 -04:00
parent 5a3b882f93
commit 920545dafb

View File

@@ -9,15 +9,14 @@ Returns (values cols rows) or nil."
:fill-pointer 0 :adjustable t)))
(format t "~C[18t" #\Esc)
(force-output)
;; Blocking read-char loop — the response arrives immediately
(loop with deadline = (+ (get-internal-real-time)
(* internal-time-units-per-second 0.5))
while (< (get-internal-real-time) deadline)
do (let ((ch (read-char saved nil nil)))
(when ch
(vector-push-extend ch response)
(when (char= ch #\t) (return)))))
(when (>= (length response) 8)
(handler-case
(sb-ext:with-timeout 0.3
(loop do (let ((ch (read-char saved nil nil)))
(when ch
(vector-push-extend ch response)
(when (char= ch #\t) (return))))))
(sb-ext:timeout ()))
(when (>= (length response) 5)
(let* ((str (subseq response 1))
(start (or (position #\[ str) 0))
(after (subseq str (1+ start)))