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:
@@ -189,6 +189,15 @@ as a fallback when a keyword is not in *named-colors*.")
|
|||||||
(rstr (sb-ext:posix-getenv "LINES"))
|
(rstr (sb-ext:posix-getenv "LINES"))
|
||||||
(cols (when cstr (parse-integer cstr :junk-allowed t)))
|
(cols (when cstr (parse-integer cstr :junk-allowed t)))
|
||||||
(rows (when rstr (parse-integer rstr :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))
|
(when (and cols rows (> cols 0) (> rows 0))
|
||||||
(values cols rows))))
|
(values cols rows))))
|
||||||
(values w h)))))
|
(values w h)))))
|
||||||
|
|||||||
@@ -48,6 +48,13 @@
|
|||||||
(rstr (sb-ext:posix-getenv "LINES"))
|
(rstr (sb-ext:posix-getenv "LINES"))
|
||||||
(cols (when cstr (parse-integer cstr :junk-allowed t)))
|
(cols (when cstr (parse-integer cstr :junk-allowed t)))
|
||||||
(rows (when rstr (parse-integer rstr :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))
|
(when (and cols rows (> cols 0) (> rows 0))
|
||||||
(values cols rows))))
|
(values cols rows))))
|
||||||
(values w h)))))
|
(values w h)))))
|
||||||
|
|||||||
Reference in New Issue
Block a user