summaryrefslogtreecommitdiff
path: root/Modules/readline.c
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-04-03 02:54:58 +0000
committerMartin Panter <vadmium+py@gmail.com>2016-04-03 02:54:58 +0000
commit5dbbf1abba89ef1766759fbc9d5a5af02db49505 (patch)
treecac2c9b19d50a3cd7593a9a28359b3a952bda79e /Modules/readline.c
parentacc03195b0609490a4e5f8b1d9eb504c22c6526e (diff)
downloadcpython-git-5dbbf1abba89ef1766759fbc9d5a5af02db49505.tar.gz
Issue #23735: Add SIGWINCH handler for Readline 6.3+ support, by Eric Price
Diffstat (limited to 'Modules/readline.c')
-rw-r--r--Modules/readline.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/Modules/readline.c b/Modules/readline.c
index 401300395d..82daa52b2d 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -928,6 +928,26 @@ on_completion_display_matches_hook(char **matches,
#endif
+#ifdef HAVE_RL_RESIZE_TERMINAL
+static volatile sig_atomic_t sigwinch_received;
+static sighandler_t sigwinch_ohandler;
+
+static void
+readline_sigwinch_handler(int signum)
+{
+ sigwinch_received = 1;
+ if (sigwinch_ohandler &&
+ sigwinch_ohandler != SIG_IGN && sigwinch_ohandler != SIG_DFL)
+ sigwinch_ohandler(signum);
+
+#ifndef HAVE_SIGACTION
+ /* If the handler was installed with signal() rather than sigaction(),
+ we need to reinstall it. */
+ PyOS_setsig(SIGWINCH, readline_sigwinch_handler);
+#endif
+}
+#endif
+
/* C function to call the Python completer. */
static char *
@@ -1033,6 +1053,10 @@ setup_readline(readlinestate *mod_state)
/* Bind both ESC-TAB and ESC-ESC to the completion function */
rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+#ifdef HAVE_RL_RESIZE_TERMINAL
+ /* Set up signal handler for window resize */
+ sigwinch_ohandler = PyOS_setsig(SIGWINCH, readline_sigwinch_handler);
+#endif
/* Set our hook functions */
rl_startup_hook = on_startup_hook;
#ifdef HAVE_RL_PRE_INPUT_HOOK
@@ -1118,6 +1142,13 @@ readline_until_enter_or_signal(const char *prompt, int *signal)
struct timeval *timeoutp = NULL;
if (PyOS_InputHook)
timeoutp = &timeout;
+#ifdef HAVE_RL_RESIZE_TERMINAL
+ /* Update readline's view of the window size after SIGWINCH */
+ if (sigwinch_received) {
+ sigwinch_received = 0;
+ rl_resize_terminal();
+ }
+#endif
FD_SET(fileno(rl_instream), &selectset);
/* select resets selectset if no input was available */
has_input = select(fileno(rl_instream) + 1, &selectset,