Mercurial > vim
comparison src/terminal.c @ 12966:c5bccd50100e v8.0.1359
patch 8.0.1359: libvterm ANSI colors can not always be recognized
commit https://github.com/vim/vim/commit/46359e198f6d6884dc3d3c4a3e46625f1b2a2ad2
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Nov 29 22:33:38 2017 +0100
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Problem: Libvterm ANSI colors can not always be recognized from the RGB
values. The default color is wrong when t_RB is empty.
Solution: Add the ANSI color index to VTermColor.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 29 Nov 2017 22:45:05 +0100 |
parents | 32531a3eab1f |
children | a9f6a874b64f |
comparison
equal
deleted
inserted
replaced
12965:24c73ddf8b38 | 12966:c5bccd50100e |
---|---|
36 * that buffer, attributes come from the scrollback buffer tl_scrollback. | 36 * that buffer, attributes come from the scrollback buffer tl_scrollback. |
37 * When the buffer is changed it is turned into a normal buffer, the attributes | 37 * When the buffer is changed it is turned into a normal buffer, the attributes |
38 * in tl_scrollback are no longer used. | 38 * in tl_scrollback are no longer used. |
39 * | 39 * |
40 * TODO: | 40 * TODO: |
41 * - When using 'termguicolors' still use the 16 ANSI colors as-is. Helps for | |
42 * a job that uses 16 colors while Vim is using > 256. | |
41 * - in GUI vertical split causes problems. Cursor is flickering. (Hirohito | 43 * - in GUI vertical split causes problems. Cursor is flickering. (Hirohito |
42 * Higashi, 2017 Sep 19) | 44 * Higashi, 2017 Sep 19) |
43 * - Shift-Tab does not work. | 45 * - Shift-Tab does not work. |
44 * - after resizing windows overlap. (Boris Staletic, #2164) | 46 * - after resizing windows overlap. (Boris Staletic, #2164) |
45 * - Redirecting output does not work on MS-Windows, Test_terminal_redir_file() | 47 * - Redirecting output does not work on MS-Windows, Test_terminal_redir_file() |
46 * is disabled. | 48 * is disabled. |
47 * - cursor blinks in terminal on widows with a timer. (xtal8, #2142) | 49 * - cursor blinks in terminal on widows with a timer. (xtal8, #2142) |
48 * - When closing gvim with an active terminal buffer, the dialog suggests | 50 * - When closing gvim with an active terminal buffer, the dialog suggests |
49 * saving the buffer. Should say something else. (Manas Thakur, #2215) | 51 * saving the buffer. Should say something else. (Manas Thakur, #2215) |
50 * Also: #2223 | 52 * Also: #2223 |
51 * - implement term_setsize() | |
52 * - Termdebug does not work when Vim build with mzscheme. gdb hangs. | 53 * - Termdebug does not work when Vim build with mzscheme. gdb hangs. |
53 * - MS-Windows GUI: WinBar has tearoff item | 54 * - MS-Windows GUI: WinBar has tearoff item |
54 * - Adding WinBar to terminal window doesn't display, text isn't shifted down. | 55 * - Adding WinBar to terminal window doesn't display, text isn't shifted down. |
55 * - MS-Windows GUI: still need to type a key after shell exits? #1924 | 56 * - MS-Windows GUI: still need to type a key after shell exits? #1924 |
56 * - After executing a shell command the status line isn't redraw. | 57 * - After executing a shell command the status line isn't redraw. |
57 * - What to store in a session file? Shell at the prompt would be OK to | 58 * - What to store in a session file? Shell at the prompt would be OK to |
58 * restore, but others may not. Open the window and let the user start the | 59 * restore, but others may not. Open the window and let the user start the |
59 * command? | 60 * command? |
61 * - implement term_setsize() | |
60 * - add test for giving error for invalid 'termsize' value. | 62 * - add test for giving error for invalid 'termsize' value. |
61 * - support minimal size when 'termsize' is "rows*cols". | 63 * - support minimal size when 'termsize' is "rows*cols". |
62 * - support minimal size when 'termsize' is empty? | 64 * - support minimal size when 'termsize' is empty? |
63 * - GUI: when using tabs, focus in terminal, click on tab does not work. | 65 * - GUI: when using tabs, focus in terminal, click on tab does not work. |
64 * - GUI: when 'confirm' is set and trying to exit Vim, dialog offers to save | 66 * - GUI: when 'confirm' is set and trying to exit Vim, dialog offers to save |
1705 } | 1707 } |
1706 } | 1708 } |
1707 | 1709 |
1708 /* | 1710 /* |
1709 * Reverse engineer the RGB value into a cterm color index. | 1711 * Reverse engineer the RGB value into a cterm color index. |
1710 * First color is 1. Return 0 if no match found. | 1712 * First color is 1. Return 0 if no match found (default color). |
1711 */ | 1713 */ |
1712 static int | 1714 static int |
1713 color2index(VTermColor *color, int fg, int *boldp) | 1715 color2index(VTermColor *color, int fg, int *boldp) |
1714 { | 1716 { |
1715 int red = color->red; | 1717 int red = color->red; |
1716 int blue = color->blue; | 1718 int blue = color->blue; |
1717 int green = color->green; | 1719 int green = color->green; |
1718 | 1720 |
1719 /* The argument for lookup_color() is for the color_names[] table. */ | 1721 if (color->ansi_index != VTERM_ANSI_INDEX_NONE) |
1720 if (red == 0) | 1722 { |
1721 { | 1723 /* First 16 colors and default: use the ANSI index, because these |
1722 if (green == 0) | 1724 * colors can be redefined. */ |
1723 { | 1725 if (t_colors >= 16) |
1724 if (blue == 0) | 1726 return color->ansi_index; |
1725 return lookup_color(0, fg, boldp) + 1; /* black */ | 1727 switch (color->ansi_index) |
1726 if (blue == 224) | 1728 { |
1727 return lookup_color(1, fg, boldp) + 1; /* dark blue */ | 1729 case 0: return 0; |
1728 } | 1730 case 1: return lookup_color( 0, fg, boldp) + 1; |
1729 else if (green == 224) | 1731 case 2: return lookup_color( 4, fg, boldp) + 1; /* dark red */ |
1730 { | 1732 case 3: return lookup_color( 2, fg, boldp) + 1; /* dark green */ |
1731 if (blue == 0) | 1733 case 4: return lookup_color( 6, fg, boldp) + 1; /* brown */ |
1732 return lookup_color(2, fg, boldp) + 1; /* dark green */ | 1734 case 5: return lookup_color( 1, fg, boldp) + 1; /* dark blue*/ |
1733 if (blue == 224) | 1735 case 6: return lookup_color( 5, fg, boldp) + 1; /* dark magenta */ |
1734 return lookup_color(3, fg, boldp) + 1; /* dark cyan */ | 1736 case 7: return lookup_color( 3, fg, boldp) + 1; /* dark cyan */ |
1735 } | 1737 case 8: return lookup_color( 8, fg, boldp) + 1; /* light grey */ |
1736 } | 1738 case 9: return lookup_color(12, fg, boldp) + 1; /* dark grey */ |
1737 else if (red == 224) | 1739 case 10: return lookup_color(20, fg, boldp) + 1; /* red */ |
1738 { | 1740 case 11: return lookup_color(16, fg, boldp) + 1; /* green */ |
1739 if (green == 0) | 1741 case 12: return lookup_color(24, fg, boldp) + 1; /* yellow */ |
1740 { | 1742 case 13: return lookup_color(14, fg, boldp) + 1; /* blue */ |
1741 if (blue == 0) | 1743 case 14: return lookup_color(22, fg, boldp) + 1; /* magenta */ |
1742 return lookup_color(4, fg, boldp) + 1; /* dark red */ | 1744 case 15: return lookup_color(18, fg, boldp) + 1; /* cyan */ |
1743 if (blue == 224) | 1745 case 16: return lookup_color(26, fg, boldp) + 1; /* white */ |
1744 return lookup_color(5, fg, boldp) + 1; /* dark magenta */ | 1746 } |
1745 } | 1747 } |
1746 else if (green == 224) | 1748 |
1747 { | |
1748 if (blue == 0) | |
1749 return lookup_color(6, fg, boldp) + 1; /* dark yellow / brown */ | |
1750 if (blue == 224) | |
1751 return lookup_color(8, fg, boldp) + 1; /* white / light grey */ | |
1752 } | |
1753 } | |
1754 else if (red == 128) | |
1755 { | |
1756 if (green == 128 && blue == 128) | |
1757 return lookup_color(12, fg, boldp) + 1; /* dark grey */ | |
1758 } | |
1759 else if (red == 255) | |
1760 { | |
1761 if (green == 64) | |
1762 { | |
1763 if (blue == 64) | |
1764 return lookup_color(20, fg, boldp) + 1; /* light red */ | |
1765 if (blue == 255) | |
1766 return lookup_color(22, fg, boldp) + 1; /* light magenta */ | |
1767 } | |
1768 else if (green == 255) | |
1769 { | |
1770 if (blue == 64) | |
1771 return lookup_color(24, fg, boldp) + 1; /* yellow */ | |
1772 if (blue == 255) | |
1773 return lookup_color(26, fg, boldp) + 1; /* white */ | |
1774 } | |
1775 } | |
1776 else if (red == 64) | |
1777 { | |
1778 if (green == 64) | |
1779 { | |
1780 if (blue == 255) | |
1781 return lookup_color(14, fg, boldp) + 1; /* light blue */ | |
1782 } | |
1783 else if (green == 255) | |
1784 { | |
1785 if (blue == 64) | |
1786 return lookup_color(16, fg, boldp) + 1; /* light green */ | |
1787 if (blue == 255) | |
1788 return lookup_color(18, fg, boldp) + 1; /* light cyan */ | |
1789 } | |
1790 } | |
1791 if (t_colors >= 256) | 1749 if (t_colors >= 256) |
1792 { | 1750 { |
1793 if (red == blue && red == green) | 1751 if (red == blue && red == green) |
1794 { | 1752 { |
1795 /* 24-color greyscale plus white and black */ | 1753 /* 24-color greyscale plus white and black */ |
2445 } | 2403 } |
2446 return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg); | 2404 return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg); |
2447 } | 2405 } |
2448 | 2406 |
2449 static VTermColor ansi_table[16] = { | 2407 static VTermColor ansi_table[16] = { |
2450 { 0, 0, 0}, /* black */ | 2408 { 0, 0, 0, 1}, /* black */ |
2451 {224, 0, 0}, /* dark red */ | 2409 {224, 0, 0, 2}, /* dark red */ |
2452 { 0, 224, 0}, /* dark green */ | 2410 { 0, 224, 0, 3}, /* dark green */ |
2453 {224, 224, 0}, /* dark yellow / brown */ | 2411 {224, 224, 0, 4}, /* dark yellow / brown */ |
2454 { 0, 0, 224}, /* dark blue */ | 2412 { 0, 0, 224, 5}, /* dark blue */ |
2455 {224, 0, 224}, /* dark magenta */ | 2413 {224, 0, 224, 6}, /* dark magenta */ |
2456 { 0, 224, 224}, /* dark cyan */ | 2414 { 0, 224, 224, 7}, /* dark cyan */ |
2457 {224, 224, 224}, /* light grey */ | 2415 {224, 224, 224, 8}, /* light grey */ |
2458 | 2416 |
2459 {128, 128, 128}, /* dark grey */ | 2417 {128, 128, 128, 9}, /* dark grey */ |
2460 {255, 64, 64}, /* light red */ | 2418 {255, 64, 64, 10}, /* light red */ |
2461 { 64, 255, 64}, /* light green */ | 2419 { 64, 255, 64, 11}, /* light green */ |
2462 {255, 255, 64}, /* yellow */ | 2420 {255, 255, 64, 12}, /* yellow */ |
2463 { 64, 64, 255}, /* light blue */ | 2421 { 64, 64, 255, 13}, /* light blue */ |
2464 {255, 64, 255}, /* light magenta */ | 2422 {255, 64, 255, 14}, /* light magenta */ |
2465 { 64, 255, 255}, /* light cyan */ | 2423 { 64, 255, 255, 15}, /* light cyan */ |
2466 {255, 255, 255}, /* white */ | 2424 {255, 255, 255, 16}, /* white */ |
2467 }; | 2425 }; |
2468 | 2426 |
2469 static int cube_value[] = { | 2427 static int cube_value[] = { |
2470 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF | 2428 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF |
2471 }; | 2429 }; |
2547 bg->red = bg->green = bg->blue = bgval; | 2505 bg->red = bg->green = bg->blue = bgval; |
2548 | 2506 |
2549 /* The "Terminal" highlight group overrules the defaults. */ | 2507 /* The "Terminal" highlight group overrules the defaults. */ |
2550 id = syn_name2id((char_u *)"Terminal"); | 2508 id = syn_name2id((char_u *)"Terminal"); |
2551 | 2509 |
2552 /* Use the actual color for the GUI and when 'guitermcolors' is set. */ | 2510 /* Use the actual color for the GUI and when 'termguicolors' is set. */ |
2553 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) | 2511 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
2554 if (0 | 2512 if (0 |
2555 # ifdef FEAT_GUI | 2513 # ifdef FEAT_GUI |
2556 || gui.in_use | 2514 || gui.in_use |
2557 # endif | 2515 # endif |