Patch 8.0.0791
Problem:    Terminal colors depend on the system.
Solution:   Use the highlight color lookup tables.
Files:      src/syntax.c, src/proto/syntax.pro, src/terminal.c


*** ../vim-8.0.0790/src/syntax.c        2017-07-23 18:07:51.050808235 +0200
--- src/syntax.c        2017-07-28 15:03:13.091153967 +0200
***************
*** 7221,7226 ****
--- 7221,7336 ----
      return retval;
  }
  
+ static char *(color_names[28]) = {
+           "Black", "DarkBlue", "DarkGreen", "DarkCyan",
+           "DarkRed", "DarkMagenta", "Brown", "DarkYellow",
+           "Gray", "Grey", "LightGray", "LightGrey",
+           "DarkGray", "DarkGrey",
+           "Blue", "LightBlue", "Green", "LightGreen",
+           "Cyan", "LightCyan", "Red", "LightRed", "Magenta",
+           "LightMagenta", "Yellow", "LightYellow", "White", "NONE"};
+           /* indices:
+            * 0, 1, 2, 3,
+            * 4, 5, 6, 7,
+            * 8, 9, 10, 11,
+            * 12, 13,
+            * 14, 15, 16, 17,
+            * 18, 19, 20, 21, 22,
+            * 23, 24, 25, 26, 27 */
+ static int color_numbers_16[28] = {0, 1, 2, 3,
+                                4, 5, 6, 6,
+                                7, 7, 7, 7,
+                                8, 8,
+                                9, 9, 10, 10,
+                                11, 11, 12, 12, 13,
+                                13, 14, 14, 15, -1};
+ /* for xterm with 88 colors... */
+ static int color_numbers_88[28] = {0, 4, 2, 6,
+                                1, 5, 32, 72,
+                                84, 84, 7, 7,
+                                82, 82,
+                                12, 43, 10, 61,
+                                14, 63, 9, 74, 13,
+                                75, 11, 78, 15, -1};
+ /* for xterm with 256 colors... */
+ static int color_numbers_256[28] = {0, 4, 2, 6,
+                                1, 5, 130, 130,
+                                248, 248, 7, 7,
+                                242, 242,
+                                12, 81, 10, 121,
+                                14, 159, 9, 224, 13,
+                                225, 11, 229, 15, -1};
+ /* for terminals with less than 16 colors... */
+ static int color_numbers_8[28] = {0, 4, 2, 6,
+                                1, 5, 3, 3,
+                                7, 7, 7, 7,
+                                0+8, 0+8,
+                                4+8, 4+8, 2+8, 2+8,
+                                6+8, 6+8, 1+8, 1+8, 5+8,
+                                5+8, 3+8, 3+8, 7+8, -1};
+ 
+ /*
+  * Lookup the "cterm" value to be used for color with index "idx" in
+  * color_names[].
+  */
+     int
+ lookup_color(int idx, int foreground)
+ {
+     int               color = color_numbers_16[idx];
+     char_u    *p;
+ 
+     /* Use the _16 table to check if it's a valid color name. */
+     if (color < 0)
+       return -1;
+ 
+     if (t_colors == 8)
+     {
+       /* t_Co is 8: use the 8 colors table */
+ #if defined(__QNXNTO__)
+       color = color_numbers_8_qansi[idx];
+ #else
+       color = color_numbers_8[idx];
+ #endif
+       if (foreground)
+       {
+           /* set/reset bold attribute to get light foreground
+            * colors (on some terminals, e.g. "linux") */
+           if (color & 8)
+           {
+               HL_TABLE()[idx].sg_cterm |= HL_BOLD;
+               HL_TABLE()[idx].sg_cterm_bold = TRUE;
+           }
+           else
+               HL_TABLE()[idx].sg_cterm &= ~HL_BOLD;
+       }
+       color &= 7;     /* truncate to 8 colors */
+     }
+     else if (t_colors == 16 || t_colors == 88
+                                          || t_colors >= 256)
+     {
+       /*
+        * Guess: if the termcap entry ends in 'm', it is
+        * probably an xterm-like terminal.  Use the changed
+        * order for colors.
+        */
+       if (*T_CAF != NUL)
+           p = T_CAF;
+       else
+           p = T_CSF;
+       if (*p != NUL && (t_colors > 256
+                             || *(p + STRLEN(p) - 1) == 'm'))
+       {
+           if (t_colors == 88)
+               color = color_numbers_88[idx];
+           else if (t_colors >= 256)
+               color = color_numbers_256[idx];
+           else
+               color = color_numbers_8[idx];
+       }
+     }
+     return color;
+ }
+ 
  /*
   * Handle the ":highlight .." command.
   * When using ":hi clear" this is called recursively for each group with
***************
*** 7723,7767 ****
            }
            else
            {
-               static char *(color_names[28]) = {
-                           "Black", "DarkBlue", "DarkGreen", "DarkCyan",
-                           "DarkRed", "DarkMagenta", "Brown", "DarkYellow",
-                           "Gray", "Grey",
-                           "LightGray", "LightGrey", "DarkGray", "DarkGrey",
-                           "Blue", "LightBlue", "Green", "LightGreen",
-                           "Cyan", "LightCyan", "Red", "LightRed", "Magenta",
-                           "LightMagenta", "Yellow", "LightYellow", "White", 
"NONE"};
-               static int color_numbers_16[28] = {0, 1, 2, 3,
-                                                4, 5, 6, 6,
-                                                7, 7,
-                                                7, 7, 8, 8,
-                                                9, 9, 10, 10,
-                                                11, 11, 12, 12, 13,
-                                                13, 14, 14, 15, -1};
-               /* for xterm with 88 colors... */
-               static int color_numbers_88[28] = {0, 4, 2, 6,
-                                                1, 5, 32, 72,
-                                                84, 84,
-                                                7, 7, 82, 82,
-                                                12, 43, 10, 61,
-                                                14, 63, 9, 74, 13,
-                                                75, 11, 78, 15, -1};
-               /* for xterm with 256 colors... */
-               static int color_numbers_256[28] = {0, 4, 2, 6,
-                                                1, 5, 130, 130,
-                                                248, 248,
-                                                7, 7, 242, 242,
-                                                12, 81, 10, 121,
-                                                14, 159, 9, 224, 13,
-                                                225, 11, 229, 15, -1};
-               /* for terminals with less than 16 colors... */
-               static int color_numbers_8[28] = {0, 4, 2, 6,
-                                                1, 5, 3, 3,
-                                                7, 7,
-                                                7, 7, 0+8, 0+8,
-                                                4+8, 4+8, 2+8, 2+8,
-                                                6+8, 6+8, 1+8, 1+8, 5+8,
-                                                5+8, 3+8, 3+8, 7+8, -1};
  #if defined(__QNXNTO__)
                static int *color_numbers_8_qansi = color_numbers_8;
                /* On qnx, the 8 & 16 color arrays are the same */
