fix: add stty size subprocess fallback in both backends
stty size via uiop:run-program is the most reliable method — it works from the shell on every Unix system and bypasses alien/ioctl quirks. Placed between stdout ioctl and /dev/tty ioctl in the fallback chain.
This commit is contained in:
@@ -173,6 +173,19 @@ as a fallback when a keyword is not in *named-colors*.")
|
||||
(values (sb-alien:deref winsize 1) ;; cols
|
||||
(sb-alien:deref winsize 0))) ;; rows
|
||||
(sb-alien:free-alien winsize))))
|
||||
;; stty size via subprocess — reliable on every Unix, bypasses
|
||||
;; SBCL's alien/ioctl quirks. Returns "ROWS COLS".
|
||||
(ignore-errors
|
||||
(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 ((rows (parse-integer (first parts) :junk-allowed t))
|
||||
(cols (parse-integer (second parts) :junk-allowed t)))
|
||||
(when (and rows cols (> rows 0) (> cols 0))
|
||||
(values cols rows))))))
|
||||
;; Direct ioctl on /dev/tty — opens the real controlling terminal.
|
||||
(ignore-errors
|
||||
(let ((tty-fd (sb-unix:unix-open "/dev/tty" 0 0))) ; O_RDONLY
|
||||
|
||||
@@ -34,6 +34,18 @@
|
||||
(values (sb-alien:deref winsize 1)
|
||||
(sb-alien:deref winsize 0)))
|
||||
(sb-alien:free-alien winsize))))
|
||||
;; stty size via subprocess — reliable on every Unix.
|
||||
(ignore-errors
|
||||
(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 ((rows (parse-integer (first parts) :junk-allowed t))
|
||||
(cols (parse-integer (second parts) :junk-allowed t)))
|
||||
(when (and rows cols (> rows 0) (> cols 0))
|
||||
(values cols rows))))))
|
||||
(ignore-errors
|
||||
(let ((tty-fd (sb-unix:unix-open "/dev/tty" 0 0))) ; O_RDONLY
|
||||
(when (and tty-fd (numberp tty-fd) (> tty-fd 0))
|
||||
|
||||
Reference in New Issue
Block a user