diff --git a/include/wintty.h b/include/wintty.h index 4fc07fe2d..b4c983eee 100644 --- a/include/wintty.h +++ b/include/wintty.h @@ -189,9 +189,8 @@ extern void term_end_raw_bold(void); extern void term_end_color(void); extern void term_start_color(int color); extern void term_start_bgcolor(int color); -extern void term_start_extracolor(uint32 nhcolor); +extern void term_start_extracolor(uint32, uint16); extern void term_end_extracolor(void); /* termcap.c, consoletty.c */ -extern void term_start_256color(int idx); /* ### topl.c ### */ diff --git a/sys/msdos/video.c b/sys/msdos/video.c index 62a5f990c..e172513ee 100644 --- a/sys/msdos/video.c +++ b/sys/msdos/video.c @@ -378,12 +378,7 @@ term_start_bgcolor(int bgcolor) } void -term_start_extracolor(uint32 nhcolor UNUSED) -{ -} - -void -term_start_256color(int idx UNUSED) +term_start_extracolor(uint32 nhcolor UNUSED, uint16 color256idx UNUSED) { } diff --git a/sys/windows/consoletty.c b/sys/windows/consoletty.c index 51a3079f7..5ea736fce 100644 --- a/sys/windows/consoletty.c +++ b/sys/windows/consoletty.c @@ -1452,12 +1452,13 @@ g_pututf8(uint8 *sequence) } void -term_start_extracolor(uint32 nhcolor) +term_start_extracolor(uint32 nhcolor, uint16 color256idx) { #ifdef VIRTUAL_TERMINAL_SEQUENCES if ((nhcolor & NH_BASIC_COLOR) == 0) { console.color24 = COLORVAL(nhcolor); /* color 0 has bit 0x1000000 set */ console.current_colorflags = 0; + console.color256idx = color256idx; } else { #endif /* NH_BASIC_COLOR */ @@ -1471,7 +1472,6 @@ term_start_extracolor(uint32 nhcolor) void term_start_256color(int idx) { - console.color256idx = idx; } void diff --git a/win/tty/termcap.c b/win/tty/termcap.c index b5d905312..17eab38d4 100644 --- a/win/tty/termcap.c +++ b/win/tty/termcap.c @@ -17,9 +17,8 @@ static char *e_atr2str(int); void cmov(int, int); void nocmov(int, int); -void term_start_extracolor(uint32 nhcolor); +void term_start_extracolor(uint32, uint16); void term_end_extracolor(void); -void term_start_256color(int); #if defined(TERMLIB) #if (!defined(UNIX) || !defined(TERMINFO)) && !defined(TOS) @@ -1470,60 +1469,55 @@ term_start_bgcolor(int color) } #ifndef SEP2 +#define tcfmtstr "\033[38;2;%ld;%ld;%ldm" #ifdef UNIX -#define tcfmtstr "\033[38;2;%d;%d;%dm" -#define tcfmtstr24bit "\033[38;2;%d;%d;%dm" +#define tcfmtstr24bit "\033[38;2;%u;%u;%um" #define tcfmtstr256 "\033[38;5;%dm" #else -#define tcfmtstr "\033[38;2;%ld;%ld;%ldm" -#define tcfmtstr24bit "\033[38;2;%ld;%ld;%ldm" -#define tcfmtstr256 "\033[38:5:%ldm" +#define tcfmtstr24bit "\033[38;2;%lu;%lu;%lum" +#define tcfmtstr256 "\033[38:5:%lum" #endif #endif -static void emit24bit(uint32 color24bit); +static void emit24bit(long mcolor); static void emit256(int u256coloridx); -static void emit24bit(uint32 color24bit) +static void emit24bit(long mcolor) { static char tcolorbuf[QBUFSZ]; Snprintf(tcolorbuf, sizeof tcolorbuf, tcfmtstr, - ((color24bit >> 16) & 0xFF), /* red */ - ((color24bit >> 8) & 0xFF), /* green */ - ((color24bit >> 0) & 0xFF)); /* blue */ + ((mcolor >> 16) & 0xFF), /* red */ + ((mcolor >> 8) & 0xFF), /* green */ + ((mcolor >> 0) & 0xFF)); /* blue */ xputs(tcolorbuf); } -static void emit256(int u256coloridx) +static void emit256(int color256idx) { static char tcolorbuf[QBUFSZ]; Snprintf(tcolorbuf, sizeof tcolorbuf, tcfmtstr256, - u256coloridx); + color256idx); xputs(tcolorbuf); } void -term_start_256color(int idx) +term_start_extracolor(uint32 customcolor, uint16 color256idx) { - emit256(idx); -} - -void -term_start_extracolor(uint32 nhcolor) -{ - /* color 0 has bit NH_BASIC_COLOR set */ - uint32 modcolor = COLORVAL(nhcolor); - - emit24bit(modcolor); + /* color 0 has bit 0x1000000 set */ + long mcolor = (customcolor & 0xFFFFFF); + if (iflags.colorcount == 256) + emit256(color256idx); + else + emit24bit(mcolor); } void term_end_extracolor(void) { - xputs("\033[0m"); + xputs("\033[0m"); } - #endif /* TTY_GRAPHICS && !NO_TERMS */ + /*termcap.c*/ diff --git a/win/tty/wintty.c b/win/tty/wintty.c index b2739a468..492e62ddb 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -252,9 +252,7 @@ static void status_sanity_check(void); void g_pututf8(uint8 *utf8str); #endif -/* this is always present to reduce preproc conditional code */ static boolean calling_from_update_inventory = FALSE; - #ifdef TTY_PERM_INVENT static struct tty_perminvent_cell emptyttycell = { 0, 0, 0, { 0 }, NO_COLOR + 1 @@ -3067,8 +3065,7 @@ ttyinv_add_menu( row = (slot % rows_per_side) + 1; /* +1: top border */ /* side: left side panel or right side panel, not a window column */ side = slot / rows_per_side; - ttyinv_populate_slot(cw, row, side, text, - (uint32) clr, startcolor_at); + ttyinv_populate_slot(cw, row, side, text, clr, startcolor_at); } return; } @@ -3221,8 +3218,8 @@ ttyinv_end_menu(int window, struct WinDesc *cw) static void ttyinv_render(winid window, struct WinDesc *cw) { - int row, col, slot, side, filled_count = 0, slot_limit; - uint32 current_row_color = NO_COLOR; + int row, col, slot, side, filled_count = 0, slot_limit, + current_row_color = NO_COLOR; struct tty_perminvent_cell *cell; char invbuf[BUFSZ]; boolean force_redraw = gp.program_state.in_docrt ? TRUE : FALSE, @@ -3336,7 +3333,7 @@ ttyinv_populate_slot( int row, /* 'row' within the window, not within screen */ int side, /* 'side'==0 is left panel or ==1 is right panel */ const char *text, - uint32 color, + int32_t color, int clroffset) { struct tty_perminvent_cell *cell; @@ -3804,12 +3801,8 @@ tty_print_glyph( boolean inverse_on = FALSE, colordone = FALSE, glyphdone = FALSE; boolean petattr = FALSE; int ch; - uint32 color, nhcolor = 0; + uint32 color; unsigned special; -#if 0 - int clridx; - uint32 closecolor; -#endif HUPSKIP(); #ifdef CLIPPING @@ -3837,34 +3830,29 @@ tty_print_glyph( } #endif if (iflags.use_color) { - if (color != ttyDisplay->color) { - if (ttyDisplay->color != NO_COLOR) { - term_end_color(); - } - } ttyDisplay->colorflags = NH_BASIC_COLOR; - if (iflags.colorcount >= 256 && glyphinfo->gm.customcolor != 0 - && !calling_from_update_inventory - && (tty_procs.wincap2 & WC2_EXTRACOLORS) != 0) { - if ((glyphinfo->gm.customcolor & NH_BASIC_COLOR) != 0) { - /* don't set colordone or nhcolor */ - color = COLORVAL(glyphinfo->gm.customcolor); - } else if (iflags.colorcount == 256) { - ttyDisplay->colorflags = 0; /* not NH_BASIC_COLOR */ - term_start_256color(glyphinfo->gm.color256idx); - } else { - nhcolor = COLORVAL(glyphinfo->gm.customcolor); + if (color != ttyDisplay->color) { + if (ttyDisplay->color != NO_COLOR) + term_end_color(); + } + /* we don't link with termcap.o if NO_TERMS is defined */ + if ((tty_procs.wincap2 & WC2_EXTRACOLORS) + && glyphinfo->gm.customcolor != 0 + && iflags.colorcount >= 256 + && !calling_from_update_inventory) { + if ((glyphinfo->gm.customcolor & NH_BASIC_COLOR) == 0) { + term_start_extracolor(glyphinfo->gm.customcolor, + glyphinfo->gm.color256idx); ttyDisplay->colorflags = 0; - term_start_extracolor(nhcolor); colordone = TRUE; + } else { + color = COLORVAL(glyphinfo->gm.customcolor); } } if (!colordone) { - /* NH_BASIC_COLOR processing */ ttyDisplay->color = color; - if (color != NO_COLOR) { + if (color != NO_COLOR) term_start_color(color); - } } } /* iflags.use_color aka iflags.wc_color */