forked from aniani/vim
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Problem: Cannot use 24 bit colors in MS-Windows console.
Solution: Add support for vcon. (Nobuhiro Takasaki, Ken Takasaki,
fixes #1270, fixes #2060)
This commit is contained in:
153
src/term.c
153
src/term.c
@@ -76,7 +76,6 @@ struct builtin_term
|
||||
|
||||
static struct builtin_term *find_builtin_term(char_u *name);
|
||||
static void parse_builtin_tcap(char_u *s);
|
||||
static void term_color(char_u *s, int n);
|
||||
static void gather_termleader(void);
|
||||
#ifdef FEAT_TERMRESPONSE
|
||||
static void req_codes_from_term(void);
|
||||
@@ -600,6 +599,10 @@ static struct builtin_term builtin_termcaps[] =
|
||||
# else
|
||||
{(int)KS_CS, "\033|%i%d;%dr"},/* scroll region */
|
||||
# endif
|
||||
# ifdef FEAT_TERMGUICOLORS
|
||||
{(int)KS_8F, "\033|38;2;%lu;%lu;%lum"},
|
||||
{(int)KS_8B, "\033|48;2;%lu;%lu;%lum"},
|
||||
# endif
|
||||
|
||||
{K_UP, "\316H"},
|
||||
{K_DOWN, "\316P"},
|
||||
@@ -2007,6 +2010,11 @@ set_termname(char_u *term)
|
||||
may_req_termresponse();
|
||||
#endif
|
||||
|
||||
#if defined(WIN3264) && !defined(FEAT_GUI) && defined(FEAT_TERMGUICOLORS)
|
||||
if (STRCMP(term, "win32") == 0)
|
||||
set_color_count((p_tgc) ? 256 : 16);
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -2818,31 +2826,12 @@ term_set_winsize(int height, int width)
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
term_fg_color(int n)
|
||||
{
|
||||
/* Use "AF" termcap entry if present, "Sf" entry otherwise */
|
||||
if (*T_CAF)
|
||||
term_color(T_CAF, n);
|
||||
else if (*T_CSF)
|
||||
term_color(T_CSF, n);
|
||||
}
|
||||
|
||||
void
|
||||
term_bg_color(int n)
|
||||
{
|
||||
/* Use "AB" termcap entry if present, "Sb" entry otherwise */
|
||||
if (*T_CAB)
|
||||
term_color(T_CAB, n);
|
||||
else if (*T_CSB)
|
||||
term_color(T_CSB, n);
|
||||
}
|
||||
|
||||
static void
|
||||
term_color(char_u *s, int n)
|
||||
{
|
||||
char buf[20];
|
||||
int i = 2; /* index in s[] just after <Esc>[ or CSI */
|
||||
int i = *s == CSI ? 1 : 2;
|
||||
/* index in s[] just after <Esc>[ or CSI */
|
||||
|
||||
/* Special handling of 16 colors, because termcap can't handle it */
|
||||
/* Also accept "\e[3%dm" for TERMINFO, it is sometimes used */
|
||||
@@ -2869,6 +2858,26 @@ term_color(char_u *s, int n)
|
||||
OUT_STR(tgoto((char *)s, 0, n));
|
||||
}
|
||||
|
||||
void
|
||||
term_fg_color(int n)
|
||||
{
|
||||
/* Use "AF" termcap entry if present, "Sf" entry otherwise */
|
||||
if (*T_CAF)
|
||||
term_color(T_CAF, n);
|
||||
else if (*T_CSF)
|
||||
term_color(T_CSF, n);
|
||||
}
|
||||
|
||||
void
|
||||
term_bg_color(int n)
|
||||
{
|
||||
/* Use "AB" termcap entry if present, "Sb" entry otherwise */
|
||||
if (*T_CAB)
|
||||
term_color(T_CAB, n);
|
||||
else if (*T_CSB)
|
||||
term_color(T_CSB, n);
|
||||
}
|
||||
|
||||
#if defined(FEAT_TERMGUICOLORS) || defined(PROTO)
|
||||
|
||||
#define RED(rgb) (((long_u)(rgb) >> 16) & 0xFF)
|
||||
@@ -6614,6 +6623,106 @@ update_tcap(int attr)
|
||||
++p;
|
||||
}
|
||||
}
|
||||
|
||||
struct ks_tbl_s
|
||||
{
|
||||
int code; /* value of KS_ */
|
||||
char *vtp; /* code in vtp mode */
|
||||
char *buf; /* buffer in non-vtp mode */
|
||||
char *vbuf; /* buffer in vtp mode */
|
||||
};
|
||||
|
||||
static struct ks_tbl_s ks_tbl[] =
|
||||
{
|
||||
{(int)KS_ME, "\033|0m" }, /* normal */
|
||||
{(int)KS_MR, "\033|7m" }, /* reverse */
|
||||
{(int)KS_MD, "\033|1m" }, /* bold */
|
||||
{(int)KS_SO, "\033|91m"}, /* standout: bright red text */
|
||||
{(int)KS_SE, "\033|39m"}, /* standout end: default color */
|
||||
{(int)KS_CZH, "\033|95m"}, /* italic: bright magenta text */
|
||||
{(int)KS_CZR, "\033|0m",}, /* italic end */
|
||||
{(int)KS_US, "\033|4m",}, /* underscore */
|
||||
{(int)KS_UE, "\033|24m"}, /* underscore end */
|
||||
{(int)KS_NAME, NULL}
|
||||
};
|
||||
|
||||
static struct builtin_term *
|
||||
find_first_tcap(
|
||||
char_u *name,
|
||||
int code)
|
||||
{
|
||||
struct builtin_term *p;
|
||||
|
||||
p = find_builtin_term(name);
|
||||
while (p->bt_string != NULL)
|
||||
{
|
||||
if (p->bt_entry == code)
|
||||
return p;
|
||||
p++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* For Win32 console: replace the sequence immediately after termguicolors.
|
||||
*/
|
||||
void
|
||||
swap_tcap(void)
|
||||
{
|
||||
# ifdef FEAT_TERMGUICOLORS
|
||||
static int init = 0;
|
||||
static int last_tgc;
|
||||
struct ks_tbl_s *ks;
|
||||
struct builtin_term *bt;
|
||||
|
||||
/* buffer initialization */
|
||||
if (init == 0)
|
||||
{
|
||||
ks = ks_tbl;
|
||||
while (ks->vtp != NULL)
|
||||
{
|
||||
bt = find_first_tcap(DEFAULT_TERM, ks->code);
|
||||
ks->buf = bt->bt_string;
|
||||
ks->vbuf = ks->vtp;
|
||||
ks++;
|
||||
}
|
||||
init++;
|
||||
last_tgc = p_tgc;
|
||||
return;
|
||||
}
|
||||
|
||||
if (last_tgc != p_tgc)
|
||||
{
|
||||
if (p_tgc)
|
||||
{
|
||||
/* switch to special character sequence */
|
||||
ks = ks_tbl;
|
||||
while (ks->vtp != NULL)
|
||||
{
|
||||
bt = find_first_tcap(DEFAULT_TERM, ks->code);
|
||||
ks->buf = bt->bt_string;
|
||||
bt->bt_string = ks->vbuf;
|
||||
ks++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* switch to index color */
|
||||
ks = ks_tbl;
|
||||
while (ks->vtp != NULL)
|
||||
{
|
||||
bt = find_first_tcap(DEFAULT_TERM, ks->code);
|
||||
ks->vbuf = bt->bt_string;
|
||||
bt->bt_string = ks->buf;
|
||||
ks++;
|
||||
}
|
||||
}
|
||||
|
||||
last_tgc = p_tgc;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO)
|
||||
|
||||
Reference in New Issue
Block a user