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.
This commit is contained in:
2026-05-14 13:14:22 -04:00
parent 4b9482c09a
commit 5e9a974981
2 changed files with 23 additions and 0 deletions

View File

@@ -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)))

View File

@@ -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)))