--- 7833,7838 ----
***************
*** 7782,7838 ****
                    break;
                }
  
!               /* Use the _16 table to check if it's a valid color name. */
!               color = color_numbers_16[i];
!               if (color >= 0)
!               {
!                   if (t_colors == 8)
!                   {
!                       /* t_Co is 8: use the 8 colors table */
! #if defined(__QNXNTO__)
!                       color = color_numbers_8_qansi[i];
! #else
!                       color = color_numbers_8[i];
! #endif
!                       if (key[5] == 'F')
!                       {
!                           /* set/reset bold attribute to get light foreground
!                            * colors (on some terminals, e.g. "linux") */
!                           if (color & 8)
!                           {
!                               HL_TABLE()[idx].sg_cterm |= HL_BOLD;
!                               HL_TABLE()[idx].sg_cterm_bold = TRUE;
!                           }
!                           else
!                               HL_TABLE()[idx].sg_cterm &= ~HL_BOLD;
!                       }
!                       color &= 7;     /* truncate to 8 colors */
!                   }
!                   else if (t_colors == 16 || t_colors == 88
!                                                          || t_colors >= 256)
!                   {
!                       /*
!                        * Guess: if the termcap entry ends in 'm', it is
!                        * probably an xterm-like terminal.  Use the changed
!                        * order for colors.
!                        */
!                       if (*T_CAF != NUL)
!                           p = T_CAF;
!                       else
!                           p = T_CSF;
!                       if (*p != NUL && (t_colors > 256
!                                             || *(p + STRLEN(p) - 1) == 'm'))
!                       {
!                           if (t_colors == 88)
!                               color = color_numbers_88[i];
!                           else if (t_colors >= 256)
!                               color = color_numbers_256[i];
!                           else
!                               color = color_numbers_8[i];
!                       }
!                   }
!               }
            }
            /* Add one to the argument, to avoid zero.  Zero is used for
             * "NONE", then "color" is -1. */
            if (key[5] == 'F')
--- 7853,7861 ----
                    break;
                }
  
!               color = lookup_color(i, key[5] == 'F');
            }
+ 
            /* Add one to the argument, to avoid zero.  Zero is used for
             * "NONE", then "color" is -1. */
            if (key[5] == 'F')
*** ../vim-8.0.0790/src/proto/syntax.pro        2017-07-23 18:07:51.050808235 
+0200
--- src/proto/syntax.pro        2017-07-28 15:02:33.679438256 +0200
***************
*** 23,28 ****
--- 23,29 ----
  char_u *get_syntime_arg(expand_T *xp, int idx);
  void init_highlight(int both, int reset);
  int load_colors(char_u *name);
+ int lookup_color(int idx, int foreground);
  void do_highlight(char_u *line, int forceit, int init);
  void free_highlight(void);
  void restore_cterm_colors(void);
