Shell wrapper for terminal raw mode, demo no longer sets raw mode

Added ./demo shell script that sets raw mode via stty before running
the Lisp demo and restores it on exit (including SIGINT/SIGTERM).

demo.lisp no longer attempts to set raw mode from inside SBCL —
terminal raw mode is the shell's responsibility.  This avoids the
recurring problem of sb-ext:run-program + stty not being able to
access the controlling terminal from inside sbcl --script.
This commit is contained in:
Hermes
2026-05-12 01:43:52 +00:00
parent 613e4b6217
commit 2b2119a2f1
2 changed files with 68 additions and 53 deletions

20
demo Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/sh
# cl-tty demo launcher
# Sets raw terminal mode, runs the demo, restores terminal on exit.
# This is needed because SBCL's --script mode + run-program combo
# can't reliably set raw mode from inside the Lisp process.
SAVED=$(stty -g 2>/dev/null)
if [ -z "$SAVED" ]; then
echo "ERROR: Not running in a real terminal." >&2
echo " Try: sbcl --script demo.lisp" >&2
exit 1
fi
cleanup() {
stty "$SAVED" 2>/dev/null
}
trap cleanup EXIT INT TERM
stty raw -echo -isig -icanon min 1 time 0 2>/dev/null
sbcl --script "$(dirname "$0")/demo.lisp"

View File

@@ -124,17 +124,14 @@
t))) t)))
(defun run-demo () (defun run-demo ()
(let ((saved (ignore-errors (set-raw-mode)))) "Run the demo. Assumes raw terminal mode is already set by the
(unless saved shell wrapper (./demo) or by running:
(format *error-output* "~&ERROR: Cannot set terminal to raw mode.~%") stty raw -echo -isig -icanon min 1 time 0
(format *error-output* " Make sure you are in a real terminal (not a pipe/redirect).~%") sbcl --script demo.lisp"
(format *error-output* " Try: sbcl --script demo.lisp~%")
(return-from run-demo))
(unwind-protect
(progn
(init-app-state) (init-app-state)
(let* ((backend (detect-backend)) (let* ((backend (detect-backend))
(w 80) (h 24)) (w 80) (h 24))
(declare (ignore h))
(initialize-backend backend) (initialize-backend backend)
(unwind-protect (unwind-protect
(loop while (getf *app* :running) (loop while (getf *app* :running)
@@ -176,8 +173,6 @@
(when event (when event
(handle-event event)))) (handle-event event))))
(shutdown-backend backend)))) (shutdown-backend backend))))
(when saved
(restore-terminal-state saved)))))
(run-demo) (run-demo)
(uiop:quit 0) (uiop:quit 0)