From 1f8a3aee435288be8d39259077e1db7f66e7d02c Mon Sep 17 00:00:00 2001 From: aycabta Date: Tue, 21 Dec 2021 00:16:32 +0900 Subject: [PATCH] Finalize when exception occurred Co-authored-by: Alex Gittemeier --- lib/reline.rb | 7 ++++++- lib/reline/line_editor.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/reline.rb b/lib/reline.rb index 88f1df3995..a9fc49b416 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -290,7 +290,6 @@ def readline(prompt = '', add_hist = false) may_req_ambiguous_char_width line_editor.reset(prompt, encoding: Reline::IOGate.encoding) - line_editor.set_signal_handlers if multiline line_editor.multiline_on if block_given? @@ -320,6 +319,7 @@ def readline(prompt = '', add_hist = false) line_editor.rerender begin + line_editor.set_signal_handlers prev_pasting_state = false loop do prev_pasting_state = Reline::IOGate.in_pasting? @@ -348,6 +348,11 @@ def readline(prompt = '', add_hist = false) line_editor.finalize Reline::IOGate.deprep(otio) raise e + rescue Exception + # Including Interrupt + line_editor.finalize + Reline::IOGate.deprep(otio) + raise end line_editor.finalize diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 55717a0fe8..bcd7cae1d1 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -235,7 +235,7 @@ def set_signal_handlers when 'EXIT' exit else - @old_trap.call + @old_trap.call if @old_trap.respond_to?(:call) end } begin