Skip to content

Commit

Permalink
patch 8.0.0913: MS-Windows: CTRL-C kills shell in terminal window
Browse files Browse the repository at this point in the history
Problem:    MS-Windows: CTRL-C kills shell in terminal window instead of the
            command running in the shell.
Solution:   Make CTRL-C only send a CTRL_C_EVENT and have CTRL-BREAK kill the
            job. (partly by Yasuhiro Matsumoto, closes #1962)
  • Loading branch information
brammool committed Aug 12, 2017
1 parent 8cad930 commit 9698ad7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/globals.h
Expand Up @@ -1671,6 +1671,10 @@ EXTERN int did_echo_string_emsg INIT(= FALSE);
EXTERN int *eval_lavars_used INIT(= NULL); EXTERN int *eval_lavars_used INIT(= NULL);
#endif #endif


#ifdef WIN3264
EXTERN int ctrl_break_was_pressed = FALSE;
#endif

/* /*
* Optional Farsi support. Include it here, so EXTERN and INIT are defined. * Optional Farsi support. Include it here, so EXTERN and INIT are defined.
*/ */
Expand Down
1 change: 1 addition & 0 deletions src/gui_w32.c
Expand Up @@ -1840,6 +1840,7 @@ process_message(void)
{ {
trash_input_buf(); trash_input_buf();
got_int = TRUE; got_int = TRUE;
ctrl_break_was_pressed = TRUE;
string[0] = Ctrl_C; string[0] = Ctrl_C;
add_to_input_buf(string, 1); add_to_input_buf(string, 1);
} }
Expand Down
1 change: 1 addition & 0 deletions src/os_win32.c
Expand Up @@ -6296,6 +6296,7 @@ mch_breakcheck(int force)
#ifndef FEAT_GUI_W32 /* never used */ #ifndef FEAT_GUI_W32 /* never used */
if (g_fCtrlCPressed || g_fCBrkPressed) if (g_fCtrlCPressed || g_fCBrkPressed)
{ {
ctrl_break_was_pressed = g_fCBrkPressed;
g_fCtrlCPressed = g_fCBrkPressed = FALSE; g_fCtrlCPressed = g_fCBrkPressed = FALSE;
got_int = TRUE; got_int = TRUE;
} }
Expand Down
14 changes: 10 additions & 4 deletions src/terminal.c
Expand Up @@ -1016,6 +1016,9 @@ term_vgetc()
++no_mapping; ++no_mapping;
++allow_keys; ++allow_keys;
got_int = FALSE; got_int = FALSE;
#ifdef WIN3264
ctrl_break_was_pressed = FALSE;
#endif
c = vgetc(); c = vgetc();
got_int = FALSE; got_int = FALSE;
--no_mapping; --no_mapping;
Expand Down Expand Up @@ -1201,11 +1204,14 @@ terminal_loop(void)
may_send_sigint(c, curbuf->b_term->tl_job->jv_pid, 0); may_send_sigint(c, curbuf->b_term->tl_job->jv_pid, 0);
#endif #endif
#ifdef WIN3264 #ifdef WIN3264
/* On Windows we do not know whether the job can handle CTRL-C itself
* or not. Therefore CTRL-C only sends a CTRL_C_EVENT to avoid killing
* the shell instead of a command running in the shell.
* Use CTRL-BREAK to kill the job. */
if (c == Ctrl_C) if (c == Ctrl_C)
/* We don't know if the job can handle CTRL-C itself or not, this mch_signal_job(curbuf->b_term->tl_job, (char_u *)"int");
* may kill the shell instead of killing the command running in the if (ctrl_break_was_pressed)
* shell. */ mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill");
mch_signal_job(curbuf->b_term->tl_job, (char_u *)"quit");
#endif #endif


if (c == (termkey == 0 ? Ctrl_W : termkey) || c == Ctrl_BSL) if (c == (termkey == 0 ? Ctrl_W : termkey) || c == Ctrl_BSL)
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -769,6 +769,8 @@ static char *(features[]) =


static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
913,
/**/ /**/
912, 912,
/**/ /**/
Expand Down

0 comments on commit 9698ad7

Please sign in to comment.