From 1fb2c98b392b44f8a9ad3512608c92e1dad9c7af Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 5 Aug 2018 19:32:11 -0400 Subject: Fix color pairs once and for all 8/16 color setup adapted from chat/ui.c. termcap patch hack no longer required. Black on black and bright black now work. Nothing will appear bold anymore on 256-color terminals. The keys for black have definitely always been in the help. You just didn't notice. --- client.c | 65 ++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 26 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index d46649b..7af6950 100644 --- a/client.c +++ b/client.c @@ -71,18 +71,31 @@ static void clientMap(void) { clientMessage(msg); } -static chtype colorAttrs(uint8_t color) { - uint8_t bright = color & COLOR_BRIGHT; - uint8_t fg = color & 0x07; - uint8_t bg = color & 0x70; - return COLOR_PAIR(bg >> 1 | fg) | (bright ? A_BOLD : 0); +static void colorPairs(void) { + assume_default_colors(0, 0); + if (COLORS >= 16) { + for (short pair = 1; pair < 0x80; ++pair) { + init_pair(pair, pair & 0x0F, (pair & 0xF0) >> 4); + } + } else { + for (short pair = 1; pair < 0100; ++pair) { + init_pair(pair, pair & 007, (pair & 070) >> 3); + } + } +} + +static chtype colorAttr(uint8_t color) { + if (COLORS >= 16) return COLOR_PAIR(color); + chtype bold = (color & COLOR_BRIGHT) ? A_BOLD : A_NORMAL; + short pair = (color & 0x70) >> 1 | (color & 0x07); + return bold | COLOR_PAIR(pair); } -static uint8_t attrsColor(chtype attrs) { - chtype bright = attrs & A_BOLD; - short fg = PAIR_NUMBER(attrs) & 007; - short bg = PAIR_NUMBER(attrs) & 070; - return bg << 1 | fg | (bright ? COLOR_BRIGHT : 0); +static uint8_t attrColor(chtype attr) { + if (COLORS >= 16) return PAIR_NUMBER(attr); + uint8_t bright = (attr & A_BOLD) ? COLOR_BRIGHT : 0; + short pair = PAIR_NUMBER(attr); + return (pair & 070) << 1 | bright | (pair & 007); } static struct { @@ -129,13 +142,13 @@ static void insertMode(int8_t dx, int8_t dy) { } static void swapCell(int8_t dx, int8_t dy) { - uint8_t aColor = attrsColor(inch()); + uint8_t aColor = attrColor(inch()); char aCell = inch() & A_CHARTEXT; int sy, sx; getyx(stdscr, sy, sx); move(sy + dy, sx + dx); - uint8_t bColor = attrsColor(inch()); + uint8_t bColor = attrColor(inch()); char bCell = inch() & A_CHARTEXT; move(sy, sx); @@ -164,7 +177,7 @@ static void inputNormal(int c) { break; case 'r': input.mode = MODE_REPLACE; break; case 'p': input.mode = MODE_PUT; break; case 'R': input.mode = MODE_DRAW; input.draw = 0; - break; case 'x': clientPut(attrsColor(inch()), ' '); + break; case 'x': clientPut(attrColor(inch()), ' '); break; case '~': { clientPut(input.color, inch() & A_CHARTEXT); @@ -192,7 +205,7 @@ static void inputNormal(int c) { break; case 'B': swapCell(-1, 1); break; case 'N': swapCell( 1, 1); - break; case '`': input.color = attrsColor(inch()); + break; case '`': input.color = attrColor(inch()); break; case '0': colorFg(COLOR_BLACK); break; case '1': colorFg(COLOR_RED); @@ -260,7 +273,7 @@ static void inputInsert(int c) { } static void inputReplace(int c) { - if (isprint(c)) clientPut(attrsColor(inch()), c); + if (isprint(c)) clientPut(attrColor(inch()), c); input.mode = MODE_NORMAL; } @@ -294,7 +307,7 @@ static void readInput(void) { } static void serverPut(uint8_t x, uint8_t y, uint8_t color, char cell) { - mvaddch(y, x, colorAttrs(color) | cell); + mvaddch(y, x, colorAttr(color) | cell); } static void serverTile(void) { @@ -370,15 +383,15 @@ static void serverMap(void) { time *= ARRAY_LEN(MAP_COLORS) - 1; char cell = MAP_CELLS[(int)round(count)]; - chtype attrs = colorAttrs(MAP_COLORS[(int)round(time)]); + chtype attr = colorAttr(MAP_COLORS[(int)round(time)]); if (y == MAP_ROWS / 2 && x == MAP_COLS / 2) { - attrs |= A_REVERSE; + attr |= A_REVERSE; } wmove(mapWindow, y, 3 * x); - waddch(mapWindow, attrs | cell); - waddch(mapWindow, attrs | cell); - waddch(mapWindow, attrs | cell); + waddch(mapWindow, attr | cell); + waddch(mapWindow, attr | cell); + waddch(mapWindow, attr | cell); } } @@ -456,11 +469,7 @@ static void curse(void) { ); exit(EX_CONFIG); } - for (int bg = COLOR_BLACK; bg < COLOR_BRIGHT; ++bg) { - for (int fg = COLOR_BLACK; fg < COLOR_BRIGHT; ++fg) { - init_pair(PAIR_NUMBER(colorAttrs(bg << 4 | fg)), fg, bg); - } - } + colorPairs(); if (LINES < CELL_ROWS || COLS < CELL_COLS) { endwin(); @@ -468,6 +477,8 @@ static void curse(void) { fprintf(stderr, "It needs to be at least 80x25 characters.\n"); exit(EX_CONFIG); } + + attrset(colorAttr(COLOR_WHITE)); if (LINES > CELL_ROWS) { mvhline(CELL_ROWS, 0, 0, CELL_COLS); } @@ -477,6 +488,7 @@ static void curse(void) { if (LINES > CELL_ROWS && COLS > CELL_COLS) { mvaddch(CELL_ROWS, CELL_COLS, ACS_LRCORNER); } + attrset(A_NORMAL); mapFrame = newwin( MAP_ROWS + 2, @@ -490,6 +502,7 @@ static void curse(void) { CELL_INIT_Y - MAP_ROWS / 2, CELL_INIT_X - 3 * MAP_COLS / 2 ); + wattrset(mapFrame, colorAttr(COLOR_WHITE)); box(mapFrame, 0, 0); } -- cgit 1.4.1 -0400'>2021-09-21Rewrite pngo, add explicit optionsJune McEnroe 2021-09-16Fix /* **/ comment matchingJune McEnroe 2021-09-15Remove typer, add downgrade to READMEJune McEnroe 2021-09-15Set bot mode on downgradeJune McEnroe 2021-09-15Enter capsicum in downgradeJune McEnroe 2021-09-15Factor out common parts of downgrade messagesJune McEnroe 2021-09-14Add downgrade IRC botJune McEnroe 2021-09-14Sort by title if authors matchJune McEnroe 2021-09-13Swap-remove tags as they're foundJune McEnroe 2021-09-12Replace htagml regex with strncmpJune McEnroe 2021-09-11Also defer printing comment for lone close-parensJune McEnroe 2021-09-10Publish "git-comment"June McEnroe 2021-09-10Add git comment --pretty optionJune McEnroe 2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe 2021-09-08Up default min-repeat to 30 linesJune McEnroe 2021-09-08Handle dirty lines in git-commentJune McEnroe 2021-09-08Document and install git-commentJune McEnroe 2021-09-08Add repeat and all options to git-commentJune McEnroe 2021-09-08Add group threshold to git-commentJune McEnroe