summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-07-24 21:44:43 +0200
committerBram Moolenaar <Bram@vim.org>2017-07-24 21:44:43 +0200
commit2155441460a6dc0a72125f7860507693112a1460 (patch)
treebfc7f9ad6f58cf6d2cf980e93a90695186ca2b97
parentd60547bf80881f6c99bcbd7c8c4c6cfb7e405a90 (diff)
downloadvim-git-2155441460a6dc0a72125f7860507693112a1460.tar.gz
patch 8.0.0768: terminal window status shows "[Scratch]"v8.0.0768
Problem: Terminal window status shows "[Scratch]". Solution: Show "[Terminal]" when no title was set. (Yasuhiro Matsumoto) Store the terminal title that vterm sends and use it. Update the special buffer name. (closes #1869)
-rw-r--r--src/buffer.c64
-rw-r--r--src/proto/terminal.pro2
-rw-r--r--src/terminal.c112
-rw-r--r--src/version.c2
4 files changed, 130 insertions, 50 deletions
diff --git a/src/buffer.c b/src/buffer.c
index ae23db080..fb1331736 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -3626,6 +3626,13 @@ maketitle(void)
#define SPACE_FOR_ARGNR (IOSIZE - 10) /* at least room for " - VIM" */
if (curbuf->b_fname == NULL)
vim_strncpy(buf, (char_u *)_("[No Name]"), SPACE_FOR_FNAME);
+#ifdef FEAT_TERMINAL
+ else if (curbuf->b_term != NULL)
+ {
+ vim_strncpy(buf, term_get_status_text(curbuf->b_term),
+ SPACE_FOR_FNAME);
+ }
+#endif
else
{
p = transstr(gettail(curbuf->b_fname));
@@ -3633,20 +3640,27 @@ maketitle(void)
vim_free(p);
}
- switch (bufIsChanged(curbuf)
- + (curbuf->b_p_ro * 2)
- + (!curbuf->b_p_ma * 4))
- {
- case 1: STRCAT(buf, " +"); break;
- case 2: STRCAT(buf, " ="); break;
- case 3: STRCAT(buf, " =+"); break;
- case 4:
- case 6: STRCAT(buf, " -"); break;
- case 5:
- case 7: STRCAT(buf, " -+"); break;
- }
+#ifdef FEAT_TERMINAL
+ if (curbuf->b_term == NULL)
+#endif
+ switch (bufIsChanged(curbuf)
+ + (curbuf->b_p_ro * 2)
+ + (!curbuf->b_p_ma * 4))
+ {
+ case 1: STRCAT(buf, " +"); break;
+ case 2: STRCAT(buf, " ="); break;
+ case 3: STRCAT(buf, " =+"); break;
+ case 4:
+ case 6: STRCAT(buf, " -"); break;
+ case 5:
+ case 7: STRCAT(buf, " -+"); break;
+ }
- if (curbuf->b_fname != NULL)
+ if (curbuf->b_fname != NULL
+#ifdef FEAT_TERMINAL
+ && curbuf->b_term == NULL
+#endif
+ )
{
/* Get path of file, replace home dir with ~ */
off = (int)STRLEN(buf);
@@ -3663,18 +3677,8 @@ maketitle(void)
p = gettail_sep(buf + off);
if (p == buf + off)
{
- char *txt;
-
-#ifdef FEAT_TERMINAL
- if (curbuf->b_term != NULL)
- txt = term_job_running(curbuf)
- ? _("running") : _("finished");
- else
-#endif
- txt = _("help");
-
- /* must be a help or terminal buffer */
- vim_strncpy(buf + off, (char_u *)txt,
+ /* must be a help buffer */
+ vim_strncpy(buf + off, (char_u *)_("help"),
(size_t)(SPACE_FOR_DIR - off - 1));
}
else
@@ -5670,16 +5674,20 @@ buf_spname(buf_T *buf)
return (char_u *)_(msg_qflist);
}
#endif
-#ifdef FEAT_QUICKFIX
+
/* There is no _file_ when 'buftype' is "nofile", b_sfname
- * contains the name as specified by the user */
+ * contains the name as specified by the user. */
if (bt_nofile(buf))
{
+#ifdef FEAT_TERMINAL
+ if (buf->b_term != NULL)
+ return term_get_status_text(buf->b_term);
+#endif
if (buf->b_sfname != NULL)
return buf->b_sfname;
return (char_u *)_("[Scratch]");
}
-#endif
+
if (buf->b_fname == NULL)
return (char_u *)_("[No Name]");
return NULL;
diff --git a/src/proto/terminal.pro b/src/proto/terminal.pro
index bdab8902b..d7d153850 100644
--- a/src/proto/terminal.pro
+++ b/src/proto/terminal.pro
@@ -4,6 +4,6 @@ void free_terminal(term_T *term);
void write_to_term(buf_T *buffer, char_u *msg, channel_T *channel);
void terminal_loop(void);
void term_job_ended(job_T *job);
-int term_job_running(buf_T *buf);
void term_update_window(win_T *wp);
+char_u *term_get_status_text(term_T *term);
/* vim: set ft=c : */
diff --git a/src/terminal.c b/src/terminal.c
index f2fae5789..ef3c3c241 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -34,7 +34,6 @@
*
* TODO:
* - do not store terminal buffer in viminfo
- * - put terminal title in the statusline
* - Add a scrollback buffer (contains lines to scroll off the top).
* Can use the buf_T lines, store attributes somewhere else?
* - When the job ends:
@@ -43,6 +42,9 @@
* - Free the terminal emulator.
* - Display the scrollback buffer (but with attributes).
* Make the buffer not modifiable, drop attributes when making changes.
+ * - Need an option or argument to drop the window+buffer right away, to be
+ * used for a shell or Vim.
+ * - add a character in :ls output
* - when closing window and job has not ended, make terminal hidden?
* - don't allow exiting Vim when a terminal is still running a job
* - use win_del_lines() to make scroll-up efficient.
@@ -95,6 +97,9 @@ struct terminal_S {
int tl_rows_fixed;
int tl_cols_fixed;
+ char_u *tl_title; /* NULL or allocated */
+ char_u *tl_status_text; /* NULL or allocated */
+
/* Range of screen rows to update. Zero based. */
int tl_dirty_row_start; /* -1 if nothing dirty */
int tl_dirty_row_end; /* row below last one to update */
@@ -271,6 +276,8 @@ free_terminal(term_T *term)
}
term_free(term);
+ vim_free(term->tl_title);
+ vim_free(term->tl_status_text);
vim_free(term);
}
@@ -527,6 +534,25 @@ terminal_loop(void)
void
term_job_ended(job_T *job)
{
+ term_T *term;
+ int did_one = FALSE;
+
+ for (term = first_term; term != NULL; term = term->tl_next)
+ if (term->tl_job == job)
+ {
+ vim_free(term->tl_title);
+ term->tl_title = NULL;
+ vim_free(term->tl_status_text);
+ term->tl_status_text = NULL;
+ redraw_buf_and_status_later(term->tl_buffer, VALID);
+ did_one = TRUE;
+ }
+ if (did_one)
+ {
+ redraw_statuslines();
+ setcursor();
+ out_flush();
+ }
if (curbuf->b_term != NULL && curbuf->b_term->tl_job == job)
maketitle();
}
@@ -534,11 +560,10 @@ term_job_ended(job_T *job)
/*
* Return TRUE if the job for "buf" is still running.
*/
- int
-term_job_running(buf_T *buf)
+ static int
+term_job_running(term_T *term)
{
- return buf->b_term != NULL && buf->b_term->tl_job != NULL
- && buf->b_term->tl_job->jv_status == JOB_STARTED;
+ return term->tl_job != NULL && term->tl_job->jv_status == JOB_STARTED;
}
static void
@@ -548,22 +573,6 @@ position_cursor(win_T *wp, VTermPos *pos)
wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1));
}
-static int handle_damage(VTermRect rect, void *user);
-static int handle_moverect(VTermRect dest, VTermRect src, void *user);
-static int handle_movecursor(VTermPos pos, VTermPos oldpos, int visible, void *user);
-static int handle_resize(int rows, int cols, void *user);
-
-static VTermScreenCallbacks screen_callbacks = {
- handle_damage, /* damage */
- handle_moverect, /* moverect */
- handle_movecursor, /* movecursor */
- NULL, /* settermprop */
- NULL, /* bell */
- handle_resize, /* resize */
- NULL, /* sb_pushline */
- NULL /* sb_popline */
-};
-
static int
handle_damage(VTermRect rect, void *user)
{
@@ -615,6 +624,30 @@ handle_movecursor(
return 1;
}
+ static int
+handle_settermprop(
+ VTermProp prop,
+ VTermValue *value,
+ void *user)
+{
+ term_T *term = (term_T *)user;
+
+ switch (prop)
+ {
+ case VTERM_PROP_TITLE:
+ vim_free(term->tl_title);
+ term->tl_title = vim_strsave((char_u *)value->string);
+ vim_free(term->tl_status_text);
+ term->tl_status_text = NULL;
+ if (term == curbuf->b_term)
+ maketitle();
+ return 1;
+ default:
+ break;
+ }
+ return 0;
+}
+
/*
* The job running in the terminal resized the terminal.
*/
@@ -639,6 +672,17 @@ handle_resize(int rows, int cols, void *user)
return 1;
}
+static VTermScreenCallbacks screen_callbacks = {
+ handle_damage, /* damage */
+ handle_moverect, /* moverect */
+ handle_movecursor, /* movecursor */
+ handle_settermprop, /* settermprop */
+ NULL, /* bell */
+ handle_resize, /* resize */
+ NULL, /* sb_pushline */
+ NULL /* sb_popline */
+};
+
/*
* Reverse engineer the RGB value into a cterm color index.
* First color is 1. Return 0 if no match found.
@@ -950,6 +994,32 @@ create_vterm(term_T *term, int rows, int cols)
vterm_screen_reset(screen, 1 /* hard */);
}
+/*
+ * Return the text to show for the buffer name and status.
+ */
+ char_u *
+term_get_status_text(term_T *term)
+{
+ if (term->tl_status_text == NULL)
+ {
+ char_u *txt;
+ size_t len;
+
+ if (term->tl_title != NULL)
+ txt = term->tl_title;
+ else if (term_job_running(term))
+ txt = (char_u *)_("running");
+ else
+ txt = (char_u *)_("finished");
+ len = 9 + STRLEN(term->tl_buffer->b_fname) + STRLEN(txt);
+ term->tl_status_text = alloc(len);
+ if (term->tl_status_text != NULL)
+ vim_snprintf((char *)term->tl_status_text, len, "%s [%s]",
+ term->tl_buffer->b_fname, txt);
+ }
+ return term->tl_status_text;
+}
+
# ifdef WIN3264
#define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
diff --git a/src/version.c b/src/version.c
index d629eac52..894fa452d 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 */
/**/
+ 768,
+/**/
767,
/**/
766,