--- fhandler_console.cc.orig	Mon Dec 11 10:27:55 2000
+++ fhandler_console.cc.new	Mon Dec 11 10:36:18 2000
@@ -47,6 +47,8 @@ static struct
 
 const char * get_nonascii_key (INPUT_RECORD&, char *);
 
+static BOOL use_mouse = FALSE;
+
 HANDLE console_shared_h;
 
 static tty_min NO_COPY *shared_console_info = NULL;
@@ -184,7 +186,7 @@ fhandler_console::read (void *pv, size_t
 
       DWORD nread;
       INPUT_RECORD input_rec;
-      const char *toadd;
+      const char *toadd = 0;
 
       if (!ReadConsoleInput (h, &input_rec, 1, &nread))
 	{
@@ -217,7 +219,7 @@ fhandler_console::read (void *pv, size_t
 	      tmp[1] = ich;
 	      /* Need this check since US code page seems to have a bug when
 		 converting a CTRL-U. */
-	  if ((unsigned char)ich > 0x7f && current_codepage == ansi_cp)
+	      if ((unsigned char)ich > 0x7f && current_codepage == ansi_cp)
 		OemToCharBuff (tmp + 1, tmp + 1, 1);
 	      if (!(input_rec.Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED))
 		toadd = tmp + 1;
@@ -234,86 +236,90 @@ fhandler_console::read (void *pv, size_t
 	  break;
 
 	case MOUSE_EVENT:
-	  {
-	    MOUSE_EVENT_RECORD & mouse_event = input_rec.Event.MouseEvent;
-
-	    /* Treat the double-click event like a regular button press */
-	    if (mouse_event.dwEventFlags == DOUBLE_CLICK)
-	      {
-		syscall_printf("mouse: double-click -> click");
-		mouse_event.dwEventFlags = 0;
-	      }
-
-	    /* Did something other than a click occur? */
-	    if (mouse_event.dwEventFlags)
-	      continue;
-
-	    /* If the mouse event occurred out of the area we can handle,
-	       ignore it. */
-	    int x = mouse_event.dwMousePosition.X;
-	    int y = mouse_event.dwMousePosition.Y;
-	    if ((x + ' ' + 1 > 0xFF) || (y + ' ' + 1 > 0xFF))
-	      {
-		syscall_printf("mouse: position out of range");
-		continue;
-	      }
+	  if (use_mouse)
+	    {
+	      MOUSE_EVENT_RECORD & mouse_event = input_rec.Event.MouseEvent;
 
-	    /* Ignore unimportant mouse buttons */
-	    mouse_event.dwButtonState &= 0x7;
+	      /* Treat the double-click event like a regular button press */
+	      if (mouse_event.dwEventFlags == DOUBLE_CLICK)
+		{
+		  syscall_printf("mouse: double-click -> click");
+		  mouse_event.dwEventFlags = 0;
+		}
 
-	    /* This code assumes Windows never reports multiple button
-	       events at the same time. */
-	    static DWORD dwLastButtonState = 0;
-	    int b = 0;
-	    char sz[32];
-	    if (mouse_event.dwButtonState == dwLastButtonState)
-	      {
-		syscall_printf("mouse: button state unchanged");
+	      /* Did something other than a click occur? */
+	      if (mouse_event.dwEventFlags)
 		continue;
-	      }
-	    else if (mouse_event.dwButtonState < dwLastButtonState)
-	      {
-		b = 3;
-		strcpy(sz, "btn up");
-	      }
-	    else if ((mouse_event.dwButtonState & 1) != (dwLastButtonState & 1))
-	      {
-		b = 0;
-		strcpy(sz, "btn1 down");
-	      }
-	    else if ((mouse_event.dwButtonState & 2) != (dwLastButtonState & 2))
-	      {
-		b = 1;
-		strcpy(sz, "btn2 down");
-	      }
-	    else if ((mouse_event.dwButtonState & 4) != (dwLastButtonState & 4))
-	      {
-		b = 2;
-		strcpy(sz, "btn3 down");
-	      }
-
-	    /* Remember the current button state */
-	    dwLastButtonState = mouse_event.dwButtonState;
-
-	    static int nModifiers = 0;
-	    /* If a button was pressed, remember the modifiers */
-	    if (b != 3)
-	      {
-		nModifiers = 0;
-		if (mouse_event.dwControlKeyState & SHIFT_PRESSED)
-		  nModifiers |= 0x4;
-		if (mouse_event.dwControlKeyState & (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED))
-		  nModifiers |= 0x8;
-		if (mouse_event.dwControlKeyState & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED))
-		  nModifiers |= 0x10;
-	      }
-
-	    b |= nModifiers;
-
-	    /* We can now create the code. */
-	    sprintf(tmp, "\033[M%c%c%c", b + ' ', x + ' ' + 1, y + ' ' + 1);
-	    syscall_printf("mouse: %s at (%d,%d)", sz, x, y);
-	  }
+	      
+	      /* If the mouse event occurred out of the area we can handle,
+		 ignore it. */
+	      int x = mouse_event.dwMousePosition.X;
+	      int y = mouse_event.dwMousePosition.Y;
+	      if ((x + ' ' + 1 > 0xFF) || (y + ' ' + 1 > 0xFF))
+		{
+		  syscall_printf("mouse: position out of range");
+		  continue;
+		}
+	      
+	      /* Ignore unimportant mouse buttons */
+	      mouse_event.dwButtonState &= 0x7;
+	      
+	      /* This code assumes Windows never reports multiple button
+		 events at the same time. */
+	      static DWORD dwLastButtonState = 0;
+	      int b = 0;
+	      char sz[32];
+	      if (mouse_event.dwButtonState == dwLastButtonState)
+		{
+		  syscall_printf("mouse: button state unchanged");
+		  continue;
+		}
+	      else if (mouse_event.dwButtonState < dwLastButtonState)
+		{
+		  b = 3;
+		  strcpy(sz, "btn up");
+		}
+	      else if ((mouse_event.dwButtonState & 1) != (dwLastButtonState & 1))
+		{
+		  b = 0;
+		  strcpy(sz, "btn1 down");
+		}
+	      else if ((mouse_event.dwButtonState & 2) != (dwLastButtonState & 2))
+		{
+		  b = 1;
+		  strcpy(sz, "btn2 down");
+		}
+	      else if ((mouse_event.dwButtonState & 4) != (dwLastButtonState & 4))
+		{
+		  b = 2;
+		  strcpy(sz, "btn3 down");
+		}
+	      
+	      /* Remember the current button state */
+	      dwLastButtonState = mouse_event.dwButtonState;
+	      
+	      static int nModifiers = 0;
+	      /* If a button was pressed, remember the modifiers */
+	      if (b != 3)
+		{
+		  nModifiers = 0;
+		  if (mouse_event.dwControlKeyState & SHIFT_PRESSED)
+		    nModifiers |= 0x4;
+		  if (mouse_event.dwControlKeyState & (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED))
+		    nModifiers |= 0x8;
+		  if (mouse_event.dwControlKeyState & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED))
+		    nModifiers |= 0x10;
+		}
+	      
+	      b |= nModifiers;
+	      
+	      /* We can now create the code. */
+	      sprintf(tmp, "\033[M%c%c%c", b + ' ', x + ' ' + 1, y + ' ' + 1);
+	      syscall_printf("mouse: %s at (%d,%d)", sz, x, y);
+
+	      toadd = tmp;
+	      nread = 6;
+	    }
 	  break;
 
 	case WINDOW_BUFFER_SIZE_EVENT:
@@ -324,7 +330,7 @@ fhandler_console::read (void *pv, size_t
 	  continue;
 	}
 
-      if (line_edit (toadd, nread))
+      if (toadd && line_edit (toadd, nread))
 	break;
     }
 
@@ -956,6 +962,10 @@ fhandler_console::char_command (char c)
 	     case 37:		/* WHITE foreg */
 	       fg = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
 	       break;
+	     case 39:		/* Default foreg */
+	       fg = default_color & (FOREGROUND_BLUE | FOREGROUND_GREEN |
+				     FOREGROUND_RED);
+	       break;
 	     case 40:		/* BLACK background */
 	       bg = 0;
 	       break;
@@ -992,7 +1002,21 @@ fhandler_console::char_command (char c)
       break;
     case 'h':
     case 'l':
-      /* Ignore */
+      /* FIXME: Most, if not all, of these require a '?' before the
+	 number.  In an earlier routine, they are eaten as unknown
+	 characters, so ^[[1000h would be the same as ^[[?1000h,
+	 which is probably not good. */
+      switch (args_[0])
+	{
+	case 1000: /* Mouse support */
+	  use_mouse = (c == 'h') ? TRUE : FALSE;
+	  syscall_printf("mouse support %sabled", use_mouse ? "en" : "dis");
+	  break;
+
+	default: /* Ignore */
+	  syscall_printf("unknown h/l command: %d", args_[0]);
+	  break;
+	}
       break;
     case 'J':
       switch (args_[0])
