v1.0.0: TUI support — resize events, with-terminal macro
- read-event now checks *terminal-resized-p* and returns :resize on SIGWINCH - Added with-terminal convenience macro (detect → init → body → shutdown) - Exported *terminal-resized-p* from cl-tty.input package - Exported with-terminal from cl-tty.backend package - Updated text-input.org with resize event integration and refactored tests - Tests: 461 checks, 100% pass (93 input suite, +2 new test cases)
This commit is contained in:
@@ -18,6 +18,37 @@ Called before SIGTSTP or similar suspension. Application should redraw after res
|
||||
Called after SIGCONT or similar resume. Re-enables raw mode and backend features.")
|
||||
(:method ((b backend)) (values)))
|
||||
|
||||
(defmacro with-terminal ((backend-var &optional (cols-var (gensym)) (rows-var (gensym)))
|
||||
&body body)
|
||||
"Execute BODY with a fully initialized terminal backend.
|
||||
|
||||
DETECT-BACKEND, INITIALIZE-BACKEND, and SHUTDOWN-BACKEND are called
|
||||
automatically. The backend instance is bound to BACKEND-VAR. If
|
||||
COLS-VAR and ROWS-VAR are provided, they are bound to the terminal
|
||||
dimensions at startup.
|
||||
|
||||
The caller should wrap this in SB-POSIX:WITH-RAW-TERMINAL (or
|
||||
equivalent) if raw-mode input handling is needed.
|
||||
|
||||
Example:
|
||||
(with-terminal (be cols rows)
|
||||
(loop for ev = (read-event be :timeout 0.1)
|
||||
while ev
|
||||
do (format t \"~A~%\" ev))))"
|
||||
(let ((be-sym (gensym "BE"))
|
||||
(c-sym (gensym "COLS"))
|
||||
(r-sym (gensym "ROWS")))
|
||||
`(let* ((,be-sym (detect-backend))
|
||||
(,c-sym (nth-value 0 (backend-size ,be-sym)))
|
||||
(,r-sym (nth-value 1 (backend-size ,be-sym))))
|
||||
(initialize-backend ,be-sym)
|
||||
(unwind-protect
|
||||
(let ((,backend-var ,be-sym)
|
||||
,@(when cols-var `((,cols-var ,c-sym)))
|
||||
,@(when rows-var `((,rows-var ,r-sym))))
|
||||
,@body)
|
||||
(shutdown-backend ,be-sym)))))
|
||||
|
||||
(defgeneric backend-size (backend)
|
||||
(:method ((b backend))
|
||||
(values 80 24)))
|
||||
|
||||
Reference in New Issue
Block a user