diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-03-07 22:52:45 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-03-07 22:52:45 +0300 |
commit | a7207d8526dd05e778e3972003a9be1a5106321a (patch) | |
tree | baf1051b8cafba7827bb0ba71e11af565b66e14b | |
parent | 4a84ed510d79182d6a47ba074f549c8c39821c0a (diff) | |
download | sciteco-a7207d8526dd05e778e3972003a9be1a5106321a.tar.gz |
ncurses: support monochrome terminals
* If the background color would be non-black, render text in reverse
video. ncurses doesn't do that automatically.
* Fixes rendering under historical terminals like VT100 and VT240,
but also all of the monochrome versions of modern emulators in terminfo.
* This also improves the situation when $TERM is set to something conservative,
e.g. when connecting via RS232.
* Scinterm is temporarily changed to my own fork, which already contains
a monochrome patch.
-rw-r--r-- | .gitmodules | 2 | ||||
m--------- | contrib/scinterm | 0 | ||||
-rw-r--r-- | src/interface-curses/interface.c | 37 |
3 files changed, 27 insertions, 12 deletions
diff --git a/.gitmodules b/.gitmodules index ed91108..db70f81 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,7 +4,7 @@ ignore = untracked [submodule "scinterm"] path = contrib/scinterm - url = https://github.com/orbitalquark/scinterm.git + url = https://github.com/rhaberkorn/scinterm.git [submodule "lexilla"] path = contrib/lexilla url = https://github.com/ScintillaOrg/lexilla.git diff --git a/contrib/scinterm b/contrib/scinterm -Subproject 430822df945b51ce1ed3026047fe8967a18d1ff +Subproject 3a47c1b053c7316a4237d55fce125683a43eca2 diff --git a/src/interface-curses/interface.c b/src/interface-curses/interface.c index 42ffdc6..206ff30 100644 --- a/src/interface-curses/interface.c +++ b/src/interface-curses/interface.c @@ -176,14 +176,29 @@ static gint teco_xterm_version(void) G_GNUC_UNUSED; /** * Curses attribute for the color combination - * `f` (foreground) and `b` (background) * according to the color pairs initialized by * Scinterm. - * NOTE: This depends on the global variable - * `COLORS` and is thus not a constant expression. + * This is equivalent to Scinterm's internal term_color_attr(). + * + * @param fg foreground color + * @param bg background color + * @return curses attribute */ -#define SCI_COLOR_ATTR(f, b) \ - ((attr_t)COLOR_PAIR(SCI_COLOR_PAIR(f, b))) +static inline attr_t +teco_color_attr(gshort fg, gshort bg) +{ + if (has_colors()) + return COLOR_PAIR(SCI_COLOR_PAIR(fg, bg)); + + /* + * Basic support for monochrome terminals: + * Every background, that is not black is assumed to be a + * dark-on-bright area, rendered in reverse. + * This will at least work with the terminal.tes + * color scheme. + */ + return bg != COLOR_BLACK ? A_REVERSE : 0; +} /** * Translate a Scintilla-compatible RGB color value @@ -881,7 +896,7 @@ teco_interface_vmsg(teco_msg_t type, const gchar *fmt, va_list ap) } wmove(teco_interface.msg_window, 0, 0); - wbkgdset(teco_interface.msg_window, ' ' | SCI_COLOR_ATTR(fg, bg)); + wbkgdset(teco_interface.msg_window, ' ' | teco_color_attr(fg, bg)); vw_printw(teco_interface.msg_window, fmt, ap); wclrtoeol(teco_interface.msg_window); } @@ -895,7 +910,7 @@ teco_interface_msg_clear(void) short fg = teco_rgb2curses(teco_interface_ssm(SCI_STYLEGETBACK, STYLE_DEFAULT, 0)); short bg = teco_rgb2curses(teco_interface_ssm(SCI_STYLEGETFORE, STYLE_DEFAULT, 0)); - wbkgdset(teco_interface.msg_window, ' ' | SCI_COLOR_ATTR(fg, bg)); + wbkgdset(teco_interface.msg_window, ' ' | teco_color_attr(fg, bg)); werase(teco_interface.msg_window); } @@ -1007,7 +1022,7 @@ teco_interface_draw_info(void) short bg = teco_rgb2curses(teco_interface_ssm(SCI_STYLEGETFORE, STYLE_DEFAULT, 0)); wmove(teco_interface.info_window, 0, 0); - wbkgdset(teco_interface.info_window, ' ' | SCI_COLOR_ATTR(fg, bg)); + wbkgdset(teco_interface.info_window, ' ' | teco_color_attr(fg, bg)); const gchar *info_type_str; @@ -1177,7 +1192,7 @@ teco_interface_draw_cmdline(void) short fg = teco_rgb2curses(teco_interface_ssm(SCI_STYLEGETFORE, STYLE_DEFAULT, 0)); short bg = teco_rgb2curses(teco_interface_ssm(SCI_STYLEGETBACK, STYLE_DEFAULT, 0)); - wbkgdset(teco_interface.cmdline_window, ' ' | SCI_COLOR_ATTR(fg, bg)); + wbkgdset(teco_interface.cmdline_window, ' ' | teco_color_attr(fg, bg)); werase(teco_interface.cmdline_window); mvwaddch(teco_interface.cmdline_window, 0, 0, '*' | A_BOLD); copywin(teco_interface.cmdline_pad, teco_interface.cmdline_window, @@ -1667,7 +1682,7 @@ teco_interface_popup_show(gsize prefix_len) short bg = teco_rgb2curses(teco_interface_ssm(SCI_STYLEGETBACK, STYLE_CALLTIP, 0)); teco_interface.popup_prefix_len = prefix_len; - teco_curses_info_popup_show(&teco_interface.popup, SCI_COLOR_ATTR(fg, bg)); + teco_curses_info_popup_show(&teco_interface.popup, teco_color_attr(fg, bg)); } void @@ -1823,7 +1838,7 @@ teco_interface_getmouse(GError **error) short fg = teco_rgb2curses(teco_interface_ssm(SCI_STYLEGETFORE, STYLE_CALLTIP, 0)); short bg = teco_rgb2curses(teco_interface_ssm(SCI_STYLEGETBACK, STYLE_CALLTIP, 0)); - teco_curses_info_popup_show(&teco_interface.popup, SCI_COLOR_ATTR(fg, bg)); + teco_curses_info_popup_show(&teco_interface.popup, teco_color_attr(fg, bg)); return TRUE; } |