Author: fejj
Date: 2007-04-24 12:41:45 -0400 (Tue, 24 Apr 2007)
New Revision: 76202

Modified:
   branches/mono-1-2-4/mcs/class/corlib/System/ChangeLog
   branches/mono-1-2-4/mcs/class/corlib/System/TermInfoDriver.cs
Log:
2007-04-23  Jeffrey Stedfast  <[EMAIL PROTECTED]>

        * TermInfoDriver.cs (ReadKeyInternal): Since our input stream is
        buffered, check if it has more buffered input in addition to our
        timeout check. This makes it such that we will actually correctly
        match multi-char escape sequences.
        (Read): Changed the logic slightly wrt 'fresh' echoing. Once we
        encounter a fresh char, all chars afterward should also be
        considered 'fresh' even if 'fresh' is returned as false later.
        (ReadLine): Same logic here.

2007-04-23  Jeffrey Stedfast  <[EMAIL PROTECTED]>

        Fixes bug #80702 (via getting rid of the casting) and more.

        The following change makes it such that even if an application
        calls Console.SetOut() with its own output stream, we can still
        properly echo user-input from stdin to the real stdout.

        * TermInfoDriver.cs (ctor): Grab a reference to the original
        Console.stdout so we can be sure we always echo to console.
        (QueueEcho): No need to cast Console.stdout anymore.
        (EchoFlush): Same.
        (WriteConsole: Here too.



Modified: branches/mono-1-2-4/mcs/class/corlib/System/ChangeLog
===================================================================
--- branches/mono-1-2-4/mcs/class/corlib/System/ChangeLog       2007-04-24 
16:41:39 UTC (rev 76201)
+++ branches/mono-1-2-4/mcs/class/corlib/System/ChangeLog       2007-04-24 
16:41:45 UTC (rev 76202)
@@ -1,3 +1,28 @@
+2007-04-23  Jeffrey Stedfast  <[EMAIL PROTECTED]>
+
+       * TermInfoDriver.cs (ReadKeyInternal): Since our input stream is
+       buffered, check if it has more buffered input in addition to our
+       timeout check. This makes it such that we will actually correctly
+       match multi-char escape sequences.
+       (Read): Changed the logic slightly wrt 'fresh' echoing. Once we
+       encounter a fresh char, all chars afterward should also be
+       considered 'fresh' even if 'fresh' is returned as false later.
+       (ReadLine): Same logic here.
+
+2007-04-23  Jeffrey Stedfast  <[EMAIL PROTECTED]>
+
+       Fixes bug #80702 (via getting rid of the casting) and more.
+
+       The following change makes it such that even if an application
+       calls Console.SetOut() with its own output stream, we can still
+       properly echo user-input from stdin to the real stdout.
+
+       * TermInfoDriver.cs (ctor): Grab a reference to the original
+       Console.stdout so we can be sure we always echo to console.
+       (QueueEcho): No need to cast Console.stdout anymore.
+       (EchoFlush): Same.
+       (WriteConsole: Here too.
+
 2007-04-20  Jeffrey Stedfast  <[EMAIL PROTECTED]>
 
        * TermInfoDriver.cs (QueueEcho): Renamed from Echo(char). Use

Modified: branches/mono-1-2-4/mcs/class/corlib/System/TermInfoDriver.cs
===================================================================
--- branches/mono-1-2-4/mcs/class/corlib/System/TermInfoDriver.cs       
2007-04-24 16:41:39 UTC (rev 76201)
+++ branches/mono-1-2-4/mcs/class/corlib/System/TermInfoDriver.cs       
2007-04-24 16:41:45 UTC (rev 76202)
@@ -52,6 +52,7 @@
                string bell;
                string term;
                StreamReader stdin;
+               CStreamWriter stdout;
                internal byte verase;
                byte vsusp;
                byte intr;
@@ -113,12 +114,12 @@
                        return null;
                }
 
-               static void WriteConsole (string str)
+               void WriteConsole (string str)
                {
                        if (str == null)
                                return;
-
-                       ((CStreamWriter) Console.stdout).InternalWriteString 
(str);
+                       
+                       stdout.InternalWriteString (str);
                }
 
                public TermInfoDriver ()
@@ -146,6 +147,14 @@
 
                        if (reader == null)
                                reader = new TermInfoReader (term, 
KnownTerminals.ansi);
+
+                       if (!(Console.stdout is CStreamWriter)) {
+                               // Application set its own stdout, we need a 
reference to the real stdout
+                               stdout = new CStreamWriter 
(Console.OpenStandardOutput (0), Console.OutputEncoding);
+                               ((StreamWriter) stdout).AutoFlush = true;
+                       } else {
+                               stdout = (CStreamWriter) Console.stdout;
+                       }
                }
 
                public bool Initialized {
@@ -156,7 +165,7 @@
                {
                        if (inited)
                                return;
-                       
+
                        /* This should not happen any more, since it is checked 
for in Console */
                        if (!ConsoleDriver.IsConsole)
                                throw new IOException ("Not a tty.");
@@ -858,7 +867,11 @@
                                                do {
                                                        AddToBuffer (stdin.Read 
());
                                                } while 
(ConsoleDriver.InternalKeyAvailable (0) > 0);
-                                       } else {
+                                       } else if (stdin.Peek () != -1) {
+                                               do {
+                                                       AddToBuffer (stdin.Read 
());
+                                               } while (stdin.Peek () != -1);
+                                       } else {                                
                
                                                if ((o = GetKeyFromBuffer 
(false)) != null)
                                                        break;
 
@@ -898,7 +911,7 @@
 
                        if (echon == echobuf.Length || !InputPending ()) {
                                // blit our echo buffer to the console
-                               ((CStreamWriter) 
Console.stdout).InternalWriteChars (echobuf, echon);
+                               stdout.InternalWriteChars (echobuf, echon);
                                echon = 0;
                        }
                }
@@ -924,17 +937,17 @@
                                return;
 
                        // flush our echo buffer to the console
-                       ((CStreamWriter) Console.stdout).InternalWriteChars 
(echobuf, echon);
+                       stdout.InternalWriteChars (echobuf, echon);
                        echon = 0;
                }
 #endregion
 
                public int Read ([In, Out] char [] dest, int index, int count)
                {
+                       bool fresh, echo = false;
                        StringBuilder sbuf;
                        ConsoleKeyInfo key;
                        int BoL = 0;  // Beginning-of-Line marker (can't 
backspace beyond this)
-                       bool fresh;
                        object o;
                        char c;
 
