summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-07-30 19:38:21 +0200
committerBram Moolenaar <Bram@vim.org>2017-07-30 19:38:21 +0200
commitb000e328efcf859d14454ffd241d44f6d14f300b (patch)
treef82e07a6c46fcd8a2cc61946a5943c336896d507
parent12d93ee26d4290321ed0cc3d0493b966d1475a66 (diff)
downloadvim-git-b000e328efcf859d14454ffd241d44f6d14f300b.tar.gz
patch 8.0.0821: cannot get the title and status of a terminal windowv8.0.0821
Problem: Cannot get the title and status of a terminal window. Solution: Implement term_gettitle() and term_getstatus().
-rw-r--r--runtime/doc/eval.txt22
-rw-r--r--src/evalfunc.c2
-rw-r--r--src/proto/terminal.pro2
-rw-r--r--src/terminal.c46
-rw-r--r--src/version.c2
5 files changed, 69 insertions, 5 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index adaa8176e..f43e7164a 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2374,6 +2374,8 @@ term_getcursor({buf}) List get the cursor position of 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_getsize({buf}) List get the size of a terminal
+term_getstatus({buf}) String get the status of a terminal
+term_gettitle({buf}) String get the title of a terminal
term_list() List get the list of terminal buffers
term_scrape({buf}[, {row}]) List get row of a terminal screen
term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
@@ -7945,6 +7947,26 @@ term_getsize({buf}) *term_getsize()*
buffer does not exist or is not a terminal window, an empty
list is returned.
+term_getstatus({buf}) *term_getstatus()*
+ Get the status of terminal {buf}. This returns a comma
+ separated list of these items:
+ running job is running
+ finished job has finished
+ terminal in Terminal-Normal mode
+ One of "running" or "finished" is always present.
+
+ {buf} must be the buffer number of a terminal window. If the
+ buffer does not exist or is not a terminal window, an empty
+ string is returned.
+
+term_gettitle({buf}) *term_gettitle()*
+ Get the title of terminal {buf}. This is the title that the
+ job in the terminal has set.
+
+ {buf} must be the buffer number of a terminal window. If the
+ buffer does not exist or is not a terminal window, an empty
+ string is returned.
+
term_list() *term_list()*
Return a list with the buffer numbers of all buffers for
terminal windows.
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 2c11de191..fc0e05dad 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -836,6 +836,8 @@ static struct fst
{"term_getjob", 1, 1, f_term_getjob},
{"term_getline", 1, 2, f_term_getline},
{"term_getsize", 1, 1, f_term_getsize},
+ {"term_getstatus", 1, 1, f_term_getstatus},
+ {"term_gettitle", 1, 1, f_term_gettitle},
{"term_list", 0, 0, f_term_list},
{"term_scrape", 1, 2, f_term_scrape},
{"term_sendkeys", 2, 2, f_term_sendkeys},
diff --git a/src/proto/terminal.pro b/src/proto/terminal.pro
index 63cda59ca..24789293d 100644
--- a/src/proto/terminal.pro
+++ b/src/proto/terminal.pro
@@ -20,6 +20,8 @@ void f_term_getcursor(typval_T *argvars, typval_T *rettv);
void f_term_getjob(typval_T *argvars, typval_T *rettv);
void f_term_getline(typval_T *argvars, typval_T *rettv);
void f_term_getsize(typval_T *argvars, typval_T *rettv);
+void f_term_getstatus(typval_T *argvars, typval_T *rettv);
+void f_term_gettitle(typval_T *argvars, typval_T *rettv);
void f_term_list(typval_T *argvars, typval_T *rettv);
void f_term_scrape(typval_T *argvars, typval_T *rettv);
void f_term_sendkeys(typval_T *argvars, typval_T *rettv);
diff --git a/src/terminal.c b/src/terminal.c
index b289f6c99..d04b99ec6 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -36,15 +36,11 @@
* that buffer, attributes come from the scrollback buffer tl_scrollback.
*
* TODO:
- * - Problem with statusline (Zyx, Christian)
* - Make CTRL-W "" paste register content to the job?
* - in bash mouse clicks are inserting characters.
* - mouse scroll: when over other window, scroll that window.
* - For the scrollback buffer store lines in the buffer, only attributes in
* tl_scrollback.
- * - Add term_status(): "" if not a terminal, "running" if job running,
- * "finished" if finished, "running,vim" when job is running and in
- * Terminal mode, "running,vim,pending" when job output is pending.
* - When the job ends:
* - Need an option or argument to drop the window+buffer right away, to be
* 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)
}
/*
- * Return TRUE if the job for "buf" is still running.
+ * Return TRUE if the job for "term" is still running.
*/
static int
term_job_running(term_T *term)
@@ -1799,6 +1795,46 @@ f_term_getsize(typval_T *argvars, typval_T *rettv)
}
/*
+ * "term_getstatus(buf)" function
+ */
+ void
+f_term_getstatus(typval_T *argvars, typval_T *rettv)
+{
+ buf_T *buf = term_get_buf(argvars);
+ term_T *term;
+ char_u val[100];
+
+ rettv->v_type = VAR_STRING;
+ if (buf == NULL)
+ return;
+ term = buf->b_term;
+
+ if (term_job_running(term))
+ STRCPY(val, "running");
+ else
+ STRCPY(val, "finished");
+ if (term->tl_terminal_mode)
+ STRCAT(val, ",terminal");
+ rettv->vval.v_string = vim_strsave(val);
+}
+
+/*
+ * "term_gettitle(buf)" function
+ */
+ void
+f_term_gettitle(typval_T *argvars, typval_T *rettv)
+{
+ buf_T *buf = term_get_buf(argvars);
+
+ rettv->v_type = VAR_STRING;
+ if (buf == NULL)
+ return;
+
+ if (buf->b_term->tl_title != NULL)
+ rettv->vval.v_string = vim_strsave(buf->b_term->tl_title);
+}
+
+/*
* "term_list()" function
*/
void
diff --git a/src/version.c b/src/version.c
index 8733db28e..875119f41 100644
--- a/src/version.c
+++ b/src/version.c
@@ -770,6 +770,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 821,
+/**/
820,
/**/
819,