summaryrefslogtreecommitdiffstats
path: root/Modules/readline.c
diff options
context:
space:
mode:
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 4013003..82daa52 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,