patch 8.0.0768: terminal window status shows "[Scratch]"
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)
This commit is contained in:
64
src/buffer.c
64
src/buffer.c
@ -3626,6 +3626,13 @@ maketitle(void)
|
|||||||
#define SPACE_FOR_ARGNR (IOSIZE - 10) /* at least room for " - VIM" */
|
#define SPACE_FOR_ARGNR (IOSIZE - 10) /* at least room for " - VIM" */
|
||||||
if (curbuf->b_fname == NULL)
|
if (curbuf->b_fname == NULL)
|
||||||
vim_strncpy(buf, (char_u *)_("[No Name]"), SPACE_FOR_FNAME);
|
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
|
else
|
||||||
{
|
{
|
||||||
p = transstr(gettail(curbuf->b_fname));
|
p = transstr(gettail(curbuf->b_fname));
|
||||||
@ -3633,20 +3640,27 @@ maketitle(void)
|
|||||||
vim_free(p);
|
vim_free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (bufIsChanged(curbuf)
|
#ifdef FEAT_TERMINAL
|
||||||
+ (curbuf->b_p_ro * 2)
|
if (curbuf->b_term == NULL)
|
||||||
+ (!curbuf->b_p_ma * 4))
|
#endif
|
||||||
{
|
switch (bufIsChanged(curbuf)
|
||||||
case 1: STRCAT(buf, " +"); break;
|
+ (curbuf->b_p_ro * 2)
|
||||||
case 2: STRCAT(buf, " ="); break;
|
+ (!curbuf->b_p_ma * 4))
|
||||||
case 3: STRCAT(buf, " =+"); break;
|
{
|
||||||
case 4:
|
case 1: STRCAT(buf, " +"); break;
|
||||||
case 6: STRCAT(buf, " -"); break;
|
case 2: STRCAT(buf, " ="); break;
|
||||||
case 5:
|
case 3: STRCAT(buf, " =+"); break;
|
||||||
case 7: 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 ~ */
|
/* Get path of file, replace home dir with ~ */
|
||||||
off = (int)STRLEN(buf);
|
off = (int)STRLEN(buf);
|
||||||
@ -3663,18 +3677,8 @@ maketitle(void)
|
|||||||
p = gettail_sep(buf + off);
|
p = gettail_sep(buf + off);
|
||||||
if (p == buf + off)
|
if (p == buf + off)
|
||||||
{
|
{
|
||||||
char *txt;
|
/* must be a help buffer */
|
||||||
|
vim_strncpy(buf + off, (char_u *)_("help"),
|
||||||
#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,
|
|
||||||
(size_t)(SPACE_FOR_DIR - off - 1));
|
(size_t)(SPACE_FOR_DIR - off - 1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -5670,16 +5674,20 @@ buf_spname(buf_T *buf)
|
|||||||
return (char_u *)_(msg_qflist);
|
return (char_u *)_(msg_qflist);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_QUICKFIX
|
|
||||||
/* There is no _file_ when 'buftype' is "nofile", b_sfname
|
/* 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))
|
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)
|
if (buf->b_sfname != NULL)
|
||||||
return buf->b_sfname;
|
return buf->b_sfname;
|
||||||
return (char_u *)_("[Scratch]");
|
return (char_u *)_("[Scratch]");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if (buf->b_fname == NULL)
|
if (buf->b_fname == NULL)
|
||||||
return (char_u *)_("[No Name]");
|
return (char_u *)_("[No Name]");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@ -4,6 +4,6 @@ void free_terminal(term_T *term);
|
|||||||
void write_to_term(buf_T *buffer, char_u *msg, channel_T *channel);
|
void write_to_term(buf_T *buffer, char_u *msg, channel_T *channel);
|
||||||
void terminal_loop(void);
|
void terminal_loop(void);
|
||||||
void term_job_ended(job_T *job);
|
void term_job_ended(job_T *job);
|
||||||
int term_job_running(buf_T *buf);
|
|
||||||
void term_update_window(win_T *wp);
|
void term_update_window(win_T *wp);
|
||||||
|
char_u *term_get_status_text(term_T *term);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
|||||||
112
src/terminal.c
112
src/terminal.c
@ -34,7 +34,6 @@
|
|||||||
*
|
*
|
||||||
* TODO:
|
* TODO:
|
||||||
* - do not store terminal buffer in viminfo
|
* - do not store terminal buffer in viminfo
|
||||||
* - put terminal title in the statusline
|
|
||||||
* - Add a scrollback buffer (contains lines to scroll off the top).
|
* - Add a scrollback buffer (contains lines to scroll off the top).
|
||||||
* Can use the buf_T lines, store attributes somewhere else?
|
* Can use the buf_T lines, store attributes somewhere else?
|
||||||
* - When the job ends:
|
* - When the job ends:
|
||||||
@ -43,6 +42,9 @@
|
|||||||
* - Free the terminal emulator.
|
* - Free the terminal emulator.
|
||||||
* - Display the scrollback buffer (but with attributes).
|
* - Display the scrollback buffer (but with attributes).
|
||||||
* Make the buffer not modifiable, drop attributes when making changes.
|
* 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?
|
* - when closing window and job has not ended, make terminal hidden?
|
||||||
* - don't allow exiting Vim when a terminal is still running a job
|
* - don't allow exiting Vim when a terminal is still running a job
|
||||||
* - use win_del_lines() to make scroll-up efficient.
|
* - use win_del_lines() to make scroll-up efficient.
|
||||||
@ -95,6 +97,9 @@ struct terminal_S {
|
|||||||
int tl_rows_fixed;
|
int tl_rows_fixed;
|
||||||
int tl_cols_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. */
|
/* Range of screen rows to update. Zero based. */
|
||||||
int tl_dirty_row_start; /* -1 if nothing dirty */
|
int tl_dirty_row_start; /* -1 if nothing dirty */
|
||||||
int tl_dirty_row_end; /* row below last one to update */
|
int tl_dirty_row_end; /* row below last one to update */
|
||||||
@ -271,6 +276,8 @@ free_terminal(term_T *term)
|
|||||||
}
|
}
|
||||||
|
|
||||||
term_free(term);
|
term_free(term);
|
||||||
|
vim_free(term->tl_title);
|
||||||
|
vim_free(term->tl_status_text);
|
||||||
vim_free(term);
|
vim_free(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,6 +534,25 @@ terminal_loop(void)
|
|||||||
void
|
void
|
||||||
term_job_ended(job_T *job)
|
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)
|
if (curbuf->b_term != NULL && curbuf->b_term->tl_job == job)
|
||||||
maketitle();
|
maketitle();
|
||||||
}
|
}
|
||||||
@ -534,11 +560,10 @@ term_job_ended(job_T *job)
|
|||||||
/*
|
/*
|
||||||
* Return TRUE if the job for "buf" is still running.
|
* Return TRUE if the job for "buf" is still running.
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
term_job_running(buf_T *buf)
|
term_job_running(term_T *term)
|
||||||
{
|
{
|
||||||
return buf->b_term != NULL && buf->b_term->tl_job != NULL
|
return term->tl_job != NULL && term->tl_job->jv_status == JOB_STARTED;
|
||||||
&& buf->b_term->tl_job->jv_status == JOB_STARTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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));
|
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
|
static int
|
||||||
handle_damage(VTermRect rect, void *user)
|
handle_damage(VTermRect rect, void *user)
|
||||||
{
|
{
|
||||||
@ -615,6 +624,30 @@ handle_movecursor(
|
|||||||
return 1;
|
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.
|
* The job running in the terminal resized the terminal.
|
||||||
*/
|
*/
|
||||||
@ -639,6 +672,17 @@ handle_resize(int rows, int cols, void *user)
|
|||||||
return 1;
|
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.
|
* Reverse engineer the RGB value into a cterm color index.
|
||||||
* First color is 1. Return 0 if no match found.
|
* 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 */);
|
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
|
# ifdef WIN3264
|
||||||
|
|
||||||
#define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
|
#define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
|
||||||
|
|||||||
@ -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 */
|
||||||
|
/**/
|
||||||
|
768,
|
||||||
/**/
|
/**/
|
||||||
767,
|
767,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
Reference in New Issue
Block a user