From: sbkelley Date: Fri, 19 Jun 2026 14:59:15 +0000 (-0400) Subject: user term default fg/bg now accessible as fg or bg color with -1 X-Git-Tag: 1.6.1-roc-2606C^2~2 X-Git-Url: https://skyeroc.xyz/gitweb/?a=commitdiff_plain;h=90e8d728a23ad21796c72a1d41f2c9cc518fc89d;p=dgamelaunch user term default fg/bg now accessible as fg or bg color with -1 * Improve explanatory comment * Flatten another if statement * Add default-color pairs (129-152) * Refactor remap_attr_string * Make default colors more accessible * Stop trying to overwrite color 0 * let remap_attr_string() read negative numbers * parse negative numbers to return default-pairs * Stop reducing screen height by 3 for banners --- diff --git a/dgamelaunch.c b/dgamelaunch.c index bb81e21..4e03e9b 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -614,7 +614,7 @@ loadbanner (char *fname, struct dg_banner *ban) { memset (buf, 0, DGL_BANNER_LINELEN); - if (ban->len >= win.ws_row - 3) + if (ban->len >= win.ws_row) break; } @@ -624,64 +624,77 @@ loadbanner (char *fname, struct dg_banner *ban) { int remap_attr_string(char *s) { int attr = 0; - if (s && *s) + if ( !(s && *s) ) { - switch (*s) - { - default: - break; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - { - char *num_delimiter; - int num; - int other_num; + attr = A_NORMAL; + return attr; + } + switch (*s) + { + default: + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case '-': + { + char *num_delimiter; + int num; + int other_num; + int offset = 1; - if ((num_delimiter = strchr(s, ','))) - { - *num_delimiter = '\0'; - num = atoi(s); - s = num_delimiter + 1; - other_num = atoi(s); + if ((num_delimiter = strchr(s, ','))) + { + *num_delimiter = '\0'; + num_delimiter++; + other_num = atoi(num_delimiter); + } + num = atoi(s); - if (other_num >= 0 && other_num <= 7) - { - // If there's a valid background color, set that, overriding whatever - // came from the first number (but leaving the foreground in place) - num &= 15; - num |= other_num << 4; - } + if (other_num < 0 && num >= 0) + { + other_num = 0; + offset += 129; + } + else if (num < 0 && other_num >= 0) + { + num = other_num; + other_num = 0; + offset += 145; + } + else if (num < 0 && other_num < 0) + { + num = 0; + other_num = 0; + offset = 0; + } - } - else // no ',' delimiter - num = atoi(s); + num &= 15; + other_num &= 7; + num |= other_num << 4; - if (num >= -1 && num <= 128) - attr |= COLOR_PAIR(num+1); - } + if ((num + offset) >= 0 && (num + offset) <= 151) + attr |= COLOR_PAIR(num+offset); + } + break; + case 'b': + attr |= A_BOLD; + break; + case 's': + attr |= A_STANDOUT; + break; + case 'u': + attr |= A_UNDERLINE; + break; + case 'r': + attr |= A_REVERSE; + break; + case 'd': + attr |= A_DIM; + break; + case 'f': + attr |= A_BLINK; break; - case 'b': - attr |= A_BOLD; - break; - case 's': - attr |= A_STANDOUT; - break; - case 'u': - attr |= A_UNDERLINE; - break; - case 'r': - attr |= A_REVERSE; - break; - case 'd': - attr |= A_DIM; - break; - case 'f': - attr |= A_BLINK; - break; - } } - else - attr = A_NORMAL; return attr; } @@ -1926,9 +1939,10 @@ initcurses () start_color(); use_default_colors(); - init_pair(0, COLOR_WHITE, COLOR_BLACK); - init_pair(129, -1, -1); - /* color_pair_idx(0, 0) = 1; color_pair_idx(15, 7) = 128*/ + /* default = 0; + color_pair_idx(0, 0) = 1; + color_pair_idx(15, 7) = 128; + */ for (i = 0; i <= 15; i++) { for (j = 0; j <= 7; j++) @@ -1936,6 +1950,16 @@ initcurses () init_pair(color_pair_idx(i, j), i, j); } } + // fg on default bg = 129-144 + for (i = 0; i <= 15; i++) + { + init_pair(color_pair_idx(i, 0)+129, i, -1); + } + // default fg on bg = 145-152 + for (j = 0; j <= 7; j++) + { + init_pair(color_pair_idx(j, 0)+145, -1, j); + } if (globalconfig.utf8esc) (void) write(1, "\033%G", 3); #endif clear();