0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

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)
This commit is contained in:
Bram Moolenaar 2017-07-30 18:19:46 +02:00
parent f144a3fb73
commit 22aad2f880
4 changed files with 28 additions and 22 deletions

View File

@ -1,4 +1,4 @@
*eval.txt* For Vim version 8.0. Last change: 2017 Jul 29 *eval.txt* For Vim version 8.0. Last change: 2017 Jul 30
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@ -2371,10 +2371,10 @@ tanh({expr}) Float hyperbolic tangent of {expr}
tempname() String name for a temporary file tempname() String name for a temporary file
term_getattr({attr}, {what} Number get the value of attribute {what} term_getattr({attr}, {what} Number get the value of attribute {what}
term_getjob({buf}) Job get the job associated with a terminal term_getjob({buf}) Job get the job associated with a terminal
term_getline({buf}, {row}) String get a line of text from a terminal term_getline({buf}[, {row}]) String get a line of text from a terminal
term_getsize({buf}) List get the size of a terminal term_getsize({buf}) List get the size of a terminal
term_list() List get the list of terminal buffers term_list() List get the list of terminal buffers
term_scrape({buf}, {row}) List get row of a terminal screen term_scrape({buf}[, {row}]) List get row of a terminal screen
term_sendkeys({buf}, {keys}) none send keystrokes to a terminal term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
term_start({cmd}, {options}) Job open a terminal window and run a job term_start({cmd}, {options}) Job open a terminal window and run a job
term_wait({buf}) Number wait for screen to be updated term_wait({buf}) Number wait for screen to be updated
@ -7914,12 +7914,13 @@ term_getjob({buf}) *term_getjob()*
Get the Job associated with terminal window {buf}. Get the Job associated with terminal window {buf}.
{buf} is used as with |term_getsize()|. {buf} is used as with |term_getsize()|.
term_getline({buf}, {row}) *term_getline()* term_getline({buf} [, {row}]) *term_getline()*
Get a line of text from the terminal window of {buf}. Get a line of text from the terminal window of {buf}.
{buf} is used as with |term_getsize()|. {buf} is used as with |term_getsize()|.
The first line has {row} zero. When {row} is invalid an empty The first line has {row} zero. When {row} is invalid an empty
string is returned. string is returned. When {row} is omitted, the cursor line is
used.
term_getsize({buf}) *term_getsize()* term_getsize({buf}) *term_getsize()*
Get the size of terminal {buf}. Returns a list with two Get the size of terminal {buf}. Returns a list with two
@ -7930,17 +7931,17 @@ term_getsize({buf}) *term_getsize()*
buffer does not exist or is not a terminal window, an empty buffer does not exist or is not a terminal window, an empty
list is returned. list is returned.
term_list(}) *term_list()* term_list() *term_list()*
Return a list with the buffer numbers of all buffers for Return a list with the buffer numbers of all buffers for
terminal windows. terminal windows.
term_scrape({buf}, {row}) *term_scrape()* term_scrape({buf} [, {row}]) *term_scrape()*
Get the contents of {row} of terminal screen of {buf}. Get the contents of {row} of terminal screen of {buf}.
For {buf} see |term_getsize()|. For {buf} see |term_getsize()|.
The first {row} is zero. When {row} is invalid an empty list The first {row} is zero. When {row} is invalid an empty list
is returned. is returned. When {row} is omitted the cursor line is used.
Return a List containing a Dict for each screen cell: Return a List containing a Dict for each screen cell:
"chars" character(s) at the cell "chars" character(s) at the cell
"fg" foreground color as #rrggbb "fg" foreground color as #rrggbb

View File

@ -833,10 +833,10 @@ static struct fst
#ifdef FEAT_TERMINAL #ifdef FEAT_TERMINAL
{"term_getattr", 2, 2, f_term_getattr}, {"term_getattr", 2, 2, f_term_getattr},
{"term_getjob", 1, 1, f_term_getjob}, {"term_getjob", 1, 1, f_term_getjob},
{"term_getline", 2, 2, f_term_getline}, {"term_getline", 1, 2, f_term_getline},
{"term_getsize", 1, 1, f_term_getsize}, {"term_getsize", 1, 1, f_term_getsize},
{"term_list", 0, 0, f_term_list}, {"term_list", 0, 0, f_term_list},
{"term_scrape", 2, 2, f_term_scrape}, {"term_scrape", 1, 2, f_term_scrape},
{"term_sendkeys", 2, 2, f_term_sendkeys}, {"term_sendkeys", 2, 2, f_term_sendkeys},
{"term_start", 1, 2, f_term_start}, {"term_start", 1, 2, f_term_start},
{"term_wait", 1, 1, f_term_wait}, {"term_wait", 1, 1, f_term_wait},

View File

@ -53,6 +53,7 @@
* :term <24x80> <close> vim notes.txt * :term <24x80> <close> vim notes.txt
* - To set BS correctly, check get_stty(); Pass the fd of the pty. * - To set BS correctly, check get_stty(); Pass the fd of the pty.
* - do not store terminal window in viminfo. Or prefix term:// ? * - do not store terminal window in viminfo. Or prefix term:// ?
* - add term_getcursor() - return cursor position: [row, col, visible]
* - add a character in :ls output * - add a character in :ls output
* - add 't' to mode() * - add 't' to mode()
* - when closing window and job has not ended, make terminal hidden? * - when closing window and job has not ended, make terminal hidden?
@ -120,7 +121,7 @@ struct terminal_S {
garray_T tl_scrollback; garray_T tl_scrollback;
int tl_scrollback_scrolled; int tl_scrollback_scrolled;
pos_T tl_cursor; VTermPos tl_cursor_pos;
int tl_cursor_visible; int tl_cursor_visible;
}; };
@ -1020,20 +1021,16 @@ handle_movecursor(
{ {
term_T *term = (term_T *)user; term_T *term = (term_T *)user;
win_T *wp; win_T *wp;
int is_current = FALSE;
term->tl_cursor_pos = pos;
term->tl_cursor_visible = visible;
FOR_ALL_WINDOWS(wp) FOR_ALL_WINDOWS(wp)
{ {
if (wp->w_buffer == term->tl_buffer) if (wp->w_buffer == term->tl_buffer)
{
position_cursor(wp, &pos); position_cursor(wp, &pos);
if (wp == curwin)
is_current = TRUE;
}
} }
if (term->tl_buffer == curbuf)
term->tl_cursor_visible = visible;
if (is_current)
{ {
may_toggle_cursor(term); may_toggle_cursor(term);
update_cursor(term, TRUE); update_cursor(term, TRUE);
@ -1723,7 +1720,10 @@ f_term_getline(typval_T *argvars, typval_T *rettv)
if (buf == NULL) if (buf == NULL)
return; return;
term = buf->b_term; term = buf->b_term;
row = (int)get_tv_number(&argvars[1]); if (argvars[1].v_type == VAR_UNKNOWN)
row = term->tl_cursor_pos.row;
else
row = (int)get_tv_number(&argvars[1]);
if (term->tl_vterm == NULL) if (term->tl_vterm == NULL)
{ {
@ -1814,7 +1814,10 @@ f_term_scrape(typval_T *argvars, typval_T *rettv)
screen = vterm_obtain_screen(term->tl_vterm); screen = vterm_obtain_screen(term->tl_vterm);
l = rettv->vval.v_list; l = rettv->vval.v_list;
pos.row = (int)get_tv_number(&argvars[1]); if (argvars[1].v_type == VAR_UNKNOWN)
pos.row = term->tl_cursor_pos.row;
else
pos.row = (int)get_tv_number(&argvars[1]);
for (pos.col = 0; pos.col < term->tl_cols; ) for (pos.col = 0; pos.col < term->tl_cols; )
{ {
dict_T *dcell; dict_T *dcell;

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 */
/**/
817,
/**/ /**/
816, 816,
/**/ /**/