Patchwork [RFC,8.3,0/3] Some style fixes

login
register
mail settings
Submitter Eli Zaretskii
Date March 13, 2019, 3:50 p.m.
Message ID <83k1h23hat.fsf@gnu.org>
Download mbox | patch
Permalink /patch/31843/
State New
Headers show

Comments

Eli Zaretskii - March 13, 2019, 3:50 p.m.
For the MinGW-specific problem with TUI colors, described here:

  https://www.sourceware.org/ml/gdb-patches/2019-03/msg00000.html
  https://www.sourceware.org/ml/gdb-patches/2019-03/msg00034.html

I propose to fix that as in the patch below.  Any objections to my
pushing this to the master and th gdb-8.3 branch (with suitable
ChangeLog entries)?
Tom Tromey - March 14, 2019, 12:20 p.m.
>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:

Eli> +#ifdef __MINGW32__
Eli> +#include <windows.h>
Eli> +static SHORT ncurses_norm_attr;
Eli> +#endif

I'd somewhat prefer it if the definition were in a separate block after
all the includes.

The rest seems fine to me.

Tom
Pedro Alves - March 14, 2019, 2:40 p.m.
On 03/14/2019 12:20 PM, Tom Tromey wrote:
>>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:
> 
> Eli> +#ifdef __MINGW32__
> Eli> +#include <windows.h>
> Eli> +static SHORT ncurses_norm_attr;
> Eli> +#endif
> 
> I'd somewhat prefer it if the definition were in a separate block after
> all the includes.
> 

Me too.  It would help with the "namespace gdb" effort as well,
since the variable will be braced under "namespace gdb" while
the header won't.

Thanks,
Pedro Alves
Eli Zaretskii - March 14, 2019, 3:36 p.m.
> Cc: tromey@adacore.com, gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Thu, 14 Mar 2019 14:40:37 +0000
> 
> On 03/14/2019 12:20 PM, Tom Tromey wrote:
> >>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:
> > 
> > Eli> +#ifdef __MINGW32__
> > Eli> +#include <windows.h>
> > Eli> +static SHORT ncurses_norm_attr;
> > Eli> +#endif
> > 
> > I'd somewhat prefer it if the definition were in a separate block after
> > all the includes.
> 
> Me too.  It would help with the "namespace gdb" effort as well,
> since the variable will be braced under "namespace gdb" while
> the header won't.

Thanks for the review.  I made the requested change and pushed to both
branches.

Patch

--- gdb/tui/tui-io.c~5	2019-03-12 09:18:11.713960000 +0200
+++ gdb/tui/tui-io.c	2019-03-13 09:09:15.185827600 +0200
@@ -37,6 +37,10 @@ 
 #include "cli-out.h"
 #include <fcntl.h>
 #include <signal.h>
+#ifdef __MINGW32__
+#include <windows.h>
+static SHORT ncurses_norm_attr;
+#endif
 #include "common/filestuff.h"
 #include "completer.h"
 #include "gdb_curses.h"
@@ -322,6 +326,16 @@  apply_ansi_escape (WINDOW *w, const char
       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));
@@ -803,6 +817,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