fix: add CSI positioning and ioctl sizing to simple-backend

- backend-size now uses TIOCGWINSZ ioctl (like modern-backend)
- draw-text adds \033[row;colH CSI cursor positioning
- draw-rect fills background with space characters at position
- draw-border uses CSI positioning instead of raw newlines+spaces
- Added cursor-hide/cursor-show, cursor-move, initialize/shutdown
- Detection: broader DA1 check (any ANSI response, not just kitty)
- Detection: added TERM-based fallback for modern terminal detection
This commit is contained in:
2026-05-14 08:55:56 -04:00
parent 1637c3352c
commit e8b37f6268
2 changed files with 66 additions and 28 deletions

View File

@@ -31,13 +31,26 @@ TIMEOUT seconds. Returns the response string, or nil if no response."
response)))
(defun detect-backend-by-da1 ()
"Send DA1 (ESC[c) query and check for kitty terminal response code.
Returns T if terminal reports kitty compatibility codes."
"Send DA1 (ESC[c) query and check for any terminal response.
Returns T if the terminal responds to DA1 (indicating an ANSI-compatible terminal)."
(let ((response (query-terminal (format nil "~C[c" (code-char 27)))))
(when response
;; DA1 response format: ESC [ ? digits ; digits c
;; Kitty reports code 62 in the response
(search "?62" response))))
;; Any DA1 response (ESC [ ? digits ... c) means the terminal
;; understands ANSI escape sequences — good enough for modern-backend
(> (length response) 0))))
(defun detect-backend-by-term ()
"Check TERM environment variable for modern terminal types.
Returns :modern if TERM contains xterm, tmux, screen, kitty,
alacritty, foot, wezterm, or ghostty."
(let ((term (sb-ext:posix-getenv "TERM")))
(when term
;; Known non-modern terms
(unless (or (string-equal term "dumb")
(string-equal term "dump")
(string-equal term "emacs")
(search "52" term)) ; VT52 — no ANSI
:modern))))
(defun detect-backend ()
"Auto-detect the appropriate backend for the current terminal.
@@ -47,6 +60,7 @@ Result is cached in *detected-backend* for subsequent calls."
(setf *detected-backend*
(if (and (detect-backend-by-tty)
(or (eql (detect-backend-by-env) :modern)
(detect-backend-by-da1)))
(detect-backend-by-da1)
(eql (detect-backend-by-term) :modern)))
(make-modern-backend)
(make-simple-backend)))))