Skip to content

Commit b000e32

Browse files
committed
patch 8.0.0821: cannot get the title and status of a terminal window
Problem: Cannot get the title and status of a terminal window. Solution: Implement term_gettitle() and term_getstatus().
1 parent 12d93ee commit b000e32

5 files changed

Lines changed: 69 additions & 5 deletions

File tree

runtime/doc/eval.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,8 @@ term_getcursor({buf}) List get the cursor position of a terminal
23742374
term_getjob({buf}) Job get the job associated with a terminal
23752375
term_getline({buf}[, {row}]) String get a line of text from a terminal
23762376
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
23772379
term_list() List get the list of terminal buffers
23782380
term_scrape({buf}[, {row}]) List get row of a terminal screen
23792381
term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
@@ -7945,6 +7947,26 @@ term_getsize({buf}) *term_getsize()*
79457947
buffer does not exist or is not a terminal window, an empty
79467948
list is returned.
79477949

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+
79487970
term_list() *term_list()*
79497971
Return a list with the buffer numbers of all buffers for
79507972
terminal windows.

src/evalfunc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,8 @@ static struct fst
836836
{"term_getjob", 1, 1, f_term_getjob},
837837
{"term_getline", 1, 2, f_term_getline},
838838
{"term_getsize", 1, 1, f_term_getsize},
839+
{"term_getstatus", 1, 1, f_term_getstatus},
840+
{"term_gettitle", 1, 1, f_term_gettitle},
839841
{"term_list", 0, 0, f_term_list},
840842
{"term_scrape", 1, 2, f_term_scrape},
841843
{"term_sendkeys", 2, 2, f_term_sendkeys},

src/proto/terminal.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ void f_term_getcursor(typval_T *argvars, typval_T *rettv);
2020
void f_term_getjob(typval_T *argvars, typval_T *rettv);
2121
void f_term_getline(typval_T *argvars, typval_T *rettv);
2222
void f_term_getsize(typval_T *argvars, typval_T *rettv);
23+
void f_term_getstatus(typval_T *argvars, typval_T *rettv);
24+
void f_term_gettitle(typval_T *argvars, typval_T *rettv);
2325
void f_term_list(typval_T *argvars, typval_T *rettv);
2426
void f_term_scrape(typval_T *argvars, typval_T *rettv);
2527
void f_term_sendkeys(typval_T *argvars, typval_T *rettv);

src/terminal.c

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,11 @@
3636
* that buffer, attributes come from the scrollback buffer tl_scrollback.
3737
*
3838
* TODO:
39-
* - Problem with statusline (Zyx, Christian)
4039
* - Make CTRL-W "" paste register content to the job?
4140
* - in bash mouse clicks are inserting characters.
4241
* - mouse scroll: when over other window, scroll that window.
4342
* - For the scrollback buffer store lines in the buffer, only attributes in
4443
* tl_scrollback.
45-
* - Add term_status(): "" if not a terminal, "running" if job running,
46-
* "finished" if finished, "running,vim" when job is running and in
47-
* Terminal mode, "running,vim,pending" when job output is pending.
4844
* - When the job ends:
4945
* - Need an option or argument to drop the window+buffer right away, to be
5046
* used for a shell or Vim. 'termfinish'; "close", "open" (open window when
@@ -560,7 +556,7 @@ term_convert_key(term_T *term, int c, char *buf)
560556
}
561557

562558
/*
563-
* Return TRUE if the job for "buf" is still running.
559+
* Return TRUE if the job for "term" is still running.
564560
*/
565561
static int
566562
term_job_running(term_T *term)
@@ -1798,6 +1794,46 @@ f_term_getsize(typval_T *argvars, typval_T *rettv)
17981794
list_append_number(l, buf->b_term->tl_cols);
17991795
}
18001796

1797+
/*
1798+
* "term_getstatus(buf)" function
1799+
*/
1800+
void
1801+
f_term_getstatus(typval_T *argvars, typval_T *rettv)
1802+
{
1803+
buf_T *buf = term_get_buf(argvars);
1804+
term_T *term;
1805+
char_u val[100];
1806+
1807+
rettv->v_type = VAR_STRING;
1808+
if (buf == NULL)
1809+
return;
1810+
term = buf->b_term;
1811+
1812+
if (term_job_running(term))
1813+
STRCPY(val, "running");
1814+
else
1815+
STRCPY(val, "finished");
1816+
if (term->tl_terminal_mode)
1817+
STRCAT(val, ",terminal");
1818+
rettv->vval.v_string = vim_strsave(val);
1819+
}
1820+
1821+
/*
1822+
* "term_gettitle(buf)" function
1823+
*/
1824+
void
1825+
f_term_gettitle(typval_T *argvars, typval_T *rettv)
1826+
{
1827+
buf_T *buf = term_get_buf(argvars);
1828+
1829+
rettv->v_type = VAR_STRING;
1830+
if (buf == NULL)
1831+
return;
1832+
1833+
if (buf->b_term->tl_title != NULL)
1834+
rettv->vval.v_string = vim_strsave(buf->b_term->tl_title);
1835+
}
1836+
18011837
/*
18021838
* "term_list()" function
18031839
*/

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+
821,
772774
/**/
773775
820,
774776
/**/

0 commit comments

Comments
 (0)