This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb/gdb-8.3-branch] Fix colors in TUI mode in MS-Windows build with ncurses
- From: Eli Zaretskii <eliz at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 14 Mar 2019 15:35:36 -0000
- Subject: [binutils-gdb/gdb-8.3-branch] Fix colors in TUI mode in MS-Windows build with ncurses
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7cf3f4acfddebe44f80b71dcdf1041d870c6d100
commit 7cf3f4acfddebe44f80b71dcdf1041d870c6d100
Author: Eli Zaretskii <eliz@gnu.org>
Date: Thu Mar 14 17:31:38 2019 +0200
Fix colors in TUI mode in MS-Windows build with ncurses
The MS-Windows port of ncurses fails to switch to a color pair if
one or both of the colors are the implicit default colors. This
change records the default colors when TUI is initialized, and
then specifies them explicitly when a color pair uses the default
colors. This allows color styling in TUI mode on MS-Windows.
gdb/ChangeLog:
2019-03-14 Eli Zaretskii <eliz@gnu.org>
* tui/tui-io.c [__MINGW32__]: Include windows.h. Declare
ncurses_norm_attr.
(tui_initialize_io) [__MINGW32__]: Record the default terminal
colors in ncurses_norm_attr.
(apply_ansi_escape) [__MINGW32__]: If a color in a color pair is
"none", replace it with the default color recorded in
ncurses_norm_attr.
(cherry picked from commit 3fff2c370cd658877be8107bfe9dde8dd0470b46)
Diff:
---
gdb/ChangeLog | 16 ++++++++++++++++
gdb/tui/tui-io.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2315067..4243a07 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,19 @@
+2019-03-14 Eli Zaretskii <eliz@gnu.org>
+
+ The MS-Windows port of ncurses fails to switch to a color pair if
+ one or both of the colors are the implicit default colors. This
+ change records the default colors when TUI is initialized, and
+ then specifies them explicitly when a color pair uses the default
+ colors. This allows color styling in TUI mode on MS-Windows.
+
+ * tui/tui-io.c [__MINGW32__]: Include windows.h. Declare
+ ncurses_norm_attr.
+ (tui_initialize_io) [__MINGW32__]: Record the default terminal
+ colors in ncurses_norm_attr.
+ (apply_ansi_escape) [__MINGW32__]: If a color in a color pair is
+ "none", replace it with the default color recorded in
+ ncurses_norm_attr.
+
2019-03-14 Tom Tromey <tromey@adacore.com>
* source-cache.h (class source_cache) <get_source_lines>: Return
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index d006e41..ef1e885 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -37,6 +37,9 @@
#include "cli-out.h"
#include <fcntl.h>
#include <signal.h>
+#ifdef __MINGW32__
+#include <windows.h>
+#endif
#include "common/filestuff.h"
#include "completer.h"
#include "gdb_curses.h"
@@ -47,6 +50,10 @@
"gdb_curses.h". */
#include "readline/readline.h"
+#ifdef __MINGW32__
+static SHORT ncurses_norm_attr;
+#endif
+
static int tui_getc (FILE *fp);
static int
@@ -322,6 +329,16 @@ apply_ansi_escape (WINDOW *w, const char *buf)
int fgi, bgi;
if (get_color (fg, &fgi) && get_color (bg, &bgi))
{
+#ifdef __MINGW32__
+ /* MS-Windows port of ncurses doesn't support implicit
+ default foreground and background colors, so we must
+ specify them explicitly when needed, using the colors we
+ saw at startup. */
+ if (fgi == -1)
+ fgi = ncurses_norm_attr & 15;
+ if (bgi == -1)
+ bgi = (ncurses_norm_attr >> 4) & 15;
+#endif
int pair = get_color_pair (fgi, bgi);
if (last_color_pair != -1)
wattroff (w, COLOR_PAIR (last_color_pair));
@@ -807,6 +824,19 @@ tui_initialize_io (void)
#else
tui_rl_outstream = stdout;
#endif
+
+#ifdef __MINGW32__
+ /* MS-Windows port of ncurses doesn't support default foreground and
+ background colors, so we must record the default colors at startup. */
+ HANDLE hstdout = (HANDLE)_get_osfhandle (fileno (stdout));
+ DWORD cmode;
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+
+ if (hstdout != INVALID_HANDLE_VALUE
+ && GetConsoleMode (hstdout, &cmode) != 0
+ && GetConsoleScreenBufferInfo (hstdout, &csbi))
+ ncurses_norm_attr = csbi.wAttributes;
+#endif
}
/* Get a character from the command window. This is called from the