0
0
mirror of https://github.com/vim/vim.git synced 2025-07-25 10:54:51 -04:00

patch 8.0.0787: cannot send CTRL-W command to terminal job

Problem:    Cannot send CTRL-W command to terminal job.
Solution:   Make CTRL-W . a prefex for sending a key to the job.
This commit is contained in:
Bram Moolenaar 2017-07-28 13:48:34 +02:00
parent 8bcc99b821
commit 1f28b4c6a3
4 changed files with 54 additions and 19 deletions

View File

@ -1,4 +1,4 @@
*terminal.txt* For Vim version 8.0. Last change: 2017 Jul 24 *terminal.txt* For Vim version 8.0. Last change: 2017 Jul 28
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@ -33,22 +33,27 @@ Or to run a debugger: >
The job runs asynchronously from Vim, the window will be updated to show The job runs asynchronously from Vim, the window will be updated to show
output from the job, also while editing in any other window. output from the job, also while editing in any other window.
Typing ~
When the keyboard focus is in the terminal window, typed keys will be send to When the keyboard focus is in the terminal window, typed keys will be send to
the job. This uses a pty when possible. the job. This uses a pty when possible. You can click outside of the
terminal window to move keyboard focus elsewhere.
Navigate between windows with CTRL-W commands (and mouse). Navigate between windows with CTRL-W commands. E.g. CTRL-W CTRL-W moves focus
E.g. CTRL-W CTRL-W moves focus to the next window. to the next window. Use "CTRL-W :" to edit an Ex command. Use "CTRL-W ." to
Use "CTRL-W :" to edit an Ex command. send a CTRL-W to the job in the terminal.
See option 'termkey' for specifying the key that precedes a Vim command. See option 'termkey' for specifying another key that precedes a Vim command.
Default is CTRL-W. Typing 'termkey' twice sends 'termkey' to the job.
Size ~
See option 'termsize' for controlling the size of the terminal window. See option 'termsize' for controlling the size of the terminal window.
(TODO: scrolling when the terminal is larger than the window) (TODO: scrolling when the terminal is larger than the window)
Syntax ~ Syntax ~
:ter[minal][!] [command] *:ter* *:terminal* :ter[minal] [command] *:ter* *:terminal*
Open a new terminal window. Open a new terminal window.
If [command] is provided run it as a job and connect If [command] is provided run it as a job and connect

View File

@ -2773,7 +2773,7 @@ static struct vimoption options[] =
{"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF, {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
#ifdef FEAT_TERMINAL #ifdef FEAT_TERMINAL
(char_u *)VAR_WIN, PV_TK, (char_u *)VAR_WIN, PV_TK,
{(char_u *)"\x17", (char_u *)NULL} {(char_u *)"", (char_u *)NULL}
#else #else
(char_u *)NULL, PV_NONE, (char_u *)NULL, PV_NONE,
{(char_u *)NULL, (char_u *)0L} {(char_u *)NULL, (char_u *)0L}

View File

@ -33,9 +33,9 @@
* while, if the terminal window is visible, the screen contents is drawn. * while, if the terminal window is visible, the screen contents is drawn.
* *
* TODO: * TODO:
* - To set BS correctly, check get_stty(); Pass the fd of the pty.
* - include functions from #1871 * - include functions from #1871
* - do not store terminal buffer in viminfo. Or prefix term:// ? * - do not store terminal buffer in viminfo. Or prefix term:// ?
* - Make CTRL-W . send CTRL-W to terminal?
* - Add a scrollback buffer (contains lines to scroll off the top). * - Add a scrollback buffer (contains lines to scroll off the top).
* Can use the buf_T lines, store attributes somewhere else? * Can use the buf_T lines, store attributes somewhere else?
* - When the job ends: * - When the job ends:
@ -50,7 +50,6 @@
* - when closing window and job has not ended, make terminal hidden? * - when closing window and job has not ended, make terminal hidden?
* - don't allow exiting Vim when a terminal is still running a job * - don't allow exiting Vim when a terminal is still running a job
* - use win_del_lines() to make scroll-up efficient. * - use win_del_lines() to make scroll-up efficient.
* - command line completion for :terminal
* - add test for giving error for invalid 'termsize' value. * - add test for giving error for invalid 'termsize' value.
* - support minimal size when 'termsize' is "rows*cols". * - support minimal size when 'termsize' is "rows*cols".
* - support minimal size when 'termsize' is empty? * - support minimal size when 'termsize' is empty?
@ -458,6 +457,24 @@ term_convert_key(int c, char *buf)
return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN); return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN);
} }
/*
* Get a key from the user without mapping.
* TODO: use terminal mode mappings.
*/
static int
term_vgetc()
{
int c;
++no_mapping;
++allow_keys;
got_int = FALSE;
c = vgetc();
--no_mapping;
--allow_keys;
return c;
}
/* /*
* Wait for input and send it to the job. * Wait for input and send it to the job.
* Return when the start of a CTRL-W command is typed or anything else that * Return when the start of a CTRL-W command is typed or anything else that
@ -481,17 +498,28 @@ terminal_loop(void)
/* TODO: skip screen update when handling a sequence of keys. */ /* TODO: skip screen update when handling a sequence of keys. */
update_screen(0); update_screen(0);
update_cursor(curbuf->b_term, FALSE); update_cursor(curbuf->b_term, FALSE);
++no_mapping; c = term_vgetc();
++allow_keys;
got_int = FALSE;
c = vgetc();
--no_mapping;
--allow_keys;
if (c == (termkey == 0 ? Ctrl_W : termkey)) if (c == (termkey == 0 ? Ctrl_W : termkey))
{ {
stuffcharReadbuff(Ctrl_W); #ifdef FEAT_CMDL_INFO
return; if (add_to_showcmd(c))
out_flush();
#endif
c = term_vgetc();
#ifdef FEAT_CMDL_INFO
clear_showcmd();
#endif
if (termkey == 0 && c == '.')
/* "CTRL-W .": send CTRL-W to the job */
c = Ctrl_W;
else if (termkey == 0 || c != termkey)
{
stuffcharReadbuff(Ctrl_W);
stuffcharReadbuff(c);
return;
}
} }
/* Catch keys that need to be handled as in Normal mode. */ /* Catch keys that need to be handled as in Normal mode. */

View File

@ -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 */
/**/
787,
/**/ /**/
786, 786,
/**/ /**/