diff src/terminal.c @ 11822:1e237c5994fc v8.0.0791

patch 8.0.0791: terminal colors depend on the system commit https://github.com/vim/vim/commit/b41bf8e6b45a773456031954bca1bc4212cbffbe Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 28 15:11:38 2017 +0200 patch 8.0.0791: terminal colors depend on the system Problem: Terminal colors depend on the system. Solution: Use the highlight color lookup tables.
author Christian Brabandt <cb@256bit.org>
date Fri, 28 Jul 2017 15:15:04 +0200
parents 0f9780ee4207
children 0cfe4a07c2ad
line wrap: on
line diff
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -33,6 +33,7 @@
  * while, if the terminal window is visible, the screen contents is drawn.
  *
  * TODO:
+ * - if 'term' starts witth "xterm" use it for $TERM.
  * - To set BS correctly, check get_stty(); Pass the fd of the pty.
  * - include functions from #1871
  * - do not store terminal buffer in viminfo.  Or prefix term:// ?
@@ -755,27 +756,28 @@ static VTermScreenCallbacks screen_callb
  * First color is 1.  Return 0 if no match found.
  */
     static int
-color2index(VTermColor *color)
+color2index(VTermColor *color, int foreground)
 {
     int red = color->red;
     int blue = color->blue;
     int green = color->green;
 
+    /* The argument for lookup_color() is for the color_names[] table. */
     if (red == 0)
     {
 	if (green == 0)
 	{
 	    if (blue == 0)
-		return 1; /* black */
+		return lookup_color(0, foreground) + 1; /* black */
 	    if (blue == 224)
-		return 5; /* blue */
+		return lookup_color(1, foreground) + 1; /* dark blue */
 	}
 	else if (green == 224)
 	{
 	    if (blue == 0)
-		return 3; /* green */
+		return lookup_color(2, foreground) + 1; /* dark green */
 	    if (blue == 224)
-		return 7; /* cyan */
+		return lookup_color(3, foreground) + 1; /* dark cyan */
 	}
     }
     else if (red == 224)
@@ -783,38 +785,38 @@ color2index(VTermColor *color)
 	if (green == 0)
 	{
 	    if (blue == 0)
-		return 2; /* red */
+		return lookup_color(4, foreground) + 1; /* dark red */
 	    if (blue == 224)
-		return 6; /* magenta */
+		return lookup_color(5, foreground) + 1; /* dark magenta */
 	}
 	else if (green == 224)
 	{
 	    if (blue == 0)
-		return 4; /* yellow */
+		return lookup_color(6, foreground) + 1; /* dark yellow / brown */
 	    if (blue == 224)
-		return 8; /* white */
+		return lookup_color(8, foreground) + 1; /* white / light grey */
 	}
     }
     else if (red == 128)
     {
 	if (green == 128 && blue == 128)
-	    return 9; /* high intensity black */
+	    return lookup_color(12, foreground) + 1; /* high intensity black / dark grey */
     }
     else if (red == 255)
     {
 	if (green == 64)
 	{
 	    if (blue == 64)
-		return 10;  /* high intensity red */
+		return lookup_color(20, foreground) + 1;  /* light red */
 	    if (blue == 255)
-		return 14;  /* high intensity magenta */
+		return lookup_color(22, foreground) + 1;  /* light magenta */
 	}
 	else if (green == 255)
 	{
 	    if (blue == 64)
-		return 12;  /* high intensity yellow */
+		return lookup_color(24, foreground) + 1;  /* yellow */
 	    if (blue == 255)
-		return 16;  /* high intensity white */
+		return lookup_color(26, foreground) + 1;  /* white */
 	}
     }
     else if (red == 64)
@@ -822,14 +824,14 @@ color2index(VTermColor *color)
 	if (green == 64)
 	{
 	    if (blue == 255)
-		return 13;  /* high intensity blue */
+		return lookup_color(14, foreground) + 1;  /* light blue */
 	}
 	else if (green == 255)
 	{
 	    if (blue == 64)
-		return 11;  /* high intensity green */
+		return lookup_color(16, foreground) + 1;  /* light green */
 	    if (blue == 255)
-		return 15;  /* high intensity cyan */
+		return lookup_color(18, foreground) + 1;  /* light cyan */
 	}
     }
     if (t_colors >= 256)
@@ -902,8 +904,8 @@ cell2attr(VTermScreenCell *cell)
     else
 #endif
     {
-	return get_cterm_attr_idx(attr, color2index(&cell->fg),
-						       color2index(&cell->bg));
+	return get_cterm_attr_idx(attr, color2index(&cell->fg, TRUE),
+						color2index(&cell->bg, FALSE));
     }
     return 0;
 }