]> granicus.if.org Git - vim/commitdiff
patch 8.0.1096: terminal window in Normal mode has wrong background v8.0.1096
authorBram Moolenaar <Bram@vim.org>
Mon, 11 Sep 2017 20:00:51 +0000 (22:00 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 11 Sep 2017 20:00:51 +0000 (22:00 +0200)
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.

src/screen.c
src/terminal.c
src/version.c

index e0d4af8fc63f05d9ea15c419b6120e4f412c5046..40c9a15a11b48cc245bf45f98015f21c3198fd4c 100644 (file)
@@ -3139,6 +3139,7 @@ win_line(
 #endif
 #ifdef FEAT_TERMINAL
     int                get_term_attr = FALSE;
+    int                term_attr = 0;          /* background for terminal window */
 #endif
 
     /* draw_state: items that are drawn in sequence: */
@@ -3256,6 +3257,7 @@ win_line(
     {
        extra_check = TRUE;
        get_term_attr = TRUE;
+       term_attr = term_get_attr(wp->w_buffer, 0, 0);
     }
 #endif
 
@@ -5056,6 +5058,9 @@ win_line(
                else if ((
 # ifdef FEAT_DIFF
                            diff_hlf != (hlf_T)0 ||
+# endif
+# ifdef FEAT_TERMINAL
+                           term_attr != 0 ||
 # endif
                            line_attr != 0
                        ) && (
@@ -5090,6 +5095,15 @@ win_line(
                                                            HL_ATTR(HLF_CUL));
                        }
                    }
+# endif
+# ifdef FEAT_TERMINAL
+                   if (term_attr != 0)
+                   {
+                       char_attr = term_attr;
+                       if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
+                           char_attr = hl_combine_attr(char_attr,
+                                                           HL_ATTR(HLF_CUL));
+                   }
 # endif
                }
 #endif
index 391121d5709d89cec6a16d7ec993adc823e04292..45f2ed623de34df98dfbaef9d706cd63ea52f0eb 100644 (file)
@@ -39,9 +39,6 @@
  *
  * TODO:
  * - patch to use GUI or cterm colors for vterm. Yasuhiro, #2067
- * - when Normal background is not white or black, going to Terminal-Normal
- *   mode does not clear correctly.  Use the terminal background color to erase
- *   the background.
  * - patch to add tmap, jakalope (Jacob Askeland) #2073
  * - Redirecting output does not work on MS-Windows.
  * - implement term_setsize()
@@ -130,6 +127,7 @@ struct terminal_S {
 
     garray_T   tl_scrollback;
     int                tl_scrollback_scrolled;
+    cellattr_T tl_default_color;
 
     VTermPos   tl_cursor_pos;
     int                tl_cursor_visible;
@@ -2321,6 +2319,7 @@ term_change_in_curbuf(void)
 
 /*
  * Get the screen attribute for a position in the buffer.
+ * Use a zero "lnum" to get the default background color.
  */
     int
 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)
     sb_line_T  *line;
     cellattr_T *cellattr;
 
-    if (lnum > term->tl_scrollback.ga_len)
-       return 0;
-    line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1;
-    if (col >= line->sb_cols)
-       return 0;
-    cellattr = line->sb_cells + col;
+    if (lnum == 0 || lnum > term->tl_scrollback.ga_len)
+       cellattr = &term->tl_default_color;
+    else
+    {
+       line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1;
+       if (col >= line->sb_cols)
+           cellattr = &term->tl_default_color;
+       else
+           cellattr = line->sb_cells + col;
+    }
     return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg);
 }
 
@@ -2347,6 +2350,8 @@ create_vterm(term_T *term, int rows, int cols)
     VTerm          *vterm;
     VTermScreen            *screen;
     VTermValue     value;
+    VTermColor     *fg, *bg;
+    int                    fgval, bgval;
 
     vterm = vterm_new(rows, cols);
     term->tl_vterm = vterm;
@@ -2357,14 +2362,23 @@ create_vterm(term_T *term, int rows, int cols)
 
     /* Vterm uses a default black background.  Set it to white when
      * 'background' is "light". */
+    vim_memset(&term->tl_default_color.attrs, 0, sizeof(VTermScreenCellAttrs));
+    term->tl_default_color.width = 1;
+    fg = &term->tl_default_color.fg;
+    bg = &term->tl_default_color.bg;
     if (*p_bg == 'l')
     {
-       VTermColor      fg, bg;
-
-       fg.red = fg.green = fg.blue = 0;
-       bg.red = bg.green = bg.blue = 255;
-       vterm_state_set_default_colors(vterm_obtain_state(vterm), &fg, &bg);
+       fgval = 0;
+       bgval = 255;
+    }
+    else
+    {
+       fgval = 255;
+       bgval = 0;
     }
+    fg->red = fg->green = fg->blue = fgval;
+    bg->red = bg->green = bg->blue = bgval;
+    vterm_state_set_default_colors(vterm_obtain_state(vterm), fg, bg);
 
     /* Required to initialize most things. */
     vterm_screen_reset(screen, 1 /* hard */);
index c970b57d8451876315bbc9dcfadf060669924f08..08d86006e36b5301359bf5f665ad8cf22e464dc6 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1096,
 /**/
     1095,
 /**/