From 920545dafbadbc156e89292ad66a56ff5c8627ad Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Thu, 14 May 2026 10:17:59 -0400 Subject: [PATCH] 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. --- src/backend/classes.lisp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/backend/classes.lisp b/src/backend/classes.lisp index 1e4af64..cf21def 100644 --- a/src/backend/classes.lisp +++ b/src/backend/classes.lisp @@ -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)))