Skip to content

Commit 22aad2f

Browse files
committed
patch 8.0.0817: cannot get the terminal line at the cursor
Problem: Cannot get the line of a terminal window at the cursor. Solution: Make the row argunt optionsl. (Yasuhiro Matsumoto, closes #1898)
1 parent f144a3f commit 22aad2f

4 files changed

Lines changed: 28 additions & 22 deletions

File tree

runtime/doc/eval.txt

Lines changed: 10 additions & 9 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 29
1+
*eval.txt* For Vim version 8.0. Last change: 2017 Jul 30
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2371,10 +2371,10 @@ tanh({expr}) Float hyperbolic tangent of {expr}
23712371
tempname() String name for a temporary file
23722372
term_getattr({attr}, {what} Number get the value of attribute {what}
23732373
term_getjob({buf}) Job get the job associated with a terminal
2374-
term_getline({buf}, {row}) String get a line of text from a terminal
2374+
term_getline({buf}[, {row}]) String get a line of text from a terminal
23752375
term_getsize({buf}) List get the size of a terminal
23762376
term_list() List get the list of terminal buffers
2377-
term_scrape({buf}, {row}) List get row of a terminal screen
2377+
term_scrape({buf}[, {row}]) List get row of a terminal screen
23782378
term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
23792379
term_start({cmd}, {options}) Job open a terminal window and run a job
23802380
term_wait({buf}) Number wait for screen to be updated
@@ -7914,12 +7914,13 @@ term_getjob({buf}) *term_getjob()*
79147914
Get the Job associated with terminal window {buf}.
79157915
{buf} is used as with |term_getsize()|.
79167916

7917-
term_getline({buf}, {row}) *term_getline()*
7917+
term_getline({buf} [, {row}]) *term_getline()*
79187918
Get a line of text from the terminal window of {buf}.
79197919
{buf} is used as with |term_getsize()|.
79207920

79217921
The first line has {row} zero. When {row} is invalid an empty
7922-
string is returned.
7922+
string is returned. When {row} is omitted, the cursor line is
7923+
used.
79237924

79247925
term_getsize({buf}) *term_getsize()*
79257926
Get the size of terminal {buf}. Returns a list with two
@@ -7930,17 +7931,17 @@ term_getsize({buf}) *term_getsize()*
79307931
buffer does not exist or is not a terminal window, an empty
79317932
list is returned.
79327933

7933-
term_list(}) *term_list()*
7934+
term_list() *term_list()*
79347935
Return a list with the buffer numbers of all buffers for
79357936
terminal windows.
79367937

7937-
term_scrape({buf}, {row}) *term_scrape()*
7938+
term_scrape({buf} [, {row}]) *term_scrape()*
79387939
Get the contents of {row} of terminal screen of {buf}.
79397940
For {buf} see |term_getsize()|.
79407941

79417942
The first {row} is zero. When {row} is invalid an empty list
7942-
is returned.
7943-
7943+
is returned. When {row} is omitted the cursor line is used.
7944+
79447945
Return a List containing a Dict for each screen cell:
79457946
"chars" character(s) at the cell
79467947
"fg" foreground color as #rrggbb

src/evalfunc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,10 @@ static struct fst
833833
#ifdef FEAT_TERMINAL
834834
{"term_getattr", 2, 2, f_term_getattr},
835835
{"term_getjob", 1, 1, f_term_getjob},
836-
{"term_getline", 2, 2, f_term_getline},
836+
{"term_getline", 1, 2, f_term_getline},
837837
{"term_getsize", 1, 1, f_term_getsize},
838838
{"term_list", 0, 0, f_term_list},
839-
{"term_scrape", 2, 2, f_term_scrape},
839+
{"term_scrape", 1, 2, f_term_scrape},
840840
{"term_sendkeys", 2, 2, f_term_sendkeys},
841841
{"term_start", 1, 2, f_term_start},
842842
{"term_wait", 1, 1, f_term_wait},

src/terminal.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
* :term <24x80> <close> vim notes.txt
5454
* - To set BS correctly, check get_stty(); Pass the fd of the pty.
5555
* - do not store terminal window in viminfo. Or prefix term:// ?
56+
* - add term_getcursor() - return cursor position: [row, col, visible]
5657
* - add a character in :ls output
5758
* - add 't' to mode()
5859
* - when closing window and job has not ended, make terminal hidden?
@@ -120,7 +121,7 @@ struct terminal_S {
120121
garray_T tl_scrollback;
121122
int tl_scrollback_scrolled;
122123

123-
pos_T tl_cursor;
124+
VTermPos tl_cursor_pos;
124125
int tl_cursor_visible;
125126
};
126127

@@ -1020,20 +1021,16 @@ handle_movecursor(
10201021
{
10211022
term_T *term = (term_T *)user;
10221023
win_T *wp;
1023-
int is_current = FALSE;
1024+
1025+
term->tl_cursor_pos = pos;
1026+
term->tl_cursor_visible = visible;
10241027

10251028
FOR_ALL_WINDOWS(wp)
10261029
{
10271030
if (wp->w_buffer == term->tl_buffer)
1028-
{
10291031
position_cursor(wp, &pos);
1030-
if (wp == curwin)
1031-
is_current = TRUE;
1032-
}
10331032
}
1034-
1035-
term->tl_cursor_visible = visible;
1036-
if (is_current)
1033+
if (term->tl_buffer == curbuf)
10371034
{
10381035
may_toggle_cursor(term);
10391036
update_cursor(term, TRUE);
@@ -1723,7 +1720,10 @@ f_term_getline(typval_T *argvars, typval_T *rettv)
17231720
if (buf == NULL)
17241721
return;
17251722
term = buf->b_term;
1726-
row = (int)get_tv_number(&argvars[1]);
1723+
if (argvars[1].v_type == VAR_UNKNOWN)
1724+
row = term->tl_cursor_pos.row;
1725+
else
1726+
row = (int)get_tv_number(&argvars[1]);
17271727

17281728
if (term->tl_vterm == NULL)
17291729
{
@@ -1814,7 +1814,10 @@ f_term_scrape(typval_T *argvars, typval_T *rettv)
18141814
screen = vterm_obtain_screen(term->tl_vterm);
18151815

18161816
l = rettv->vval.v_list;
1817-
pos.row = (int)get_tv_number(&argvars[1]);
1817+
if (argvars[1].v_type == VAR_UNKNOWN)
1818+
pos.row = term->tl_cursor_pos.row;
1819+
else
1820+
pos.row = (int)get_tv_number(&argvars[1]);
18181821
for (pos.col = 0; pos.col < term->tl_cols; )
18191822
{
18201823
dict_T *dcell;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
817,
772774
/**/
773775
816,
774776
/**/

0 commit comments

Comments
 (0)