*** ../vim-8.0.0790/src/terminal.c      2017-07-28 14:17:30.678540959 +0200
--- src/terminal.c      2017-07-28 15:10:40.955921276 +0200
***************
*** 33,38 ****
--- 33,39 ----
   * 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,781 ****
   * First color is 1.  Return 0 if no match found.
   */
      static int
! color2index(VTermColor *color)
  {
      int red = color->red;
      int blue = color->blue;
      int green = color->green;
  
      if (red == 0)
      {
        if (green == 0)
        {
            if (blue == 0)
!               return 1; /* black */
            if (blue == 224)
!               return 5; /* blue */
        }
        else if (green == 224)
        {
            if (blue == 0)
!               return 3; /* green */
            if (blue == 224)
!               return 7; /* cyan */
        }
      }
      else if (red == 224)
--- 756,783 ----
   * First color is 1.  Return 0 if no match found.
   */
      static int
! 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 lookup_color(0, foreground) + 1; /* black */
            if (blue == 224)
!               return lookup_color(1, foreground) + 1; /* dark blue */
        }
        else if (green == 224)
        {
            if (blue == 0)
!               return lookup_color(2, foreground) + 1; /* dark green */
            if (blue == 224)
!               return lookup_color(3, foreground) + 1; /* dark cyan */
        }
      }
      else if (red == 224)
***************
*** 783,820 ****
        if (green == 0)
        {
            if (blue == 0)
!               return 2; /* red */
            if (blue == 224)
!               return 6; /* magenta */
        }
        else if (green == 224)
        {
            if (blue == 0)
!               return 4; /* yellow */
            if (blue == 224)
!               return 8; /* white */
        }
      }
      else if (red == 128)
      {
        if (green == 128 && blue == 128)
!           return 9; /* high intensity black */
      }
      else if (red == 255)
      {
        if (green == 64)
        {
            if (blue == 64)
!               return 10;  /* high intensity red */
            if (blue == 255)
!               return 14;  /* high intensity magenta */
        }
        else if (green == 255)
        {
            if (blue == 64)
!               return 12;  /* high intensity yellow */
            if (blue == 255)
!               return 16;  /* high intensity white */
        }
      }
      else if (red == 64)
--- 785,822 ----
        if (green == 0)
        {
            if (blue == 0)
!               return lookup_color(4, foreground) + 1; /* dark red */
            if (blue == 224)
!               return lookup_color(5, foreground) + 1; /* dark magenta */
        }
        else if (green == 224)
        {
            if (blue == 0)
!               return lookup_color(6, foreground) + 1; /* dark yellow / brown 
*/
            if (blue == 224)
!               return lookup_color(8, foreground) + 1; /* white / light grey */
        }
      }
      else if (red == 128)
      {
        if (green == 128 && blue == 128)
!           return lookup_color(12, foreground) + 1; /* high intensity black / 
dark grey */
      }
      else if (red == 255)
      {
        if (green == 64)
        {
            if (blue == 64)
!               return lookup_color(20, foreground) + 1;  /* light red */
            if (blue == 255)
!               return lookup_color(22, foreground) + 1;  /* light magenta */
        }
        else if (green == 255)
        {
            if (blue == 64)
!               return lookup_color(24, foreground) + 1;  /* yellow */
            if (blue == 255)
!               return lookup_color(26, foreground) + 1;  /* white */
        }
      }
      else if (red == 64)
***************
*** 822,835 ****
        if (green == 64)
        {
            if (blue == 255)
!               return 13;  /* high intensity blue */
        }
        else if (green == 255)
        {
            if (blue == 64)
!               return 11;  /* high intensity green */
            if (blue == 255)
!               return 15;  /* high intensity cyan */
        }
      }
      if (t_colors >= 256)
--- 824,837 ----
        if (green == 64)
        {
            if (blue == 255)
!               return lookup_color(14, foreground) + 1;  /* light blue */
        }
        else if (green == 255)
        {
            if (blue == 64)
!               return lookup_color(16, foreground) + 1;  /* light green */
            if (blue == 255)
!               return lookup_color(18, foreground) + 1;  /* light cyan */
        }
      }
      if (t_colors >= 256)
***************
*** 902,909 ****
      else
  #endif
      {
!       return get_cterm_attr_idx(attr, color2index(&cell->fg),
!                                                      color2index(&cell->bg));
      }
      return 0;
  }
--- 904,911 ----
      else
  #endif
      {
!       return get_cterm_attr_idx(attr, color2index(&cell->fg, TRUE),
!                                               color2index(&cell->bg, FALSE));
      }
      return 0;
  }
*** ../vim-8.0.0790/src/version.c       2017-07-28 14:19:15.901799595 +0200
--- src/version.c       2017-07-28 14:40:58.768653381 +0200
***************
*** 771,772 ****
--- 771,774 ----
  {   /* Add new patch number below this line */
+ /**/
+     791,
  /**/

-- 
       He was not in the least bit scared to be mashed into a pulp
       Or to have his eyes gouged out and his elbows broken;
       To have his kneecaps split and his body burned away
       And his limbs all hacked and mangled, brave Sir Robin.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui