fix: terminal stty restore with trap (set -e kills script before restore)
set -e on line 2 causes the bash script to exit immediately when sbcl returns non-zero, before the stty icanon echo ixon restore runs. Add trap cleanup EXIT to guarantee terminal restore on any exit path.
This commit is contained in:
@@ -409,6 +409,10 @@ case "$COMMAND" in
|
|||||||
(sleep 3) (finish-output)))
|
(sleep 3) (finish-output)))
|
||||||
(uiop:quit 0)
|
(uiop:quit 0)
|
||||||
LISPEOF
|
LISPEOF
|
||||||
|
# Restore terminal on any exit (set -e can kill the script before the
|
||||||
|
# explicit stty restore below if sbcl exits non-zero).
|
||||||
|
cleanup() { stty icanon echo ixon 2>/dev/null; }
|
||||||
|
trap cleanup EXIT
|
||||||
# Capture terminal dimensions in non-standard env vars
|
# Capture terminal dimensions in non-standard env vars
|
||||||
# (SBCL strips COLUMNS/LINES but leaves MY_* alone).
|
# (SBCL strips COLUMNS/LINES but leaves MY_* alone).
|
||||||
ts=$(stty size 2>/dev/null)
|
ts=$(stty size 2>/dev/null)
|
||||||
@@ -420,9 +424,8 @@ LISPEOF
|
|||||||
find ~/.cache/common-lisp -name "*.fasl" -path "*cl-tty*" -delete 2>/dev/null
|
find ~/.cache/common-lisp -name "*.fasl" -path "*cl-tty*" -delete 2>/dev/null
|
||||||
sbcl --noinform --load /tmp/tui-load.lisp
|
sbcl --noinform --load /tmp/tui-load.lisp
|
||||||
rc=$?
|
rc=$?
|
||||||
# Restore terminal cooked mode — stty was set to -icanon -echo -ixon
|
# Restore terminal cooked mode (also handled by trap cleanup above,
|
||||||
# before exec (or sbcl subprocess) to get character-at-a-time input.
|
# but do it explicitly here for clarity).
|
||||||
# Without this restore the terminal stays raw after exit.
|
|
||||||
stty icanon echo ixon 2>/dev/null
|
stty icanon echo ixon 2>/dev/null
|
||||||
exit $rc
|
exit $rc
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in New Issue
Block a user