From 5e9a974981aa741f96b55c6ae148be920cca9a35 Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Thu, 14 May 2026 13:14:22 -0400 Subject: [PATCH] fix: fill missing env dimension from stty size When only COLUMNS or only LINES is set, run 'stty size' to get the other dimension. This handles tmux/screen where only one env var is exported. --- src/backend/modern.lisp | 12 ++++++++++++ src/backend/simple.lisp | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/backend/modern.lisp b/src/backend/modern.lisp index 498b824..7882778 100644 --- a/src/backend/modern.lisp +++ b/src/backend/modern.lisp @@ -180,6 +180,18 @@ 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)))) + ;; If only one env var is set, get the other from stty + (unless (and cols rows) + (let* ((out (uiop:run-program '("stty" "size") + :output :string + :ignore-error-status t)) + (parts (and out (uiop:split-string + (string-trim '(#\newline #\space) out))))) + (when (and parts (= (length parts) 2)) + (let ((a (parse-integer (first parts) :junk-allowed t)) + (b (parse-integer (second parts) :junk-allowed t))) + (when (and a b (> a 0) (> b 0)) + (if cols (setf rows b) (setf cols a))))))) (when (and cols rows (> cols 0) (> rows 0)) (values cols rows)))) (values 80 24))) diff --git a/src/backend/simple.lisp b/src/backend/simple.lisp index 4a524e1..79bff82 100644 --- a/src/backend/simple.lisp +++ b/src/backend/simple.lisp @@ -39,6 +39,17 @@ (rstr (sb-ext:posix-getenv "LINES")) (cols (when cstr (parse-integer cstr :junk-allowed t))) (rows (when rstr (parse-integer rstr :junk-allowed t)))) + (unless (and cols rows) + (let* ((out (uiop:run-program '("stty" "size") + :output :string + :ignore-error-status t)) + (parts (and out (uiop:split-string + (string-trim '(#\newline #\space) out))))) + (when (and parts (= (length parts) 2)) + (let ((a (parse-integer (first parts) :junk-allowed t)) + (b (parse-integer (second parts) :junk-allowed t))) + (when (and a b (> a 0) (> b 0)) + (if cols (setf rows b) (setf cols a))))))) (when (and cols rows (> cols 0) (> rows 0)) (values cols rows)))) (values 80 24)))