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:
@@ -196,6 +196,7 @@ via ~sb-posix~ directly.
|
||||
#:with-raw-terminal
|
||||
;; Event reading
|
||||
#:read-event
|
||||
#:*terminal-resized-p*
|
||||
;; UTF-8 input support
|
||||
#:utf8-decode
|
||||
;; TextInput
|
||||
@@ -704,6 +705,12 @@ All the complexity lives in ~%read-event~ and its callees.
|
||||
#+BEGIN_SRC lisp :tangle ../src/components/input.lisp
|
||||
(defmethod read-event ((b cl-tty.backend:backend) &key timeout)
|
||||
(declare (ignore b))
|
||||
;; Check for pending terminal resize before reading input.
|
||||
;; The SIGWINCH handler sets *terminal-resized-p* asynchronously.
|
||||
(when *terminal-resized-p*
|
||||
(setf *terminal-resized-p* nil)
|
||||
(multiple-value-bind (w h) (backend-size b)
|
||||
(return-from read-event (values :resize (cons w h)))))
|
||||
(when (probe-file "/dev/stdin")
|
||||
(%read-event :timeout timeout)))
|
||||
#+END_SRC
|
||||
@@ -2062,4 +2069,22 @@ The test suite is tangled to ~../tests/input-tests.lisp~ and covers:
|
||||
(remhash :local *keymaps*)
|
||||
(is-false (gethash :global *keymaps*))
|
||||
(is-false (gethash :local *keymaps*)))
|
||||
|
||||
(test resize-event-check
|
||||
"read-event returns :resize when *terminal-resized-p* is set"
|
||||
(let ((b (make-instance 'cl-tty.backend:backend)))
|
||||
(setf cl-tty.input:*terminal-resized-p* t)
|
||||
(multiple-value-bind (type data) (cl-tty.input:read-event b :timeout 0)
|
||||
(is (eq :resize type))
|
||||
(is (consp data))
|
||||
(is (integerp (car data)))
|
||||
(is (integerp (cdr data))))
|
||||
(is-false cl-tty.input:*terminal-resized-p*)))
|
||||
|
||||
(test with-terminal-macro-expands
|
||||
"with-terminal macro expands and compiles"
|
||||
(is (macro-function 'cl-tty.backend:with-terminal))
|
||||
(let ((expanded (macroexpand-1 '(cl-tty.backend:with-terminal (be)
|
||||
(print be)))))
|
||||
(is (listp expanded))))
|
||||
#+END_SRC
|
||||
|
||||
Reference in New Issue
Block a user