diff --git a/src/backend/modern.lisp b/src/backend/modern.lisp index 4362763..7f806b6 100644 --- a/src/backend/modern.lisp +++ b/src/backend/modern.lisp @@ -205,6 +205,16 @@ as a fallback when a keyword is not in *named-colors*.") (rows (sb-alien:deref winsize 0))) (values cols rows))))) (sb-unix:unix-close tty-fd))))) + ;; $COLUMNS/$LINES env vars — set by bash, may be available + ;; even when ioctl fails (SBCL strips them in some contexts + ;; but not all). + (ignore-errors + (let* ((cstr (sb-ext:posix-getenv "COLUMNS")) + (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 rows (> cols 0) (> rows 0)) + (values cols rows)))) (values 80 24))) (defmethod backend-write ((b modern-backend) string) diff --git a/src/backend/simple.lisp b/src/backend/simple.lisp index 2fbfdb3..47f103f 100644 --- a/src/backend/simple.lisp +++ b/src/backend/simple.lisp @@ -62,7 +62,15 @@ (values (sb-alien:deref winsize 1) (sb-alien:deref winsize 0)))) (sb-alien:free-alien winsize)) - (sb-unix:unix-close tty-fd))))) + (sb-unix:unix-close tty-fd))))) + ;; $COLUMNS/$LINES env vars + (ignore-errors + (let* ((cstr (sb-ext:posix-getenv "COLUMNS")) + (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 rows (> cols 0) (> rows 0)) + (values cols rows)))) (values 80 24))) (defmethod backend-write ((b simple-backend) string)