@@ -964,6 +977,7 @@
 
                        do {
                                key = ReadKeyInternal (out fresh);
+                               echo = echo || fresh;
                                c = key.KeyChar;
 
                                if (key.Key != ConsoleKey.Backspace) {
@@ -978,7 +992,7 @@
                                }
 
                                // echo fresh keys back to the console
-                               if (fresh)
+                               if (echo)
                                        Echo (key);
                        } while (key.Key != ConsoleKey.Enter);
 
@@ -1028,8 +1042,8 @@
                        GetCursorPosition ();
 
                        StringBuilder builder = new StringBuilder ();
+                       bool fresh, echo = false;
                        ConsoleKeyInfo key;
-                       bool fresh;
                        char c;
 
                        rl_startx = cursorLeft;
@@ -1037,7 +1051,9 @@
 
                        do {
                                key = ReadKeyInternal (out fresh);
+                               echo = echo || fresh;
                                c = key.KeyChar;
+
                                if (key.Key != ConsoleKey.Enter) {
                                        if (key.Key != ConsoleKey.Backspace) {
                                                builder.Append (c);
@@ -1050,7 +1066,7 @@
                                }
 
                                // echo fresh keys back to the console
-                               if (fresh)
+                               if (echo)
                                        Echo (key);
                        } while (key.Key != ConsoleKey.Enter);
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to