Commit8e72e5ddRecorded1 Mar 2026Repositorysigil-tui
Fix with-terminal to restore terminal state on exceptions
Message
The VM's exception propagation does not run dynamic-wind after-thunks, so an error inside with-terminal left the terminal in raw mode with alternate screen active. Add a guard inside the dynamic-wind thunk that manually restores the terminal before re-raising the exception.
Changed
src/sigil/tui/terminal.sgl | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)Diff
src/sigil/tui/terminal.sglmodified
@@ -79,7 +79,17 @@
79
(terminal-raw-mode! #t) 80
(alternate-screen-on) 81
(terminal-write-raw (string-append esc "[?25l"))) ;; hide cursor−82
thunk+82
(lambda ()+83
;; Guard catches exceptions and manually restores the terminal+84
;; before re-raising. This is needed because the VM's exception+85
;; propagation does not run dynamic-wind after-thunks.+86
(guard (exn (#t+87
(disable-mouse-tracking)+88
(terminal-write-raw (string-append esc "[?25h"))+89
(alternate-screen-off)+90
(terminal-raw-mode! #f)+91
(raise exn)))+92
(thunk))) 93
(lambda () 94
(disable-mouse-tracking) 95
(terminal-write-raw (string-append esc "[?25h")) ;; show cursor