From 2b11d9aedb2686aeb19bfa1704a9748a27e27f9b Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Tue, 17 Apr 2007 18:38:27 +0000 Subject: [PATCH] 2007-04-17 Jeffrey Stedfast * 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 | 13 +++ mcs/class/corlib/System/TermInfoDriver.cs | 102 +++++++++++----------- 2 files changed, 65 insertions(+), 50 deletions(-) diff --git a/mcs/class/corlib/System/ChangeLog b/mcs/class/corlib/System/ChangeLog index 4af388f349e..a55cf603cd6 100644 --- a/mcs/class/corlib/System/ChangeLog +++ b/mcs/class/corlib/System/ChangeLog @@ -1,3 +1,16 @@ +2007-04-17 Jeffrey Stedfast + + * 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 * TermInfoDriver.cs (IsSpecialKey): Oops, Enter should not be diff --git a/mcs/class/corlib/System/TermInfoDriver.cs b/mcs/class/corlib/System/TermInfoDriver.cs index b93c89d12f8..cace3cad155 100644 --- a/mcs/class/corlib/System/TermInfoDriver.cs +++ b/mcs/class/corlib/System/TermInfoDriver.cs @@ -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 (); -- 2.25.1