From bd1e8a92be20d2ba0a26bee1a8a0db87f2ea2657 Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Fri, 15 May 2026 11:43:29 -0400 Subject: [PATCH] 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. --- passepartout | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/passepartout b/passepartout index 17b02ba..3d9de1e 100755 --- a/passepartout +++ b/passepartout @@ -409,6 +409,10 @@ case "$COMMAND" in (sleep 3) (finish-output))) (uiop:quit 0) 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 # (SBCL strips COLUMNS/LINES but leaves MY_* alone). ts=$(stty size 2>/dev/null) @@ -420,9 +424,8 @@ LISPEOF find ~/.cache/common-lisp -name "*.fasl" -path "*cl-tty*" -delete 2>/dev/null sbcl --noinform --load /tmp/tui-load.lisp rc=$? - # Restore terminal cooked mode — stty was set to -icanon -echo -ixon - # before exec (or sbcl subprocess) to get character-at-a-time input. - # Without this restore the terminal stays raw after exit. + # Restore terminal cooked mode (also handled by trap cleanup above, + # but do it explicitly here for clarity). stty icanon echo ixon 2>/dev/null exit $rc ;;