From abe4edaffcbd42a63db16f2618d82a75eb9f4602 Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Thu, 14 May 2026 13:04:57 -0400 Subject: [PATCH] fix: fallback to stty size when LINES env var is missing Some environments (tmux) export COLUMNS but not LINES. Use 'stty size' as a fallback for the missing dimension. --- src/backend/modern.lisp | 9 +++++++++ src/backend/simple.lisp | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/backend/modern.lisp b/src/backend/modern.lisp index b9a8450..6cf453a 100644 --- a/src/backend/modern.lisp +++ b/src/backend/modern.lisp @@ -189,6 +189,15 @@ as a fallback when a keyword is not in *named-colors*.") (rstr (sb-ext:posix-getenv "LINES")) (cols (when cstr (parse-integer cstr :junk-allowed t))) (rows (when rstr (parse-integer rstr :junk-allowed t)))) + ;; Some environments set only COLUMNS or only LINES. + ;; If one is missing, try the other from stty. + (when (and cols (null rows)) + (let* ((out (uiop:run-program '("stty" "size") + :output :string + :ignore-error-status t)) + (parts (when out (uiop:split-string (string-trim '(#\newline #\space) out))))) + (setf rows (when (and parts (= (length parts) 2)) + (parse-integer (second parts) :junk-allowed t))))) (when (and cols rows (> cols 0) (> rows 0)) (values cols rows)))) (values w h))))) diff --git a/src/backend/simple.lisp b/src/backend/simple.lisp index e2704a4..dd0bcba 100644 --- a/src/backend/simple.lisp +++ b/src/backend/simple.lisp @@ -48,6 +48,13 @@ (rstr (sb-ext:posix-getenv "LINES")) (cols (when cstr (parse-integer cstr :junk-allowed t))) (rows (when rstr (parse-integer rstr :junk-allowed t)))) + (when (and cols (null rows)) + (let* ((out (uiop:run-program '("stty" "size") + :output :string + :ignore-error-status t)) + (parts (when out (uiop:split-string (string-trim '(#\newline #\space) out))))) + (setf rows (when (and parts (= (length parts) 2)) + (parse-integer (second parts) :junk-allowed t))))) (when (and cols rows (> cols 0) (> rows 0)) (values cols rows)))) (values w h)))))