fix: add COLUMNS/LINES env var fallback in backend-size

When all ioctl methods return rows=0 (SBCL process context), try
/ from the shell environment. These are set by bash
and may survive SBCL's env filtering in some configurations.
This commit is contained in:
2026-05-14 14:53:02 -04:00
parent 11a70956a0
commit 8cb269dfee
2 changed files with 19 additions and 1 deletions

View File

@@ -205,6 +205,16 @@ as a fallback when a keyword is not in *named-colors*.")
(rows (sb-alien:deref winsize 0))) (rows (sb-alien:deref winsize 0)))
(values cols rows))))) (values cols rows)))))
(sb-unix:unix-close tty-fd))))) (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))) (values 80 24)))
(defmethod backend-write ((b modern-backend) string) (defmethod backend-write ((b modern-backend) string)

View File

@@ -62,7 +62,15 @@
(values (sb-alien:deref winsize 1) (values (sb-alien:deref winsize 1)
(sb-alien:deref winsize 0)))) (sb-alien:deref winsize 0))))
(sb-alien:free-alien winsize)) (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))) (values 80 24)))
(defmethod backend-write ((b simple-backend) string) (defmethod backend-write ((b simple-backend) string)