Skip to content

Commit 238d43b

Browse files
committed
patch 8.0.1096: terminal window in Normal mode has wrong background
Problem: Terminal window in Normal mode has wrong background. Solution: Store the default background and use it for clearning until the end of the line. Not for below the last line, since there is no text there.
1 parent a038cb5 commit 238d43b

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

src/screen.c

+14
Original file line numberDiff line numberDiff line change
@@ -3139,6 +3139,7 @@ win_line(
31393139
#endif
31403140
#ifdef FEAT_TERMINAL
31413141
int get_term_attr = FALSE;
3142+
int term_attr = 0; /* background for terminal window */
31423143
#endif
31433144

31443145
/* draw_state: items that are drawn in sequence: */
@@ -3256,6 +3257,7 @@ win_line(
32563257
{
32573258
extra_check = TRUE;
32583259
get_term_attr = TRUE;
3260+
term_attr = term_get_attr(wp->w_buffer, 0, 0);
32593261
}
32603262
#endif
32613263

@@ -5056,6 +5058,9 @@ win_line(
50565058
else if ((
50575059
# ifdef FEAT_DIFF
50585060
diff_hlf != (hlf_T)0 ||
5061+
# endif
5062+
# ifdef FEAT_TERMINAL
5063+
term_attr != 0 ||
50595064
# endif
50605065
line_attr != 0
50615066
) && (
@@ -5090,6 +5095,15 @@ win_line(
50905095
HL_ATTR(HLF_CUL));
50915096
}
50925097
}
5098+
# endif
5099+
# ifdef FEAT_TERMINAL
5100+
if (term_attr != 0)
5101+
{
5102+
char_attr = term_attr;
5103+
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
5104+
char_attr = hl_combine_attr(char_attr,
5105+
HL_ATTR(HLF_CUL));
5106+
}
50935107
# endif
50945108
}
50955109
#endif

src/terminal.c

+28-14
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
*
4040
* TODO:
4141
* - patch to use GUI or cterm colors for vterm. Yasuhiro, #2067
42-
* - when Normal background is not white or black, going to Terminal-Normal
43-
* mode does not clear correctly. Use the terminal background color to erase
44-
* the background.
4542
* - patch to add tmap, jakalope (Jacob Askeland) #2073
4643
* - Redirecting output does not work on MS-Windows.
4744
* - implement term_setsize()
@@ -130,6 +127,7 @@ struct terminal_S {
130127

131128
garray_T tl_scrollback;
132129
int tl_scrollback_scrolled;
130+
cellattr_T tl_default_color;
133131

134132
VTermPos tl_cursor_pos;
135133
int tl_cursor_visible;
@@ -2321,6 +2319,7 @@ term_change_in_curbuf(void)
23212319

23222320
/*
23232321
* Get the screen attribute for a position in the buffer.
2322+
* Use a zero "lnum" to get the default background color.
23242323
*/
23252324
int
23262325
term_get_attr(buf_T *buf, linenr_T lnum, int col)
@@ -2329,12 +2328,16 @@ term_get_attr(buf_T *buf, linenr_T lnum, int col)
23292328
sb_line_T *line;
23302329
cellattr_T *cellattr;
23312330

2332-
if (lnum > term->tl_scrollback.ga_len)
2333-
return 0;
2334-
line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1;
2335-
if (col >= line->sb_cols)
2336-
return 0;
2337-
cellattr = line->sb_cells + col;
2331+
if (lnum == 0 || lnum > term->tl_scrollback.ga_len)
2332+
cellattr = &term->tl_default_color;
2333+
else
2334+
{
2335+
line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1;
2336+
if (col >= line->sb_cols)
2337+
cellattr = &term->tl_default_color;
2338+
else
2339+
cellattr = line->sb_cells + col;
2340+
}
23382341
return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg);
23392342
}
23402343

@@ -2347,6 +2350,8 @@ create_vterm(term_T *term, int rows, int cols)
23472350
VTerm *vterm;
23482351
VTermScreen *screen;
23492352
VTermValue value;
2353+
VTermColor *fg, *bg;
2354+
int fgval, bgval;
23502355

23512356
vterm = vterm_new(rows, cols);
23522357
term->tl_vterm = vterm;
@@ -2357,14 +2362,23 @@ create_vterm(term_T *term, int rows, int cols)
23572362

23582363
/* Vterm uses a default black background. Set it to white when
23592364
* 'background' is "light". */
2365+
vim_memset(&term->tl_default_color.attrs, 0, sizeof(VTermScreenCellAttrs));
2366+
term->tl_default_color.width = 1;
2367+
fg = &term->tl_default_color.fg;
2368+
bg = &term->tl_default_color.bg;
23602369
if (*p_bg == 'l')
23612370
{
2362-
VTermColor fg, bg;
2363-
2364-
fg.red = fg.green = fg.blue = 0;
2365-
bg.red = bg.green = bg.blue = 255;
2366-
vterm_state_set_default_colors(vterm_obtain_state(vterm), &fg, &bg);
2371+
fgval = 0;
2372+
bgval = 255;
2373+
}
2374+
else
2375+
{
2376+
fgval = 255;
2377+
bgval = 0;
23672378
}
2379+
fg->red = fg->green = fg->blue = fgval;
2380+
bg->red = bg->green = bg->blue = bgval;
2381+
vterm_state_set_default_colors(vterm_obtain_state(vterm), fg, bg);
23682382

23692383
/* Required to initialize most things. */
23702384
vterm_screen_reset(screen, 1 /* hard */);

src/version.c

+2
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+
1096,
772774
/**/
773775
1095,
774776
/**/

0 commit comments

Comments
 (0)