Skip to content

Commit 28c6e2f

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 4ded3ab + 46359e1 commit 28c6e2f

4 files changed

Lines changed: 83 additions & 105 deletions

File tree

src/libvterm/include/vterm.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,16 @@ INLINE void vterm_rect_move(VTermRect *rect, int row_delta, int col_delta)
7979
}
8080
#endif
8181

82+
/* The ansi_index is used for the lower 16 colors, which can be set to any
83+
* color. */
84+
#define VTERM_ANSI_INDEX_DEFAULT 0 /* color cleared */
85+
#define VTERM_ANSI_INDEX_MIN 1
86+
#define VTERM_ANSI_INDEX_MAX 16
87+
#define VTERM_ANSI_INDEX_NONE 255 /* non-ANSI color, use red/green/blue */
88+
8289
typedef struct {
8390
uint8_t red, green, blue;
91+
uint8_t ansi_index;
8492
} VTermColor;
8593

8694
typedef enum {

src/libvterm/src/pen.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
#include <stdio.h>
44

55
static const VTermColor ansi_colors[] = {
6-
/* R G B */
7-
{ 0, 0, 0 }, /* black */
8-
{ 224, 0, 0 }, /* red */
9-
{ 0, 224, 0 }, /* green */
10-
{ 224, 224, 0 }, /* yellow */
11-
{ 0, 0, 224 }, /* blue */
12-
{ 224, 0, 224 }, /* magenta */
13-
{ 0, 224, 224 }, /* cyan */
14-
{ 224, 224, 224 }, /* white == light grey */
6+
/* R G B index */
7+
{ 0, 0, 0, 1 }, /* black */
8+
{ 224, 0, 0, 2 }, /* red */
9+
{ 0, 224, 0, 3 }, /* green */
10+
{ 224, 224, 0, 4 }, /* yellow */
11+
{ 0, 0, 224, 5 }, /* blue */
12+
{ 224, 0, 224, 6 }, /* magenta */
13+
{ 0, 224, 224, 7 }, /* cyan */
14+
{ 224, 224, 224, 8 }, /* white == light grey */
1515

1616
/* high intensity */
17-
{ 128, 128, 128 }, /* black */
18-
{ 255, 64, 64 }, /* red */
19-
{ 64, 255, 64 }, /* green */
20-
{ 255, 255, 64 }, /* yellow */
21-
{ 64, 64, 255 }, /* blue */
22-
{ 255, 64, 255 }, /* magenta */
23-
{ 64, 255, 255 }, /* cyan */
24-
{ 255, 255, 255 }, /* white for real */
17+
{ 128, 128, 128, 9 }, /* black */
18+
{ 255, 64, 64, 10 }, /* red */
19+
{ 64, 255, 64, 11 }, /* green */
20+
{ 255, 255, 64, 12 }, /* yellow */
21+
{ 64, 64, 255, 13 }, /* blue */
22+
{ 255, 64, 255, 14 }, /* magenta */
23+
{ 64, 255, 255, 15 }, /* cyan */
24+
{ 255, 255, 255, 16 }, /* white for real */
2525
};
2626

2727
static int ramp6[] = {
@@ -57,6 +57,7 @@ static int lookup_colour_palette(const VTermState *state, long index, VTermColor
5757
col->blue = ramp6[index % 6];
5858
col->green = ramp6[index/6 % 6];
5959
col->red = ramp6[index/6/6 % 6];
60+
col->ansi_index = VTERM_ANSI_INDEX_NONE;
6061

6162
return TRUE;
6263
}
@@ -67,6 +68,7 @@ static int lookup_colour_palette(const VTermState *state, long index, VTermColor
6768
col->blue = ramp24[index];
6869
col->green = ramp24[index];
6970
col->red = ramp24[index];
71+
col->ansi_index = VTERM_ANSI_INDEX_NONE;
7072

7173
return TRUE;
7274
}
@@ -84,6 +86,7 @@ static int lookup_colour(const VTermState *state, int palette, const long args[]
8486
col->red = (uint8_t)CSI_ARG(args[0]);
8587
col->green = (uint8_t)CSI_ARG(args[1]);
8688
col->blue = (uint8_t)CSI_ARG(args[2]);
89+
col->ansi_index = VTERM_ANSI_INDEX_NONE;
8790

8891
return 3;
8992

@@ -152,7 +155,9 @@ INTERNAL void vterm_state_newpen(VTermState *state)
152155

153156
/* 90% grey so that pure white is brighter */
154157
state->default_fg.red = state->default_fg.green = state->default_fg.blue = 240;
158+
state->default_fg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
155159
state->default_bg.red = state->default_bg.green = state->default_bg.blue = 0;
160+
state->default_bg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
156161

157162
for(col = 0; col < 16; col++)
158163
state->colors[col] = ansi_colors[col];
@@ -208,13 +213,18 @@ void vterm_state_get_palette_color(const VTermState *state, int index, VTermColo
208213
void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg)
209214
{
210215
state->default_fg = *default_fg;
216+
state->default_fg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
211217
state->default_bg = *default_bg;
218+
state->default_bg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
212219
}
213220

214221
void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col)
215222
{
216223
if(index >= 0 && index < 16)
224+
{
217225
state->colors[index] = *col;
226+
state->colors[index].ansi_index = index + VTERM_ANSI_INDEX_MIN;
227+
}
218228
}
219229

220230
void vterm_state_set_bold_highbright(VTermState *state, int bold_is_highbright)

src/terminal.c

Lines changed: 46 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
* in tl_scrollback are no longer used.
3939
*
4040
* 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.
4143
* - in GUI vertical split causes problems. Cursor is flickering. (Hirohito
4244
* Higashi, 2017 Sep 19)
4345
* - Shift-Tab does not work.
@@ -48,7 +50,6 @@
4850
* - When closing gvim with an active terminal buffer, the dialog suggests
4951
* saving the buffer. Should say something else. (Manas Thakur, #2215)
5052
* Also: #2223
51-
* - implement term_setsize()
5253
* - Termdebug does not work when Vim build with mzscheme. gdb hangs.
5354
* - MS-Windows GUI: WinBar has tearoff item
5455
* - Adding WinBar to terminal window doesn't display, text isn't shifted down.
@@ -57,6 +58,7 @@
5758
* - What to store in a session file? Shell at the prompt would be OK to
5859
* restore, but others may not. Open the window and let the user start the
5960
* command?
61+
* - implement term_setsize()
6062
* - add test for giving error for invalid 'termsize' value.
6163
* - support minimal size when 'termsize' is "rows*cols".
6264
* - support minimal size when 'termsize' is empty?
@@ -1712,7 +1714,7 @@ may_toggle_cursor(term_T *term)
17121714

17131715
/*
17141716
* Reverse engineer the RGB value into a cterm color index.
1715-
* First color is 1. Return 0 if no match found.
1717+
* First color is 1. Return 0 if no match found (default color).
17161718
*/
17171719
static int
17181720
color2index(VTermColor *color, int fg, int *boldp)
@@ -1721,78 +1723,34 @@ color2index(VTermColor *color, int fg, int *boldp)
17211723
int blue = color->blue;
17221724
int green = color->green;
17231725

1724-
/* The argument for lookup_color() is for the color_names[] table. */
1725-
if (red == 0)
1726+
if (color->ansi_index != VTERM_ANSI_INDEX_NONE)
17261727
{
1727-
if (green == 0)
1728-
{
1729-
if (blue == 0)
1730-
return lookup_color(0, fg, boldp) + 1; /* black */
1731-
if (blue == 224)
1732-
return lookup_color(1, fg, boldp) + 1; /* dark blue */
1733-
}
1734-
else if (green == 224)
1728+
/* First 16 colors and default: use the ANSI index, because these
1729+
* colors can be redefined. */
1730+
if (t_colors >= 16)
1731+
return color->ansi_index;
1732+
switch (color->ansi_index)
17351733
{
1736-
if (blue == 0)
1737-
return lookup_color(2, fg, boldp) + 1; /* dark green */
1738-
if (blue == 224)
1739-
return lookup_color(3, fg, boldp) + 1; /* dark cyan */
1740-
}
1741-
}
1742-
else if (red == 224)
1743-
{
1744-
if (green == 0)
1745-
{
1746-
if (blue == 0)
1747-
return lookup_color(4, fg, boldp) + 1; /* dark red */
1748-
if (blue == 224)
1749-
return lookup_color(5, fg, boldp) + 1; /* dark magenta */
1750-
}
1751-
else if (green == 224)
1752-
{
1753-
if (blue == 0)
1754-
return lookup_color(6, fg, boldp) + 1; /* dark yellow / brown */
1755-
if (blue == 224)
1756-
return lookup_color(8, fg, boldp) + 1; /* white / light grey */
1757-
}
1758-
}
1759-
else if (red == 128)
1760-
{
1761-
if (green == 128 && blue == 128)
1762-
return lookup_color(12, fg, boldp) + 1; /* dark grey */
1763-
}
1764-
else if (red == 255)
1765-
{
1766-
if (green == 64)
1767-
{
1768-
if (blue == 64)
1769-
return lookup_color(20, fg, boldp) + 1; /* light red */
1770-
if (blue == 255)
1771-
return lookup_color(22, fg, boldp) + 1; /* light magenta */
1772-
}
1773-
else if (green == 255)
1774-
{
1775-
if (blue == 64)
1776-
return lookup_color(24, fg, boldp) + 1; /* yellow */
1777-
if (blue == 255)
1778-
return lookup_color(26, fg, boldp) + 1; /* white */
1779-
}
1780-
}
1781-
else if (red == 64)
1782-
{
1783-
if (green == 64)
1784-
{
1785-
if (blue == 255)
1786-
return lookup_color(14, fg, boldp) + 1; /* light blue */
1787-
}
1788-
else if (green == 255)
1789-
{
1790-
if (blue == 64)
1791-
return lookup_color(16, fg, boldp) + 1; /* light green */
1792-
if (blue == 255)
1793-
return lookup_color(18, fg, boldp) + 1; /* light cyan */
1734+
case 0: return 0;
1735+
case 1: return lookup_color( 0, fg, boldp) + 1;
1736+
case 2: return lookup_color( 4, fg, boldp) + 1; /* dark red */
1737+
case 3: return lookup_color( 2, fg, boldp) + 1; /* dark green */
1738+
case 4: return lookup_color( 6, fg, boldp) + 1; /* brown */
1739+
case 5: return lookup_color( 1, fg, boldp) + 1; /* dark blue*/
1740+
case 6: return lookup_color( 5, fg, boldp) + 1; /* dark magenta */
1741+
case 7: return lookup_color( 3, fg, boldp) + 1; /* dark cyan */
1742+
case 8: return lookup_color( 8, fg, boldp) + 1; /* light grey */
1743+
case 9: return lookup_color(12, fg, boldp) + 1; /* dark grey */
1744+
case 10: return lookup_color(20, fg, boldp) + 1; /* red */
1745+
case 11: return lookup_color(16, fg, boldp) + 1; /* green */
1746+
case 12: return lookup_color(24, fg, boldp) + 1; /* yellow */
1747+
case 13: return lookup_color(14, fg, boldp) + 1; /* blue */
1748+
case 14: return lookup_color(22, fg, boldp) + 1; /* magenta */
1749+
case 15: return lookup_color(18, fg, boldp) + 1; /* cyan */
1750+
case 16: return lookup_color(26, fg, boldp) + 1; /* white */
17941751
}
17951752
}
1753+
17961754
if (t_colors >= 256)
17971755
{
17981756
if (red == blue && red == green)
@@ -2452,23 +2410,23 @@ term_get_attr(buf_T *buf, linenr_T lnum, int col)
24522410
}
24532411

24542412
static VTermColor ansi_table[16] = {
2455-
{ 0, 0, 0}, /* black */
2456-
{224, 0, 0}, /* dark red */
2457-
{ 0, 224, 0}, /* dark green */
2458-
{224, 224, 0}, /* dark yellow / brown */
2459-
{ 0, 0, 224}, /* dark blue */
2460-
{224, 0, 224}, /* dark magenta */
2461-
{ 0, 224, 224}, /* dark cyan */
2462-
{224, 224, 224}, /* light grey */
2463-
2464-
{128, 128, 128}, /* dark grey */
2465-
{255, 64, 64}, /* light red */
2466-
{ 64, 255, 64}, /* light green */
2467-
{255, 255, 64}, /* yellow */
2468-
{ 64, 64, 255}, /* light blue */
2469-
{255, 64, 255}, /* light magenta */
2470-
{ 64, 255, 255}, /* light cyan */
2471-
{255, 255, 255}, /* white */
2413+
{ 0, 0, 0, 1}, /* black */
2414+
{224, 0, 0, 2}, /* dark red */
2415+
{ 0, 224, 0, 3}, /* dark green */
2416+
{224, 224, 0, 4}, /* dark yellow / brown */
2417+
{ 0, 0, 224, 5}, /* dark blue */
2418+
{224, 0, 224, 6}, /* dark magenta */
2419+
{ 0, 224, 224, 7}, /* dark cyan */
2420+
{224, 224, 224, 8}, /* light grey */
2421+
2422+
{128, 128, 128, 9}, /* dark grey */
2423+
{255, 64, 64, 10}, /* light red */
2424+
{ 64, 255, 64, 11}, /* light green */
2425+
{255, 255, 64, 12}, /* yellow */
2426+
{ 64, 64, 255, 13}, /* light blue */
2427+
{255, 64, 255, 14}, /* light magenta */
2428+
{ 64, 255, 255, 15}, /* light cyan */
2429+
{255, 255, 255, 16}, /* white */
24722430
};
24732431

24742432
static int cube_value[] = {
@@ -2554,7 +2512,7 @@ create_vterm(term_T *term, int rows, int cols)
25542512
/* The "Terminal" highlight group overrules the defaults. */
25552513
id = syn_name2id((char_u *)"Terminal");
25562514

2557-
/* Use the actual color for the GUI and when 'guitermcolors' is set. */
2515+
/* Use the actual color for the GUI and when 'termguicolors' is set. */
25582516
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
25592517
if (0
25602518
# ifdef FEAT_GUI

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,8 @@ static char *(features[]) =
786786

787787
static int included_patches[] =
788788
{ /* Add new patch number below this line */
789+
/**/
790+
1359,
789791
/**/
790792
1358,
791793
/**/

0 commit comments

Comments
 (0)