session: trap SIGINT in interactive sessions like shells do
The current SIGINT handler in interactive sessions simply ignores it. This is not the behavior of most shells, which respond to SIGINT by restarting the prompt. This patch changes the behavior of DTSh to match that of shells.
Note: I'm unsure what the issue that is mentioned in the code with the pager is: Ctrl+C is properly trapped/handled by less in my Linux setup, and it is never passed to Python. Even trying to signal the process directly with kill -INT $(pidof python3) does not work while the pager is active.
The call to self._vt.pager_exit() is thus just a precaution.
The current SIGINT handler in interactive sessions simply ignores it. This is not the behavior of most shells, which respond to SIGINT by restarting the prompt. This patch changes the behavior of DTSh to match that of shells.
Fair enough ;-)
Note: I'm unsure what the issue that is mentioned in the code with the pager is: Ctrl+C is properly trapped/handled by
lessin my Linux setup, and it is never passed to Python. Even trying to signal the process directly withkill -INT $(pidof python3)does not work while the pager is active. The call toself._vt.pager_exit()is thus just a precaution.
Definitely right: comments are erroneous and misleading, there is no issue with the pager (with less at least as you say), it's while reading keyboard inputs (the opposite of being in the pager, actually) that SIGINT causes issues (the KeyboardInterrupt).
Your patch still fixes that, without messing with signal handlers unnecessarily, it's a better approach, besides better matching the usual behavior of shells.
Before I merge this, would you mind to also fix my poor comments, something like:
except KeyboardInterrupt:
# If SIGINT is signaled (e.g. CTRL-C, kill -SIGINT)
# while reading keyboard inputs,
# Python will in turn raise KeyboardInterrupt.
#
# Most shell behaviors is to just echo "^C" to the TTY
# and start a new prompt.
#
# Pagers usually ingore SIGINT: the call to pager_exit()
# is just a precaution.
self._vt.pager_exit()
self._vt.write("^C")
continue
Thanks (again).
Apologies it took me so long to get to this. Rebased over current dtsh-next and changed the comment.
@dottspina friendly ping :slightly_smiling_face: