Skip to content

Commit 43a100e

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 7841db9 + c9456ce commit 43a100e

File tree

22 files changed

+1355
-352
lines changed

22 files changed

+1355
-352
lines changed

Filelist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ SRC_ALL = \
200200
src/libvterm/.gitignore \
201201
src/libvterm/LICENSE \
202202
src/libvterm/Makefile \
203-
src/libvterm/Makefile.msc \
204203
src/libvterm/README \
205204
src/libvterm/tbl2inc_c.pl \
206205
src/libvterm/vterm.pc.in \

runtime/doc/eval.txt

Lines changed: 108 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 8.0. Last change: 2017 Jul 28
1+
*eval.txt* For Vim version 8.0. Last change: 2017 Jul 30
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2369,12 +2369,18 @@ tagfiles() List tags files used
23692369
tan({expr}) Float tangent of {expr}
23702370
tanh({expr}) Float hyperbolic tangent of {expr}
23712371
tempname() String name for a temporary file
2372-
term_getsize() Dict get the size of a terminal
2373-
term_open() Job open a terminal window and run a job
2374-
term_scrape() List inspect terminal screen
2375-
term_sendkeys() Number send keystrokes to a terminal
2376-
term_setsize() Number set the size of a terminal
2377-
term_wait() Number wait for screen to be updated
2372+
term_getattr({attr}, {what} Number get the value of attribute {what}
2373+
term_getcursor({buf}) List get the cursor position of a terminal
2374+
term_getjob({buf}) Job get the job associated with a terminal
2375+
term_getline({buf}[, {row}]) String get a line of text from a terminal
2376+
term_getsize({buf}) List get the size of a terminal
2377+
term_getstatus({buf}) String get the status of a terminal
2378+
term_gettitle({buf}) String get the title of a terminal
2379+
term_list() List get the list of terminal buffers
2380+
term_scrape({buf}[, {row}]) List get row of a terminal screen
2381+
term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
2382+
term_start({cmd}, {options}) Job open a terminal window and run a job
2383+
term_wait({buf}) Number wait for screen to be updated
23782384
test_alloc_fail({id}, {countdown}, {repeat})
23792385
none make memory allocation fail
23802386
test_autochdir() none enable 'autochdir' during startup
@@ -7898,23 +7904,106 @@ tempname() *tempname()* *temp-file-name*
78987904
For MS-Windows forward slashes are used when the 'shellslash'
78997905
option is set or when 'shellcmdflag' starts with '-'.
79007906

7901-
term_getsize() *term_getsize()*
7902-
Get the size of a terminal. NOT IMPLEMENTED YET
7907+
term_getattr({attr}, {what}) *term_getattr()*
7908+
Given {attr}, a value returned by term_scrape() in the "attr"
7909+
item, return whether {what} is on. {what} can be one of:
7910+
bold
7911+
italic
7912+
underline
7913+
strike
7914+
reverse
7915+
7916+
term_getcursor({buf}) *term_getcursor()*
7917+
Get the cusor position of terminal {buf}. Returns a list with
7918+
three numbers: [rows, cols, visible]. "rows" and "cols" are
7919+
zero based. "visible" is one when the cursor is visible, zero
7920+
when it is hidden.
7921+
7922+
This is the cursor position of the terminal itself, not of the
7923+
Vim window.
7924+
7925+
{buf} must be the buffer number of a terminal window. If the
7926+
buffer does not exist or is not a terminal window, an empty
7927+
list is returned.
7928+
7929+
term_getjob({buf}) *term_getjob()*
7930+
Get the Job associated with terminal window {buf}.
7931+
{buf} is used as with |term_getsize()|.
7932+
7933+
term_getline({buf} [, {row}]) *term_getline()*
7934+
Get a line of text from the terminal window of {buf}.
7935+
{buf} is used as with |term_getsize()|.
7936+
7937+
The first line has {row} zero. When {row} is invalid an empty
7938+
string is returned. When {row} is omitted, the cursor line is
7939+
used.
7940+
7941+
term_getsize({buf}) *term_getsize()*
7942+
Get the size of terminal {buf}. Returns a list with two
7943+
numbers: [rows, cols]. This is the size of the terminal, not
7944+
the window containing the terminal.
7945+
7946+
{buf} must be the buffer number of a terminal window. If the
7947+
buffer does not exist or is not a terminal window, an empty
7948+
list is returned.
7949+
7950+
term_getstatus({buf}) *term_getstatus()*
7951+
Get the status of terminal {buf}. This returns a comma
7952+
separated list of these items:
7953+
running job is running
7954+
finished job has finished
7955+
terminal in Terminal-Normal mode
7956+
One of "running" or "finished" is always present.
7957+
7958+
{buf} must be the buffer number of a terminal window. If the
7959+
buffer does not exist or is not a terminal window, an empty
7960+
string is returned.
7961+
7962+
term_gettitle({buf}) *term_gettitle()*
7963+
Get the title of terminal {buf}. This is the title that the
7964+
job in the terminal has set.
7965+
7966+
{buf} must be the buffer number of a terminal window. If the
7967+
buffer does not exist or is not a terminal window, an empty
7968+
string is returned.
7969+
7970+
term_list() *term_list()*
7971+
Return a list with the buffer numbers of all buffers for
7972+
terminal windows.
7973+
7974+
term_scrape({buf} [, {row}]) *term_scrape()*
7975+
Get the contents of {row} of terminal screen of {buf}.
7976+
For {buf} see |term_getsize()|.
7977+
7978+
The first {row} is zero. When {row} is invalid an empty list
7979+
is returned. When {row} is omitted the cursor line is used.
7980+
7981+
Return a List containing a Dict for each screen cell:
7982+
"chars" character(s) at the cell
7983+
"fg" foreground color as #rrggbb
7984+
"bg" background color as #rrggbb
7985+
"attr" attributes of the cell, use term_getattr()
7986+
to get the individual flags
7987+
"width" cell width: 1 or 2
7988+
7989+
term_sendkeys({buf}, {keys}) *term_sendkeys()*
7990+
Send keystrokes {keys} to terminal {buf}.
7991+
{buf} is used as with |term_getsize()|.
79037992

7904-
term_open() *term_open()*
7905-
Open a terminal window and run a job. NOT IMPLEMENTED YET
7993+
{keys} are translated as key sequences. For example, "\<c-x>"
7994+
means the character CTRL-X.
79067995

7907-
term_scrape() *term_scrape()*
7908-
Inspect terminal screen. NOT IMPLEMENTED YET
7996+
term_start({cmd}, {options}) *term_start()*
7997+
Open a terminal window and run {cmd} in it.
79097998

7910-
term_sendkeys() *term_sendkeys()*
7911-
Send keystrokes to a terminal. NOT IMPLEMENTED YET
7999+
Returns the buffer number of the terminal window.
8000+
When opening the window fails zero is returned.
79128001

7913-
term_setsize() *term_setsize()*
7914-
Set the size of a terminal. NOT IMPLEMENTED YET
8002+
{options} are not implemented yet.
79158003

7916-
term_wait() *term_wait()*
7917-
Wait for screen to be updated. NOT IMPLEMENTED YET
8004+
term_wait({buf}) *term_wait()*
8005+
Wait for pending updates of {buf} to be handled.
8006+
{buf} is used as with |term_getsize()|.
79188007

79198008
test_alloc_fail({id}, {countdown}, {repeat}) *test_alloc_fail()*
79208009
This is for testing: If the memory allocation with {id} is

runtime/doc/terminal.txt

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*terminal.txt* For Vim version 8.0. Last change: 2017 Jul 28
1+
*terminal.txt* For Vim version 8.0. Last change: 2017 Jul 30
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -33,24 +33,39 @@ Or to run a debugger: >
3333
The job runs asynchronously from Vim, the window will be updated to show
3434
output from the job, also while editing in any other window.
3535

36+
3637
Typing ~
3738

3839
When the keyboard focus is in the terminal window, typed keys will be send to
3940
the job. This uses a pty when possible. You can click outside of the
4041
terminal window to move keyboard focus elsewhere.
4142

42-
Navigate between windows with CTRL-W commands. E.g. CTRL-W CTRL-W moves focus
43-
to the next window. Use "CTRL-W :" to edit an Ex command. Use "CTRL-W ." to
44-
send a CTRL-W to the job in the terminal.
43+
CTRL-W can be used to navigate between windows and other CTRL-W commands, e.g.:
44+
CTRL-W CTRL-W move focus to the next window
45+
CTRL-W : enter an Ex command
46+
See |CTRL-W| for more commands.
47+
48+
Special in the terminal window: *CTRL-W_.* *CTRL-W_N*
49+
CTRL-W . send a CTRL-W to the job in the terminal
50+
CTRL-W N go to Terminal Normal mode, see |Terminal-mode|
51+
52+
See option 'termkey' for specifying another key instead of CTRL-W that
53+
will work like CTRL-W. However, typing 'termkey' twice sends 'termkey' to
54+
the job. For example:
55+
'termkey' CTRL-W move focus to the next window
56+
'termkey' : enter an Ex command
57+
'termkey' 'termkey' send 'termkey' to the job in the terminal
58+
'termkey' . send a CTRL-W to the job in the terminal
59+
'termkey' N go to terminal Normal mode, see below
60+
'termkey' CTRL-N same as CTRL-W N
4561

46-
See option 'termkey' for specifying another key that precedes a Vim command.
47-
Typing 'termkey' twice sends 'termkey' to the job.
4862

4963
Size ~
5064

5165
See option 'termsize' for controlling the size of the terminal window.
5266
(TODO: scrolling when the terminal is larger than the window)
5367

68+
5469
Syntax ~
5570

5671
:ter[minal] [command] *:ter* *:terminal*
@@ -99,6 +114,25 @@ terminal. |term_setsize()| can be used only when in the first or second mode,
99114
not when 'termsize' is "rowsXcols".
100115

101116

117+
Terminal Normal mode ~
118+
*Terminal-mode*
119+
When the job is running the contents of the terminal is under control of the
120+
job. That includes the cursor position. The terminal contents can change at
121+
any time.
122+
123+
Use CTRL-W N (or 'termkey' N) to go to Terminal Normal mode. Now the contents
124+
of the terminal window is under control of Vim, the job output is suspended.
125+
*E946*
126+
In this mode you can move the cursor around with the usual Vim commands,
127+
Visually mark text, yank text, etc. But you cannot change the contents of the
128+
buffer. The commands that would start insert mode, such as 'i' and 'a',
129+
return control of the window to the job. Any pending output will now be
130+
displayed.
131+
132+
In Terminal mode the statusline and window title show "(Terminal)". If the
133+
job ends while in Terminal mode this changes to "(Terminal-finished)".
134+
135+
102136
Unix ~
103137

104138
On Unix a pty is used to make it possible to run all kinds of commands. You

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,7 @@ test_arglist \
22732273
test_tagjump \
22742274
test_taglist \
22752275
test_tcl \
2276+
test_terminal \
22762277
test_textobjects \
22772278
test_timers \
22782279
test_true_false \

src/eval.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8070,8 +8070,9 @@ get_user_input(
80708070
rettv->vval.v_string = NULL;
80718071

80728072
#ifdef NO_CONSOLE_INPUT
8073-
/* While starting up, there is no place to enter text. */
8074-
if (no_console_input())
8073+
/* While starting up, there is no place to enter text. When running tests
8074+
* with --not-a-term we assume feedkeys() will be used. */
8075+
if (no_console_input() && !is_not_a_term())
80758076
return;
80768077
#endif
80778078

src/evalfunc.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,20 @@ static struct fst
830830
{"tanh", 1, 1, f_tanh},
831831
#endif
832832
{"tempname", 0, 0, f_tempname},
833+
#ifdef FEAT_TERMINAL
834+
{"term_getattr", 2, 2, f_term_getattr},
835+
{"term_getcursor", 1, 1, f_term_getcursor},
836+
{"term_getjob", 1, 1, f_term_getjob},
837+
{"term_getline", 1, 2, f_term_getline},
838+
{"term_getsize", 1, 1, f_term_getsize},
839+
{"term_getstatus", 1, 1, f_term_getstatus},
840+
{"term_gettitle", 1, 1, f_term_gettitle},
841+
{"term_list", 0, 0, f_term_list},
842+
{"term_scrape", 1, 2, f_term_scrape},
843+
{"term_sendkeys", 2, 2, f_term_sendkeys},
844+
{"term_start", 1, 2, f_term_start},
845+
{"term_wait", 1, 1, f_term_wait},
846+
#endif
833847
{"test_alloc_fail", 3, 3, f_test_alloc_fail},
834848
{"test_autochdir", 0, 0, f_test_autochdir},
835849
{"test_garbagecollect_now", 0, 0, f_test_garbagecollect_now},
@@ -1540,7 +1554,7 @@ buflist_find_by_name(char_u *name, int curtab_only)
15401554
/*
15411555
* Get buffer by number or pattern.
15421556
*/
1543-
static buf_T *
1557+
buf_T *
15441558
get_buf_tv(typval_T *tv, int curtab_only)
15451559
{
15461560
char_u *name = tv->vval.v_string;
@@ -6490,8 +6504,9 @@ f_inputlist(typval_T *argvars, typval_T *rettv)
64906504
int mouse_used;
64916505

64926506
#ifdef NO_CONSOLE_INPUT
6493-
/* While starting up, there is no place to enter text. */
6494-
if (no_console_input())
6507+
/* While starting up, there is no place to enter text. When running tests
6508+
* with --not-a-term we assume feedkeys() will be used. */
6509+
if (no_console_input() && !is_not_a_term())
64956510
return;
64966511
#endif
64976512
if (argvars[0].v_type != VAR_LIST || argvars[0].vval.v_list == NULL)

src/libvterm/src/pen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static void setpenattr(VTermState *state, VTermAttr attr, VTermValueType type UN
106106
{
107107
#ifdef DEBUG
108108
if(type != vterm_get_attr_type(attr)) {
109-
DEBUG_LOG("Cannot set attr %d as it has type %d, not type %d\n",
109+
DEBUG_LOG3("Cannot set attr %d as it has type %d, not type %d\n",
110110
attr, vterm_get_attr_type(attr), type);
111111
return;
112112
}

src/main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,11 +1425,17 @@ main_loop(
14251425
else
14261426
{
14271427
#ifdef FEAT_TERMINAL
1428-
if (curbuf->b_term != NULL && oa.op_type == OP_NOP
1429-
&& oa.regname == NUL)
1430-
terminal_loop();
1428+
if (term_use_loop() && oa.op_type == OP_NOP && oa.regname == NUL)
1429+
{
1430+
/* If terminal_loop() returns OK we got a key that is handled
1431+
* in Normal model. With FAIL the terminal was closed and the
1432+
* screen needs to be redrawn. */
1433+
if (terminal_loop() == OK)
1434+
normal_cmd(&oa, TRUE);
1435+
}
1436+
else
14311437
#endif
1432-
normal_cmd(&oa, TRUE);
1438+
normal_cmd(&oa, TRUE);
14331439
}
14341440

14351441
#ifdef FEAT_GUI_MACVIM

src/normal.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9071,6 +9071,14 @@ nv_esc(cmdarg_T *cap)
90719071
static void
90729072
nv_edit(cmdarg_T *cap)
90739073
{
9074+
#ifdef FEAT_TERMINAL
9075+
if (term_in_terminal_mode())
9076+
{
9077+
term_leave_terminal_mode();
9078+
return;
9079+
}
9080+
#endif
9081+
90749082
/* <Insert> is equal to "i" */
90759083
if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS)
90769084
cap->cmdchar = 'i';

src/option.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8359,12 +8359,22 @@ set_bool_option(
83598359
}
83608360
#endif
83618361

8362-
#ifdef FEAT_TITLE
83638362
/* when 'modifiable' is changed, redraw the window title */
83648363
else if ((int *)varp == &curbuf->b_p_ma)
83658364
{
8365+
# ifdef FEAT_TERMINAL
8366+
/* Cannot set 'modifiable' when in Terminal mode. */
8367+
if (term_in_terminal_mode())
8368+
{
8369+
curbuf->b_p_ma = FALSE;
8370+
return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8371+
}
8372+
# endif
8373+
# ifdef FEAT_TITLE
83668374
redraw_titles();
8375+
# endif
83678376
}
8377+
#ifdef FEAT_TITLE
83688378
/* when 'endofline' is changed, redraw the window title */
83698379
else if ((int *)varp == &curbuf->b_p_eol)
83708380
{

0 commit comments

Comments
 (0)