From 327d749ce03d25897447ec36ed4c46c0da4a72cb Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 16 Mar 2025 15:13:39 +0300 Subject: further improved monochrome terminal support: fixed reverse text on reverse backgrounds * Unfortunately we cannot use `wbkgdset(win, A_REVERSE)` if we plan to use reverse text on this background, i.e. if we want to cancel out the background A_REVERSE. * SciTECO therefore no longer uses background attributes, but only foreground attributes. When setting a reverse text, we XOR A_REVERSE into the previous attributes. * This fixes control characters especially in the info line and popups, as well as rendering of the popup scroll bars. * The command-line should now be rendered properly even on a dark-on-bright color theme (which does not yet exist). --- src/interface-curses/curses-info-popup.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/interface-curses/curses-info-popup.c') diff --git a/src/interface-curses/curses-info-popup.c b/src/interface-curses/curses-info-popup.c index dffbcf8..332d434 100644 --- a/src/interface-curses/curses-info-popup.c +++ b/src/interface-curses/curses-info-popup.c @@ -98,7 +98,13 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr) */ ctx->pad = newpad(pad_lines, cols - 2); - wbkgd(ctx->pad, ' ' | attr); + /* + * NOTE: attr could contain A_REVERSE on monochrome terminals, + * so we use foreground attributes instead of background attributes. + * This way, we can cancel out the A_REVERSE if necessary. + */ + wattrset(ctx->pad, attr); + teco_curses_clrtobot(ctx->pad); /* * cur_col is the row currently written. @@ -113,7 +119,8 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr) wmove(ctx->pad, cur_line-1, (cur_col % pad_cols)*pad_colwidth); - wattrset(ctx->pad, entry->highlight ? A_BOLD : A_NORMAL); + if (entry->highlight) + wattron(ctx->pad, A_BOLD); switch (entry->type) { case TECO_POPUP_FILE: @@ -137,6 +144,8 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr) break; } + wattroff(ctx->pad, A_BOLD); + cur_col++; } } @@ -167,7 +176,7 @@ teco_curses_info_popup_show(teco_curses_info_popup_t *ctx, attr_t attr) /* window covers message, scintilla and info windows */ ctx->window = newwin(popup_lines, 0, lines - 1 - popup_lines, 0); - wbkgdset(ctx->window, ' ' | attr); + wattrset(ctx->window, attr); wborder(ctx->window, ACS_VLINE, @@ -198,7 +207,7 @@ teco_curses_info_popup_show(teco_curses_info_popup_t *ctx, attr_t attr) * Instead, simply draw reverse blanks. */ wmove(ctx->window, bar_y, cols-1); - wattron(ctx->window, A_REVERSE); + wattrset(ctx->window, attr ^ A_REVERSE); wvline(ctx->window, ' ', bar_height); } -- cgit v1.2.3