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