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:
@@ -180,6 +180,18 @@ 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))))
|
||||||
|
;; 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))
|
(when (and cols rows (> cols 0) (> rows 0))
|
||||||
(values cols rows))))
|
(values cols rows))))
|
||||||
(values 80 24)))
|
(values 80 24)))
|
||||||
|
|||||||
@@ -39,6 +39,17 @@
|
|||||||
(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))))
|
||||||
|
(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))
|
(when (and cols rows (> cols 0) (> rows 0))
|
||||||
(values cols rows))))
|
(values cols rows))))
|
||||||
(values 80 24)))
|
(values 80 24)))
|
||||||
|
|||||||
Reference in New Issue
Block a user