@@ -928,6 +928,26 @@ on_completion_display_matches_hook(char **matches,
928928
929929#endif
930930
931+ #ifdef HAVE_RL_RESIZE_TERMINAL
932+ static volatile sig_atomic_t sigwinch_received ;
933+ static sighandler_t sigwinch_ohandler ;
934+
935+ static void
936+ readline_sigwinch_handler (int signum )
937+ {
938+ sigwinch_received = 1 ;
939+ if (sigwinch_ohandler &&
940+ sigwinch_ohandler != SIG_IGN && sigwinch_ohandler != SIG_DFL )
941+ sigwinch_ohandler (signum );
942+
943+ #ifndef HAVE_SIGACTION
944+ /* If the handler was installed with signal() rather than sigaction(),
945+ we need to reinstall it. */
946+ PyOS_setsig (SIGWINCH , readline_sigwinch_handler );
947+ #endif
948+ }
949+ #endif
950+
931951/* C function to call the Python completer. */
932952
933953static char *
@@ -1033,6 +1053,10 @@ setup_readline(readlinestate *mod_state)
10331053 /* Bind both ESC-TAB and ESC-ESC to the completion function */
10341054 rl_bind_key_in_map ('\t' , rl_complete , emacs_meta_keymap );
10351055 rl_bind_key_in_map ('\033' , rl_complete , emacs_meta_keymap );
1056+ #ifdef HAVE_RL_RESIZE_TERMINAL
1057+ /* Set up signal handler for window resize */
1058+ sigwinch_ohandler = PyOS_setsig (SIGWINCH , readline_sigwinch_handler );
1059+ #endif
10361060 /* Set our hook functions */
10371061 rl_startup_hook = on_startup_hook ;
10381062#ifdef HAVE_RL_PRE_INPUT_HOOK
@@ -1118,6 +1142,13 @@ readline_until_enter_or_signal(const char *prompt, int *signal)
11181142 struct timeval * timeoutp = NULL ;
11191143 if (PyOS_InputHook )
11201144 timeoutp = & timeout ;
1145+ #ifdef HAVE_RL_RESIZE_TERMINAL
1146+ /* Update readline's view of the window size after SIGWINCH */
1147+ if (sigwinch_received ) {
1148+ sigwinch_received = 0 ;
1149+ rl_resize_terminal ();
1150+ }
1151+ #endif
11211152 FD_SET (fileno (rl_instream ), & selectset );
11221153 /* select resets selectset if no input was available */
11231154 has_input = select (fileno (rl_instream ) + 1 , & selectset ,
0 commit comments