diff --git a/src/backend/modern.lisp b/src/backend/modern.lisp index 8d34192..dc848ef 100644 --- a/src/backend/modern.lisp +++ b/src/backend/modern.lisp @@ -162,23 +162,17 @@ as a fallback when a keyword is not in *named-colors*.") (values)) (defmethod backend-size ((b modern-backend)) - (or ;; ioctl on fd 0 (stdin) — the parent's own terminal, which IS - ;; the real controlling terminal when running from a shell. - (multiple-value-bind (cols rows) - (ignore-errors - (let ((winsize (sb-alien:make-alien sb-alien:unsigned-short 4))) - (unwind-protect - (let ((ok (sb-unix:unix-ioctl 0 21523 - (sb-alien:alien-sap winsize)))) - (when ok - (let ((c (sb-alien:deref winsize 1)) - (r (sb-alien:deref winsize 0))) - (when (and c r (> c 0) (> r 0)) - (values c r))))) - (sb-alien:free-alien winsize)))) + ;; MY_TERM_COLS/MY_TERM_ROWS — set by the passepartout script + ;; before exec sbcl. Check FIRST with return-from so both + ;; values (cols and rows) are preserved (or discards secondaries). + (let ((cstr (sb-ext:posix-getenv "MY_TERM_COLS")) + (rstr (sb-ext:posix-getenv "MY_TERM_ROWS"))) + (when (and cstr rstr) + (let ((cols (parse-integer cstr :junk-allowed t)) + (rows (parse-integer rstr :junk-allowed t))) (when (and cols rows (> cols 0) (> rows 0)) - (values cols rows))) - ;; ioctl on stdout fd — fast, correct after SIGWINCH at runtime. + (return-from backend-size (values cols rows)))))) + (or (multiple-value-bind (cols rows) (ignore-errors (let* ((winsize (sb-alien:make-alien sb-alien:unsigned-short 4))) @@ -204,16 +198,7 @@ as a fallback when a keyword is not in *named-colors*.") (let ((cols (sb-alien:deref winsize 1)) (rows (sb-alien:deref winsize 0))) (values cols rows))))) - (sb-unix:unix-close tty-fd))))) - ;; MY_TERM_COLS/MY_TERM_LINES — set by the passepartout script - ;; before exec sbcl. SBCL strips COLUMNS/LINES but leaves these. - (ignore-errors - (let* ((cstr (sb-ext:posix-getenv "MY_TERM_COLS")) - (rstr (sb-ext:posix-getenv "MY_TERM_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)))) + (sb-unix:unix-close tty-fd))))) (values 80 24))) (defmethod backend-write ((b modern-backend) string) diff --git a/src/backend/simple.lisp b/src/backend/simple.lisp index d6df6d5..c21fc73 100644 --- a/src/backend/simple.lisp +++ b/src/backend/simple.lisp @@ -22,6 +22,15 @@ (values)) (defmethod backend-size ((b simple-backend)) + ;; MY_TERM_COLS/MY_TERM_ROWS — set by the passepartout script. + ;; Check with return-from to preserve both values. + (let ((cstr (sb-ext:posix-getenv "MY_TERM_COLS")) + (rstr (sb-ext:posix-getenv "MY_TERM_ROWS"))) + (when (and cstr rstr) + (let ((cols (parse-integer cstr :junk-allowed t)) + (rows (parse-integer rstr :junk-allowed t))) + (when (and cols rows (> cols 0) (> rows 0)) + (return-from backend-size (values cols rows)))))) (or ;; ioctl on fd 0 (stdin) — the parent's own terminal. (multiple-value-bind (cols rows) (ignore-errors @@ -62,15 +71,7 @@ (values (sb-alien:deref winsize 1) (sb-alien:deref winsize 0)))) (sb-alien:free-alien winsize)) - (sb-unix:unix-close tty-fd))))) - ;; MY_TERM_COLS/MY_TERM_LINES — set by the passepartout script. - (ignore-errors - (let* ((cstr (sb-ext:posix-getenv "MY_TERM_COLS")) - (rstr (sb-ext:posix-getenv "MY_TERM_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)))) + (sb-unix:unix-close tty-fd))))) (values 80 24))) (defmethod backend-write ((b simple-backend) string)