Add IRCDefault to colors enum

weechat-hashes
Curtis McEnroe 2018-09-13 15:17:41 -04:00
parent 311795bf41
commit 9a69869d39
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
3 changed files with 12 additions and 11 deletions

5
chat.h
View File

@ -56,7 +56,7 @@ const struct Tag TagVerbose;
struct Tag tagFind(const char *name); struct Tag tagFind(const char *name);
struct Tag tagFor(const char *name); struct Tag tagFor(const char *name);
enum { enum IRCColor {
IRCWhite, IRCWhite,
IRCBlack, IRCBlack,
IRCBlue, IRCBlue,
@ -73,6 +73,7 @@ enum {
IRCPink, IRCPink,
IRCGray, IRCGray,
IRCLightGray, IRCLightGray,
IRCDefault = 99,
}; };
enum { enum {
IRCBold = 002, IRCBold = 002,
@ -88,7 +89,7 @@ struct Format {
size_t len; size_t len;
bool split; bool split;
bool bold, italic, underline, reverse; bool bold, italic, underline, reverse;
int fg, bg; enum IRCColor fg, bg;
}; };
void formatReset(struct Format *format); void formatReset(struct Format *format);
bool formatParse(struct Format *format, const wchar_t *split); bool formatParse(struct Format *format, const wchar_t *split);

View File

@ -25,15 +25,15 @@ void formatReset(struct Format *format) {
format->italic = false; format->italic = false;
format->underline = false; format->underline = false;
format->reverse = false; format->reverse = false;
format->fg = -1; format->fg = IRCDefault;
format->bg = -1; format->bg = IRCDefault;
} }
static void parseColor(struct Format *format) { static void parseColor(struct Format *format) {
size_t len = MIN(wcsspn(format->str, L"0123456789"), 2); size_t len = MIN(wcsspn(format->str, L"0123456789"), 2);
if (!len) { if (!len) {
format->fg = -1; format->fg = IRCDefault;
format->bg = -1; format->bg = IRCDefault;
return; return;
} }
format->fg = 0; format->fg = 0;
@ -41,7 +41,7 @@ static void parseColor(struct Format *format) {
format->fg *= 10; format->fg *= 10;
format->fg += format->str[i] - L'0'; format->fg += format->str[i] - L'0';
} }
if (format->fg > IRCLightGray) format->fg = -1; if (format->fg > IRCLightGray) format->fg = IRCDefault;
format->str = &format->str[len]; format->str = &format->str[len];
len = 0; len = 0;
@ -54,7 +54,7 @@ static void parseColor(struct Format *format) {
format->bg *= 10; format->bg *= 10;
format->bg += format->str[1 + i] - L'0'; format->bg += format->str[1 + i] - L'0';
} }
if (format->bg > IRCLightGray) format->bg = -1; if (format->bg > IRCLightGray) format->bg = IRCDefault;
format->str = &format->str[1 + len]; format->str = &format->str[1 + len];
} }

6
ui.c
View File

@ -160,7 +160,7 @@ void uiDraw(void) {
doupdate(); doupdate();
} }
static const short IRCColors[] = { static const short Colors[] = {
[IRCWhite] = 8 + COLOR_WHITE, [IRCWhite] = 8 + COLOR_WHITE,
[IRCBlack] = 0 + COLOR_BLACK, [IRCBlack] = 0 + COLOR_BLACK,
[IRCBlue] = 0 + COLOR_BLUE, [IRCBlue] = 0 + COLOR_BLUE,
@ -187,8 +187,8 @@ static void addFormat(WINDOW *win, const struct Format *format) {
if (format->reverse) attr |= A_REVERSE; if (format->reverse) attr |= A_REVERSE;
short pair = -1; short pair = -1;
if (format->fg >= 0) pair = IRCColors[format->fg]; if (format->fg != IRCDefault) pair = Colors[format->fg];
if (format->bg >= 0) pair |= IRCColors[format->bg] << 4; if (format->bg != IRCDefault) pair |= Colors[format->bg] << 4;
wattr_set(win, attr | attr8(pair), 1 + pair8(pair), NULL); wattr_set(win, attr | attr8(pair), 1 + pair8(pair), NULL);
waddnwstr(win, format->str, format->len); waddnwstr(win, format->str, format->len);