Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/ChangeLog,v
retrieving revision 1.1568
diff -u -2 -r1.1568 ChangeLog
--- ChangeLog	25 Apr 2004 22:51:46 -0000	1.1568
+++ ChangeLog	25 Apr 2004 23:31:53 -0000
@@ -1,4 +1,11 @@
 2004-04-25  Tor Lillqvist  <tml@iki.fi>
 
+	* glib/gmessages.c (allocate_console): [Win32] New
+	function. Allocates a console if necessary, and sets its
+	appearance to be "un-DOS-like", to avoid clueless people calling
+	it a "DOS box".
+	(ensure_stdout_valid, ensure_stderr_valid): [Win32] Call
+	allocate_console().
+
 	* glib/gwin32.c (g_win32_get_package_installation_subdirectory):
 	Plug memory leak. (#140770, John Ehresman)
Index: glib/gmessages.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gmessages.c,v
retrieving revision 1.60
diff -u -2 -r1.60 gmessages.c
--- glib/gmessages.c	22 Apr 2004 20:17:54 -0000	1.60
+++ glib/gmessages.c	25 Apr 2004 23:31:54 -0000
@@ -99,4 +99,69 @@
 static gchar *fatal_msg_ptr = fatal_msg_buf;
 
+static void
+allocate_console (FILE *stream,
+		  DWORD handle)
+{
+  if ((HANDLE) _get_osfhandle (fileno (stream)) == INVALID_HANDLE_VALUE)
+    {
+      /* Create a new console window, set its scrollback buffer to be
+       * rather large, and width to at least a nice 100 columns. Set
+       * its colour to black-on-yellow as an attempt to avoid having
+       * clueless people calling it a "DOS box".
+       */
+      if (AllocConsole ())
+	{
+	  HANDLE sb;
+	  CONSOLE_SCREEN_BUFFER_INFO sbi;
+      
+	  sb = CreateFile ("CONOUT$", GENERIC_READ|GENERIC_WRITE,
+			   FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+
+	  if (sb != INVALID_HANDLE_VALUE &&
+	      GetConsoleScreenBufferInfo (sb, &sbi))
+	    {
+	      COORD origin;
+	      COORD size;
+	      SMALL_RECT window;
+	      WORD attributes[100];
+	      int i;
+				     
+	      size.Y = MAX (sbi.dwSize.Y, 500);
+	      size.X = MAX (sbi.dwSize.X, 100);
+	      SetConsoleScreenBufferSize (sb, size);
+	      GetConsoleScreenBufferInfo (sb, &sbi);
+	      window.Left = window.Top = 0;
+	      window.Right = sbi.dwSize.X - 1;
+	      window.Bottom = MIN (sbi.dwSize.Y - 1, 19);
+	      SetConsoleWindowInfo (sb, TRUE, &window);
+
+	      for (i = 0; i < G_N_ELEMENTS (attributes); i++)
+		attributes[i] = BACKGROUND_GREEN|BACKGROUND_RED|BACKGROUND_INTENSITY;
+	      origin.X = origin.Y = 0;
+
+	      while (1)
+		{
+		  DWORD nwritten;
+		  
+		  if (!WriteConsoleOutputAttribute (sb, attributes, G_N_ELEMENTS (attributes), origin, &nwritten))
+		    break;
+
+		  origin.X = (origin.X + nwritten) % sbi.dwSize.X;
+		  origin.Y = origin.Y + (origin.X + nwritten) / sbi.dwSize.X;
+
+		  if (origin.Y >= sbi.dwSize.Y)
+		    break;
+		}
+	      
+	      SetConsoleTextAttribute (sb, attributes[0]);
+	      SetStdHandle (handle, sb);
+	    }
+	}
+
+      freopen ("CONOUT$", "w", stream);
+    }
+}
+
+
 /* Just use stdio. If we're out of memory, we're hosed anyway. */
 #undef write
@@ -124,20 +189,13 @@
 ensure_stdout_valid (void)
 {
-  static gboolean alloc_console_called = FALSE;
-  HANDLE handle;
+  static gboolean allocate_console_called = FALSE;
 
   if (win32_keep_fatal_message)
     return;
 
-  if (!alloc_console_called)
+  if (!allocate_console_called)
     {
-      handle = (HANDLE) _get_osfhandle (fileno (stdout)); 
-  
-      if (handle == INVALID_HANDLE_VALUE)
-	{
-	  AllocConsole ();
-	  alloc_console_called = TRUE;
-	  freopen ("CONOUT$", "w", stdout);
-	}
+      allocate_console (stdout, STD_OUTPUT_HANDLE);
+      allocate_console_called = TRUE;
     }
 }
@@ -146,20 +204,13 @@
 ensure_stderr_valid (void)
 {
-  static gboolean alloc_console_called = FALSE;
-  HANDLE handle;
+  static gboolean allocate_console_called = FALSE;
 
   if (win32_keep_fatal_message)
     return;
 
-  if (!alloc_console_called)
+  if (!allocate_console_called)
     {
-      handle = (HANDLE) _get_osfhandle (fileno (stderr)); 
-
-      if (handle == INVALID_HANDLE_VALUE)
-	{
-	  AllocConsole ();
-	  alloc_console_called = TRUE;
-	  freopen ("CONOUT$", "w", stderr);
-	}
+      allocate_console (stderr, STD_ERROR_HANDLE);
+      allocate_console_called = TRUE;
     }
 }
