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.
This commit is contained in:
2026-05-14 13:04:57 -04:00
parent 1ac6ca02ee
commit abe4edaffc
2 changed files with 16 additions and 0 deletions

View File

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

View File

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