2007-04-17 Jeffrey Stedfast <fejj@novell.com>
authorJeffrey Stedfast <fejj@novell.com>
Tue, 17 Apr 2007 18:38:27 +0000 (18:38 -0000)
committerJeffrey Stedfast <fejj@novell.com>
Tue, 17 Apr 2007 18:38:27 +0000 (18:38 -0000)
* TermInfoDriver.cs (Init): SetEcho(false), we'll be manually
echoing from now on (ReadLine() has already been doing this, might
as well make ReadKey() behave the same).
(GetCursorPosition): No longer need to disable/re-enable echo
anymore since it is now always false.
(ReadKey): Manually echo the key back to the console just like
ReadLine() has been doing (in the interest of consistancy) if
intercept is false.
(ReadLine): No longer need to disable/re-enable echo, echo is
always off now. Also, fixed what appears to have been a typo.

svn path=/trunk/mcs/; revision=75849

mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/TermInfoDriver.cs

index 4af388f349e61044cfeaec85fa067ec52e493c89..a55cf603cd665139ae4657d233c897ad3ecc86de 100644 (file)
@@ -1,3 +1,16 @@
+2007-04-17  Jeffrey Stedfast  <fejj@novell.com>
+
+       * TermInfoDriver.cs (Init): SetEcho(false), we'll be manually
+       echoing from now on (ReadLine() has already been doing this, might
+       as well make ReadKey() behave the same).
+       (GetCursorPosition): No longer need to disable/re-enable echo
+       anymore since it is now always false.
+       (ReadKey): Manually echo the key back to the console just like
+       ReadLine() has been doing (in the interest of consistancy) if
+       intercept is false.
+       (ReadLine): No longer need to disable/re-enable echo, echo is
+       always off now. Also, fixed what appears to have been a typo.
+
 2007-04-17  Jeffrey Stedfast  <fejj@novell.com>
 
        * TermInfoDriver.cs (IsSpecialKey): Oops, Enter should not be
index b93c89d12f8d6858315e5de8c555a8a2844e9364..cace3cad1554f7415b2ca6a40de922ea64d94b41 100644 (file)
@@ -129,7 +129,7 @@ namespace System {
                public TermInfoDriver (string term)
                {
 #if DEBUG
-                       File.Delete ("console.log");
+                       //File.Delete ("console.log");
                        logger = new StreamWriter (File.OpenWrite ("console.log"));
 #endif
                        this.term = term;
@@ -162,6 +162,9 @@ namespace System {
                                throw new IOException ("Not a tty.");
 
                        inited = true;
+
+                       ConsoleDriver.SetEcho (false);
+
                        string endString = null;
                        keypadXmit = reader.Get (TermInfoStrings.KeypadXmit);
                        keypadLocal = reader.Get (TermInfoStrings.KeypadLocal);
@@ -394,58 +397,57 @@ namespace System {
                void GetCursorPosition ()
                {
                        int row = 0, col = 0;
-                       
-                       ConsoleDriver.SetEcho (false);
-                       
-                       try {
-                               WriteConsole ("\x1b[6n");
-                               if (ConsoleDriver.InternalKeyAvailable (1000) <= 0) {
-                                       noGetPosition = true;
-                                       return;
-                               }
 
-                               int b = stdin.ReadByte ();
-                               while (b != '\x1b') {
-                                       AddToBuffer (b);
-                                       if (ConsoleDriver.InternalKeyAvailable (100) <= 0)
-                                               return;
-                                       b = stdin.ReadByte ();
-                               }
+                       WriteConsole ("\x1b[6n");
+                       if (ConsoleDriver.InternalKeyAvailable (1000) <= 0) {
+                               noGetPosition = true;
+                               return;
+                       }
 
-                               b = stdin.ReadByte ();
-                               if (b != '[') {
-                                       AddToBuffer ('\x1b');
-                                       AddToBuffer (b);
+                       int b = stdin.ReadByte ();
+                       while (b != '\x1b') {
+                               AddToBuffer (b);
+                               if (ConsoleDriver.InternalKeyAvailable (100) <= 0)
                                        return;
-                               }
+                               b = stdin.ReadByte ();
+                       }
+
+                       b = stdin.ReadByte ();
+                       if (b != '[') {
+                               AddToBuffer ('\x1b');
+                               AddToBuffer (b);
+                               return;
+                       }
 
+                       b = stdin.ReadByte ();
+                       if (b != ';') {
+                               row = b - '0';
                                b = stdin.ReadByte ();
-                               if (b != ';') {
-                                       row = b - '0';
+                               while ((b >= '0') && (b <= '9')) {
+                                       row = row * 10 + b - '0';
                                        b = stdin.ReadByte ();
-                                       while ((b >= '0') && (b <= '9')) {
-                                               row = row * 10 + b - '0';
-                                               b = stdin.ReadByte ();
-                                       }
-                                       // Row/col is 0 based
-                                       row --;
                                }
+                               // Row/col is 0 based
+                               row --;
+                       }
 
+                       b = stdin.ReadByte ();
+                       if (b != 'R') {
+                               col = b - '0';
                                b = stdin.ReadByte ();
-                               if (b != 'R') {
-                                       col = b - '0';
+                               while ((b >= '0') && (b <= '9')) {
+                                       col = col * 10 + b - '0';
                                        b = stdin.ReadByte ();
-                                       while ((b >= '0') && (b <= '9')) {
-                                               col = col * 10 + b - '0';
-                                               b = stdin.ReadByte ();
-                                       }
-                                       // Row/col is 0 based
-                                       col --;
                                }
-                       } finally {
-                               ConsoleDriver.SetEcho (true);
+                               // Row/col is 0 based
+                               col --;
                        }
 
+#if DEBUG
+                       logger.WriteLine ("GetCursorPosition: {0}, {1}", col, row);
+                       logger.Flush ();
+#endif
+
                        cursorLeft = col;
                        cursorTop = row;
                }
@@ -875,13 +877,17 @@ namespace System {
                        if (!inited)
                                Init ();
                        
-                       if (intercept)
-                               ConsoleDriver.SetEcho (false);
-                       
                        ConsoleKeyInfo key = ReadKeyInternal ();
                        
-                       if (intercept)
-                               ConsoleDriver.SetEcho (true);
+                       if (!intercept) {
+                               // echo the key back to the console
+                               CStreamWriter writer = Console.stdout as CStreamWriter;
+
+                               if (writer != null)
+                                       writer.WriteKey (key);
+                               else
+                                       Console.stdout.Write (key.KeyChar);
+                       }
                        
                        return key;
                }
@@ -891,13 +897,11 @@ namespace System {
                        if (!inited)
                                Init ();
                        
-                       ConsoleDriver.SetEcho (false);
-                       
                        StringBuilder builder = new StringBuilder ();
                        bool exit = false;
                        CStreamWriter writer = Console.stdout as CStreamWriter;
                        rl_startx = cursorLeft;
-                       rl_starty = cursorLeft;
+                       rl_starty = cursorTop;
                        do {
                                ConsoleKeyInfo key = ReadKeyInternal ();
                                char c = key.KeyChar;
@@ -920,8 +924,6 @@ namespace System {
                                        Console.stdout.Write (c);
                        } while (!exit);
                        
-                       ConsoleDriver.SetEcho (true);
-                       
                        rl_startx = -1;
                        rl_starty = -1;
                        return builder.ToString ();