From 5dd16736789b7163de2ace8915cd83d6836be21a Mon Sep 17 00:00:00 2001 From: Ray Chason Date: Fri, 7 Aug 2026 11:54:07 -0400 Subject: [PATCH] Implement colors --- win/X11/winstat.c | 68 +++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/win/X11/winstat.c b/win/X11/winstat.c index ea464a329..4168bf88a 100644 --- a/win/X11/winstat.c +++ b/win/X11/winstat.c @@ -201,6 +201,7 @@ static const char *const fancy_status_hilite_colors[] = { struct tty_status_field { char *text; int color; + unsigned attrs; int chg; int percent; }; @@ -741,7 +742,8 @@ X11_status_update_tty( fldp->text = dupstr(str); fldp->chg = chg; fldp->percent = percent; - fldp->color = color; + fldp->color = color & 0xFF; + fldp->attrs = color >> 8; } break; } @@ -1162,33 +1164,33 @@ tty_status_redraw(Widget w) const char *pre; const char *post; } formats[MAXBLSTATS] = { - /*@@@*/[BL_TITLE] = { NULL, NULL }, - /*@@@*/[BL_STR] = { "St:", NULL }, - /*@@@*/[BL_DX] = { "Dx:", NULL }, - /*@@@*/[BL_CO] = { "Co:", NULL }, - /*@@@*/[BL_IN] = { "In:", NULL }, - /*@@@*/[BL_WI] = { "Wi:", NULL }, - /*@@@*/[BL_CH] = { "Ch:", NULL }, - /*@@@*/[BL_ALIGN] = { NULL, NULL }, - /*@@@*/[BL_SCORE] = { "S:", NULL }, - /*@@@*/[BL_CAP] = { NULL, NULL }, - /*@@@*/[BL_GOLD] = { NULL, NULL }, - /*@@@*/[BL_ENE] = { "Pw:", NULL }, - /*@@@*/[BL_ENEMAX] = { "(", ")" }, - /*@@@*/[BL_XP] = { "Xp:", NULL }, - /*@@@*/[BL_AC] = { "AC:", NULL }, - /*@@@*/[BL_HD] = { "HD:", NULL }, - /*@@@*/[BL_TIME] = { "T:", NULL }, - /*@@@*/[BL_HUNGER] = { NULL, NULL }, - /*@@@*/[BL_HP] = { "HP:", NULL }, - /*@@@*/[BL_HPMAX] = { "(", ")" }, - /*@@@*/[BL_LEVELDESC] = { NULL, NULL }, - /*@@@*/[BL_EXP] = { "/", NULL }, - /*@@@*/[BL_CONDITION] = { NULL, NULL }, + [BL_TITLE] = { NULL, NULL }, + [BL_STR] = { "St:", NULL }, + [BL_DX] = { "Dx:", NULL }, + [BL_CO] = { "Co:", NULL }, + [BL_IN] = { "In:", NULL }, + [BL_WI] = { "Wi:", NULL }, + [BL_CH] = { "Ch:", NULL }, + [BL_ALIGN] = { NULL, NULL }, + [BL_SCORE] = { "S:", NULL }, + [BL_CAP] = { NULL, NULL }, + [BL_GOLD] = { NULL, NULL }, + [BL_ENE] = { "Pw:", NULL }, + [BL_ENEMAX] = { "(", ")" }, + [BL_XP] = { "Xp:", NULL }, + [BL_AC] = { "AC:", NULL }, + [BL_HD] = { "HD:", NULL }, + [BL_TIME] = { "T:", NULL }, + [BL_HUNGER] = { NULL, NULL }, + [BL_HP] = { "HP:", NULL }, + [BL_HPMAX] = { "(", ")" }, + [BL_LEVELDESC] = { NULL, NULL }, + [BL_EXP] = { "/", NULL }, + [BL_CONDITION] = { NULL, NULL }, [BL_WEAPON] = { NULL, NULL }, /* not in 2-line */ [BL_ARMOR] = { NULL, NULL }, /* not in 2-line */ [BL_TERRAIN] = { NULL, NULL }, /* not in 2-line */ - /*@@@*/[BL_VERS] = { NULL, NULL }, + [BL_VERS] = { NULL, NULL }, }; Arg args[5]; int num_args; @@ -1233,7 +1235,7 @@ tty_status_redraw(Widget w) x += tty_render_text(w, x, y, formats[fld].pre, NO_COLOR, 0, FALSE); } x += tty_render_text(w, x, y, fldp->text, fldp->color, - fldp->chg ? HL_INVERSE : 0, fld == BL_GOLD); + fldp->attrs, fld == BL_GOLD); if (formats[fld].post != NULL) { x += tty_render_text(w, x, y, formats[fld].post, NO_COLOR, 0, FALSE); } @@ -1267,6 +1269,20 @@ tty_render_text(Widget w, int x, int y, const char *text, int color, int attr, XtSetArg(args[num_args], XtNfont, &font); num_args++; XtGetValues(w, args, num_args); + /* Implement color if requested */ + if (color != NO_COLOR) { + XrmValue source; + XrmValue dest; + Pixel pixel; + const char *cname = fancy_status_hilite_colors[color]; + source.addr = (XPointer) cname; + source.size = (unsigned int) strlen(cname) + 1; + dest.size = (unsigned int) sizeof (Pixel); + dest.addr = (XPointer) &pixel; + if (XtConvertAndStore(w, XtRString, &source, XtRPixel, &dest)) + fgpixel = pixel; + } + /* Get a graphics context */ if (attr & HL_INVERSE) { values.foreground = bgpixel;