Support all 99 IRC colors
Corresponding ANSI colors from the table on ircdocs.weechat-hashes
parent
8e55c049b5
commit
218bfbac32
73
ui.c
73
ui.c
|
@ -133,11 +133,11 @@ static void colorInit(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static attr_t colorAttr(short fg) {
|
static attr_t colorAttr(short fg) {
|
||||||
return (fg >= COLORS ? A_BOLD : A_NORMAL);
|
return (fg >= COLORS && fg < 16 ? A_BOLD : A_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static short colorPair(short fg, short bg) {
|
static short colorPair(short fg, short bg) {
|
||||||
if (bg == -1) return 1 + fg;
|
if (bg == -1 && fg < 16) return 1 + fg;
|
||||||
fg %= COLORS;
|
fg %= COLORS;
|
||||||
bg %= COLORS;
|
bg %= COLORS;
|
||||||
for (short pair = 17; pair < colorPairs; ++pair) {
|
for (short pair = 17; pair < colorPairs; ++pair) {
|
||||||
|
@ -286,27 +286,32 @@ struct Style {
|
||||||
};
|
};
|
||||||
static const struct Style Reset = { A_NORMAL, Default, Default };
|
static const struct Style Reset = { A_NORMAL, Default, Default };
|
||||||
|
|
||||||
static short mapColor(enum Color color) {
|
static const short Colors[100] = {
|
||||||
switch (color) {
|
[Default] = -1,
|
||||||
break; case White: return 8 + COLOR_WHITE;
|
[White] = 8 + COLOR_WHITE,
|
||||||
break; case Black: return 0 + COLOR_BLACK;
|
[Black] = 0 + COLOR_BLACK,
|
||||||
break; case Blue: return 0 + COLOR_BLUE;
|
[Blue] = 0 + COLOR_BLUE,
|
||||||
break; case Green: return 0 + COLOR_GREEN;
|
[Green] = 0 + COLOR_GREEN,
|
||||||
break; case Red: return 8 + COLOR_RED;
|
[Red] = 8 + COLOR_RED,
|
||||||
break; case Brown: return 0 + COLOR_RED;
|
[Brown] = 0 + COLOR_RED,
|
||||||
break; case Magenta: return 0 + COLOR_MAGENTA;
|
[Magenta] = 0 + COLOR_MAGENTA,
|
||||||
break; case Orange: return 0 + COLOR_YELLOW;
|
[Orange] = 0 + COLOR_YELLOW,
|
||||||
break; case Yellow: return 8 + COLOR_YELLOW;
|
[Yellow] = 8 + COLOR_YELLOW,
|
||||||
break; case LightGreen: return 8 + COLOR_GREEN;
|
[LightGreen] = 8 + COLOR_GREEN,
|
||||||
break; case Cyan: return 0 + COLOR_CYAN;
|
[Cyan] = 0 + COLOR_CYAN,
|
||||||
break; case LightCyan: return 8 + COLOR_CYAN;
|
[LightCyan] = 8 + COLOR_CYAN,
|
||||||
break; case LightBlue: return 8 + COLOR_BLUE;
|
[LightBlue] = 8 + COLOR_BLUE,
|
||||||
break; case Pink: return 8 + COLOR_MAGENTA;
|
[Pink] = 8 + COLOR_MAGENTA,
|
||||||
break; case Gray: return 8 + COLOR_BLACK;
|
[Gray] = 8 + COLOR_BLACK,
|
||||||
break; case LightGray: return 0 + COLOR_WHITE;
|
[LightGray] = 0 + COLOR_WHITE,
|
||||||
break; default: return -1;
|
52, 94, 100, 58, 22, 29, 23, 24, 17, 54, 53, 89,
|
||||||
}
|
88, 130, 142, 64, 28, 35, 30, 25, 18, 91, 90, 125,
|
||||||
}
|
124, 166, 184, 106, 34, 49, 37, 33, 19, 129, 127, 161,
|
||||||
|
196, 208, 226, 154, 46, 86, 51, 75, 21, 171, 201, 198,
|
||||||
|
203, 215, 227, 191, 83, 122, 87, 111, 63, 177, 207, 205,
|
||||||
|
217, 223, 229, 193, 157, 158, 159, 153, 147, 183, 219, 212,
|
||||||
|
16, 233, 235, 237, 239, 241, 244, 247, 250, 254, 231,
|
||||||
|
};
|
||||||
|
|
||||||
enum { B = '\2', C = '\3', O = '\17', R = '\26', I = '\35', U = '\37' };
|
enum { B = '\2', C = '\3', O = '\17', R = '\26', I = '\35', U = '\37' };
|
||||||
|
|
||||||
|
@ -342,8 +347,8 @@ static void statusAdd(const char *str) {
|
||||||
styleParse(&style, &str, &len);
|
styleParse(&style, &str, &len);
|
||||||
wattr_set(
|
wattr_set(
|
||||||
status,
|
status,
|
||||||
style.attr | colorAttr(mapColor(style.fg)),
|
style.attr | colorAttr(Colors[style.fg]),
|
||||||
colorPair(mapColor(style.fg), mapColor(style.bg)),
|
colorPair(Colors[style.fg], Colors[style.bg]),
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
waddnstr(status, str, len);
|
waddnstr(status, str, len);
|
||||||
|
@ -471,8 +476,8 @@ static int wordWrap(WINDOW *win, const char *str) {
|
||||||
|
|
||||||
wattr_set(
|
wattr_set(
|
||||||
win,
|
win,
|
||||||
style.attr | colorAttr(mapColor(style.fg)),
|
style.attr | colorAttr(Colors[style.fg]),
|
||||||
colorPair(mapColor(style.fg), mapColor(style.bg)),
|
colorPair(Colors[style.fg], Colors[style.bg]),
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
waddnstr(win, str, len);
|
waddnstr(win, str, len);
|
||||||
|
@ -555,7 +560,7 @@ static void bufferList(struct Buffer *buffer) {
|
||||||
if (!tm) continue;
|
if (!tm) continue;
|
||||||
char buf[sizeof("[00:00:00]")];
|
char buf[sizeof("[00:00:00]")];
|
||||||
strftime(buf, sizeof(buf), "[%T]", tm);
|
strftime(buf, sizeof(buf), "[%T]", tm);
|
||||||
vid_attr(colorAttr(mapColor(Gray)), colorPair(mapColor(Gray), -1), NULL);
|
vid_attr(colorAttr(Colors[Gray]), colorPair(Colors[Gray], -1), NULL);
|
||||||
printf("%s\t", buf);
|
printf("%s\t", buf);
|
||||||
|
|
||||||
size_t len;
|
size_t len;
|
||||||
|
@ -563,8 +568,8 @@ static void bufferList(struct Buffer *buffer) {
|
||||||
while (*line) {
|
while (*line) {
|
||||||
styleParse(&style, &line, &len);
|
styleParse(&style, &line, &len);
|
||||||
vid_attr(
|
vid_attr(
|
||||||
style.attr | colorAttr(mapColor(style.fg)),
|
style.attr | colorAttr(Colors[style.fg]),
|
||||||
colorPair(mapColor(style.fg), mapColor(style.bg)),
|
colorPair(Colors[style.fg], Colors[style.bg]),
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
if (len) printf("%.*s", (int)len, line);
|
if (len) printf("%.*s", (int)len, line);
|
||||||
|
@ -591,8 +596,8 @@ static void inputAdd(struct Style *style, const char *str) {
|
||||||
if (str - code > 1) waddnstr(input, &code[1], str - &code[1]);
|
if (str - code > 1) waddnstr(input, &code[1], str - &code[1]);
|
||||||
wattr_set(
|
wattr_set(
|
||||||
input,
|
input,
|
||||||
style->attr | colorAttr(mapColor(style->fg)),
|
style->attr | colorAttr(Colors[style->fg]),
|
||||||
colorPair(mapColor(style->fg), mapColor(style->bg)),
|
colorPair(Colors[style->fg], Colors[style->bg]),
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
waddnstr(input, str, len);
|
waddnstr(input, str, len);
|
||||||
|
@ -636,8 +641,8 @@ static void inputUpdate(void) {
|
||||||
wmove(input, 0, 0);
|
wmove(input, 0, 0);
|
||||||
wattr_set(
|
wattr_set(
|
||||||
input,
|
input,
|
||||||
init.attr | colorAttr(mapColor(init.fg)),
|
init.attr | colorAttr(Colors[init.fg]),
|
||||||
colorPair(mapColor(init.fg), mapColor(init.bg)),
|
colorPair(Colors[init.fg], Colors[init.bg]),
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
waddstr(input, prefix);
|
waddstr(input, prefix);
|
||||||
|
|
Loading…
Reference in New Issue