Skip to content

Commit 63ecdda

Browse files
committed
patch 8.0.0798: no highlighting in a terminal window with a finished job
Problem: No highlighting in a terminal window with a finished job. Solution: Highlight the text.
1 parent d85f271 commit 63ecdda

5 files changed

Lines changed: 93 additions & 8 deletions

File tree

src/proto/terminal.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ void write_to_term(buf_T *buffer, char_u *msg, channel_T *channel);
55
int terminal_loop(void);
66
void term_channel_closed(channel_T *ch);
77
int term_update_window(win_T *wp);
8+
int term_is_finished(buf_T *buf);
9+
void term_change_in_curbuf(void);
10+
int term_get_attr(buf_T *buf, linenr_T lnum, int col);
811
char_u *term_get_status_text(term_T *term);
912
int set_ref_in_term(int copyID);
1013
/* vim: set ft=c : */

src/screen.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,6 +3130,9 @@ win_line(
31303130
#if defined(LINE_ATTR)
31313131
int did_line_attr = 0;
31323132
#endif
3133+
#ifdef FEAT_TERMINAL
3134+
int get_term_attr = FALSE;
3135+
#endif
31333136

31343137
/* draw_state: items that are drawn in sequence: */
31353138
#define WL_START 0 /* nothing done yet */
@@ -3241,6 +3244,14 @@ win_line(
32413244
draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
32423245
#endif
32433246

3247+
#ifdef FEAT_TERMINAL
3248+
if (term_is_finished(wp->w_buffer))
3249+
{
3250+
extra_check = TRUE;
3251+
get_term_attr = TRUE;
3252+
}
3253+
#endif
3254+
32443255
#ifdef FEAT_SPELL
32453256
if (wp->w_p_spell
32463257
&& *wp->w_s->b_p_spl != NUL
@@ -4527,6 +4538,18 @@ win_line(
45274538
int can_spell = TRUE;
45284539
#endif
45294540

4541+
#ifdef FEAT_TERMINAL
4542+
if (get_term_attr)
4543+
{
4544+
syntax_attr = term_get_attr(wp->w_buffer, lnum, col);
4545+
4546+
if (!attr_pri)
4547+
char_attr = syntax_attr;
4548+
else
4549+
char_attr = hl_combine_attr(syntax_attr, char_attr);
4550+
}
4551+
#endif
4552+
45304553
#ifdef FEAT_SYN_HL
45314554
/* Get syntax attribute, unless still at the start of the line
45324555
* (double-wide char that doesn't fit). */

src/terminal.c

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Uses pseudo-tty's (pty's).
2020
*
2121
* For each terminal one VTerm is constructed. This uses libvterm. A copy of
22-
* that library is in the libvterm directory.
22+
* this library is in the libvterm directory.
2323
*
2424
* When a terminal window is opened, a job is started that will be connected to
2525
* the terminal emulator.
@@ -32,16 +32,17 @@
3232
* line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a
3333
* while, if the terminal window is visible, the screen contents is drawn.
3434
*
35+
* When the job ends the text is put in a buffer. Redrawing then happens from
36+
* that buffer, attributes come from the scrollback buffer tl_scrollback.
37+
*
3538
* TODO:
39+
* - Patch for functions: Yasuhiro Matsumoto, #1871
3640
* - For the scrollback buffer store lines in the buffer, only attributes in
3741
* tl_scrollback.
3842
* - When the job ends:
39-
* - Display the scrollback buffer (but with attributes).
40-
* Make the buffer not modifiable, drop attributes when making changes.
4143
* - Need an option or argument to drop the window+buffer right away, to be
4244
* used for a shell or Vim.
4345
* - To set BS correctly, check get_stty(); Pass the fd of the pty.
44-
* - Patch for functions: Yasuhiro Matsumoto, #1871
4546
* - do not store terminal buffer in viminfo. Or prefix term:// ?
4647
* - add a character in :ls output
4748
* - when closing window and job has not ended, make terminal hidden?
@@ -253,6 +254,19 @@ ex_terminal(exarg_T *eap)
253254
/* TODO: Setup pty, see mch_call_shell(). */
254255
}
255256

257+
/*
258+
* Free the scrollback buffer for "term".
259+
*/
260+
static void
261+
free_scrollback(term_T *term)
262+
{
263+
int i;
264+
265+
for (i = 0; i < term->tl_scrollback.ga_len; ++i)
266+
vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells);
267+
ga_clear(&term->tl_scrollback);
268+
}
269+
256270
/*
257271
* Free a terminal and everything it refers to.
258272
* Kills the job if there is one.
@@ -263,7 +277,6 @@ free_terminal(buf_T *buf)
263277
{
264278
term_T *term = buf->b_term;
265279
term_T *tp;
266-
int i;
267280

268281
if (term == NULL)
269282
return;
@@ -285,9 +298,7 @@ free_terminal(buf_T *buf)
285298
job_unref(term->tl_job);
286299
}
287300

288-
for (i = 0; i < term->tl_scrollback.ga_len; ++i)
289-
vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i) ->sb_cells);
290-
ga_clear(&term->tl_scrollback);
301+
free_scrollback(term);
291302

292303
term_free_vterm(term);
293304
vim_free(term->tl_title);
@@ -1217,6 +1228,48 @@ term_update_window(win_T *wp)
12171228
return OK;
12181229
}
12191230

1231+
/*
1232+
* Return TRUE if "wp" is a terminal window where the job has finished.
1233+
*/
1234+
int
1235+
term_is_finished(buf_T *buf)
1236+
{
1237+
return buf->b_term != NULL && buf->b_term->tl_vterm == NULL;
1238+
}
1239+
1240+
/*
1241+
* The current buffer is going to be changed. If there is terminal
1242+
* highlighting remove it now.
1243+
*/
1244+
void
1245+
term_change_in_curbuf(void)
1246+
{
1247+
term_T *term = curbuf->b_term;
1248+
1249+
if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0)
1250+
{
1251+
free_scrollback(term);
1252+
redraw_buf_later(term->tl_buffer, NOT_VALID);
1253+
}
1254+
}
1255+
1256+
/*
1257+
* Get the screen attribute for a position in the buffer.
1258+
*/
1259+
int
1260+
term_get_attr(buf_T *buf, linenr_T lnum, int col)
1261+
{
1262+
term_T *term = buf->b_term;
1263+
sb_line_T *line;
1264+
1265+
if (lnum >= term->tl_scrollback.ga_len)
1266+
return 0;
1267+
line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1;
1268+
if (col >= line->sb_cols)
1269+
return 0;
1270+
return cell2attr(line->sb_cells + col);
1271+
}
1272+
12201273
/*
12211274
* Set job options common for Unix and MS-Windows.
12221275
*/

src/undo.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ u_savecommon(
419419
}
420420
}
421421
#endif
422+
#ifdef FEAT_TERMINAL
423+
/* A change in a terminal buffer removes the highlighting. */
424+
term_change_in_curbuf();
425+
#endif
422426

423427
#ifdef FEAT_AUTOCMD
424428
/*

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+
798,
772774
/**/
773775
797,
774776
/**/

0 commit comments

Comments
 (0)