From: sbkelley Date: Wed, 10 Jun 2026 20:03:58 +0000 (-0400) Subject: Add support for arbitrary background colors X-Git-Tag: 1.6.1-roc-jun26-B-dev~1 X-Git-Url: https://skyeroc.xyz/gitweb/?a=commitdiff_plain;h=bf205bf580f7fd82afde81a78dd10f1a86338bd0;p=dgamelaunch Add support for arbitrary background colors move attr-string parsing logic to its own function Fix C-noob mistakes Add helper comments for later add color_pair_idx to prepare to add the rest of the color combos Add remainder of color pairs Should be backwards-compatible? We'll see what breaks over on linux box Finish, in principle, adding new color combos. They are not yet accessible with $ATTR(), and $ATT2() isn't done. Correcting fgbits in color_pair_idx() Reverting sleep-deprived 'correction' Let the new colors be accessible by $ATTR() Update Changelog --- diff --git a/Changelog b/Changelog index 9d1a1df..f7d6034 100644 --- a/Changelog +++ b/Changelog @@ -1,19 +1,28 @@ -1.6.1-roc (2026) +1.6.1-roc-jul + * Banner (Menu) Files + * $ATTR() now takes numbers > 15 -- they are the same colors against + all "normal" (no-dim/no-bold) backgrounds. There are now 130 color + pairs in total, including 0 and 129 which are white-on-black and + whatever the user's terminal's default fg/bg combo is, respectively. + * $ATTR() now accepts/turns an "blink" attribute, using character 'f' + for flash (since b was already taken by blink). + * Fixed lingering error in original and 1.6.1-roc dgamelaunch.conf, which + incorrectly instructed users to use ':' rather than ';' as a delimiter + in $ATTR() replacements. +1.6.1-roc-jun (2026) * Banner (Menu) Files * Changed loadbanner() [dgamelaunch.c] -- $INCLUDE() can now be anywhere in a line. * $VERSION now replaced with PACKAGE_VERSION instead of - PACKAGE_STRING + PACKAGE_STRING. * Banner files can be longer than 24 lines, if the window size is long enough. * Meta * Self-reported version now includes git tag and/or commit hash. * Forked noisytoot repository and merged changes in paxed's repo since last merge. - - - * Merged "crawl-specific" character handling from crawl repo (maybe it - will be useful for older versions of DCSS?) + * Merged "crawl-specific" character handling from crawl repo (maybe it + will be useful for older versions of DCSS?) 1.6.0-hdf (2024 - noisytoot fork, recorded here 2026 by skyebee) * Fixed various buildtime warnings in ee, and minor errors in autoconf diff --git a/dgamelaunch.c b/dgamelaunch.c index 02961a7..8e46116 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -135,25 +135,6 @@ static struct dg_watchcols default_watchcols[] = { #endif }; -int color_remap[16] = { - COLOR_PAIR(9) | A_NORMAL, - COLOR_PAIR(COLOR_BLUE) | A_NORMAL, - COLOR_PAIR(COLOR_GREEN) | A_NORMAL, - COLOR_PAIR(COLOR_CYAN) | A_NORMAL, - COLOR_PAIR(COLOR_RED) | A_NORMAL, - COLOR_PAIR(COLOR_MAGENTA) | A_NORMAL, - COLOR_PAIR(COLOR_YELLOW) | A_NORMAL, - COLOR_PAIR(COLOR_BLACK) | A_NORMAL, - COLOR_PAIR(10) | A_BOLD, - COLOR_PAIR(COLOR_BLUE) | A_BOLD, - COLOR_PAIR(COLOR_GREEN) | A_BOLD, - COLOR_PAIR(COLOR_CYAN) | A_BOLD, - COLOR_PAIR(COLOR_RED) | A_BOLD, - COLOR_PAIR(COLOR_MAGENTA) | A_BOLD, - COLOR_PAIR(COLOR_YELLOW) | A_BOLD, - COLOR_PAIR(COLOR_WHITE) | A_BOLD, -}; - static struct dg_watchcols *default_watchcols_list[DGL_MAXWATCHCOLS + 1]; struct dg_user * @@ -640,6 +621,48 @@ loadbanner (char *fname, struct dg_banner *ban) { fclose (bannerfile); } +int remap_attr_string(char *s) +{ + int attr = 0; + 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': + { + int num = atoi(s); + if (num >= 0 && num <= 129) + attr |= COLOR_PAIR(num+1); + } + 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; +} + void drawbanner(struct dg_banner *ban) { unsigned int i; @@ -681,50 +704,7 @@ void drawbanner(struct dg_banner *ban) *next_attr_char = '\0'; next_attr_char++; } - if (edit_cursor && *edit_cursor) - { - switch (*edit_cursor) - { - default: - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - { - int num = atoi(edit_cursor); - if (num >= 0 && num <= 15) - attr |= color_remap[num]; - } - 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; + attr |= remap_attr_string(edit_cursor); edit_cursor = next_attr_char; } while (delimited); @@ -742,6 +722,12 @@ void drawbanner(struct dg_banner *ban) } else mvaddstr(1 + i, x, output_cursor); +// elif ((edit_cursor = strstr(output_cursor, "$ATT2("))) +// { +// if ((special_end = strstr(edit_cursor, ")"))) +// { +// } +// } } while (line_incomplete); free(banner_line); } @@ -1906,6 +1892,7 @@ freefile () void initcurses () { + int i, j; printf("\033[2J"); if (newterm(NULL, stdout, stdin) == NULL) { if (!globalconfig.defterm || (newterm(globalconfig.defterm, stdout, stdin) == NULL)) { @@ -1923,24 +1910,30 @@ initcurses () start_color(); use_default_colors(); - init_pair(COLOR_BLACK, COLOR_WHITE, COLOR_BLACK); - init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); - init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); - init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); - init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); - init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); - init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); - init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); - init_pair(9, 0, COLOR_BLACK); - init_pair(10, COLOR_BLACK, COLOR_BLACK); - init_pair(11, -1, -1); - + init_pair(0, COLOR_WHITE, COLOR_BLACK); + init_pair(129, -1, -1); + /* color_pair_idx(0, 0) = 1; color_pair_idx(15, 7) = 128*/ + for (i = 0; i <= 15; i++) + { + for (j = 0; j <= 7; j++) + { + init_pair(color_pair_idx(i, j), i, j); + } + } if (globalconfig.utf8esc) (void) write(1, "\033%G", 3); #endif clear(); refresh(); } +int color_pair_idx(int fg, int bg) +{ + int bgbits = (7 & bg) << 4; + /* Swap bits 1 and 3 to line up with original color remap (+1) */ + int fgbits = (8 & fg) | ((1 & fg) << 2) | (2 & fg) | ((4 & fg) >> 2); + return (bgbits | fgbits) + 1; +} + /* ************************************************************* */ void diff --git a/dgamelaunch.h b/dgamelaunch.h index ee871f9..c199676 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -28,15 +28,14 @@ #define DGL_BANNER_LINELEN 256 /* max. length of banner lines*/ #ifdef USE_NCURSES_COLOR -# define CLR_NORMAL COLOR_PAIR(11) | A_NORMAL -# define CLR_RED COLOR_PAIR(COLOR_RED) | A_NORMAL -# define CLR_GREEN COLOR_PAIR(COLOR_GREEN) | A_NORMAL +# define CLR_NORMAL COLOR_PAIR(129) | A_NORMAL +# define CLR_RED COLOR_PAIR(5) | A_NORMAL +# define CLR_GREEN COLOR_PAIR(3) | A_NORMAL #else # define CLR_NORMAL 0 # define CLR_RED 0 # define CLR_GREEN 0 #endif -extern int color_remap[]; typedef enum { @@ -304,6 +303,7 @@ extern char *gen_ttyrec_filename(void); extern char *gen_inprogress_lock(int game, pid_t pid, char *ttyrec_filename); extern void catch_sighup(int signum); extern void loadbanner(char *fname, struct dg_banner *ban); +extern int remap_attr_string(char *s); extern void drawbanner(struct dg_banner *ban); extern void banner_var_add(char *name, char *value, int special); extern char *banner_var_value(char *name); @@ -351,6 +351,7 @@ extern void domailuser(char *username); extern void drawmenu(void); extern void freefile(void); extern void initcurses(void); +extern int color_pair_idx(int fg, int bg); extern void loginprompt(int from_ttyplay); extern void newuser(void); extern void autologin(char *user, char *pass);