2006-02-11 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Sat, 11 Feb 2006 20:35:51 +0000 (20:35 -0000)
committerZoltan Varga <vargaz@gmail.com>
Sat, 11 Feb 2006 20:35:51 +0000 (20:35 -0000)
* TermInfoDriver.cs (GetWindowDimensions): Obtain the exact terminal
size using an icall.
(GetCursorPosition): Convert the row and column to 0 based indexing.
Also fix reading of large values.
(CreateKeyInfoFromInt): Convert LF to ConsoleKey.Enter.

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

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

index 56d5b86fd0f176753161eb0d6b05b1e5d4bb3365..8fbd10d1918726e6eb88054a5432ef260f5f7c8a 100644 (file)
@@ -1,3 +1,13 @@
+2006-02-11  Zoltan Varga  <vargaz@gmail.com>
+
+       * TermInfoDriver.cs (GetWindowDimensions): Obtain the exact terminal
+       size using an icall.
+       (GetCursorPosition): Convert the row and column to 0 based indexing. 
+       Also fix reading of large values.
+       (CreateKeyInfoFromInt): Convert LF to ConsoleKey.Enter.
+
+       * ConsoleDriver.cs (GetTtySize): New icall.
+
 2006-02-10  Zoltan Varga  <vargaz@gmail.com>
 
        * Array.cs: Fix some methods which previously returned Nullable<T>.
index 039ae8926cf82af3d291bb2bfc194008b8dc272d..44b21638d6fb0e49a69ce5dc152127f954b55eb7 100644 (file)
@@ -222,6 +222,9 @@ namespace System {
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                internal static extern bool SetBreak (bool wantBreak);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal static extern bool GetTtySize (IntPtr handle, out int width, out int height);
        }
 }
 #endif
index 67cb1a069c186f795ba4862140b8a4de75fb1c39..1fa51c833f2d025845c09fbbfb8a526146f4dc56 100644 (file)
@@ -299,18 +299,24 @@ namespace System {
                                if (b != ';') {
                                        row = b - '0';
                                        b = stdin.ReadByte ();
-                                       if (b != ';')
+                                       while ((b >= '0') && (b <= '9')) {
                                                row = row * 10 + b - '0';
+                                               b = stdin.ReadByte ();
+                                       }
+                                       // Row/col is 0 based
+                                       row --;
                                }
 
                                b = stdin.ReadByte ();
                                if (b != 'R') {
                                        col = b - '0';
                                        b = stdin.ReadByte ();
-                                       if (b != 'R') {
+                                       while ((b >= '0') && (b <= '9')) {
                                                col = col * 10 + b - '0';
-                                               stdin.ReadByte (); // This should be the 'R'
+                                               b = stdin.ReadByte ();
                                        }
+                                       // Row/col is 0 based
+                                       col --;
                                }
                        } finally {
                                Echo = prevEcho;
@@ -445,21 +451,25 @@ namespace System {
                void GetWindowDimensions ()
                {
                        //TODO: Handle SIGWINCH
-                       windowWidth = reader.Get (TermInfoNumbers.Columns);
-                       string env = Environment.GetEnvironmentVariable ("COLUMNS");
-                       if (env != null) {
-                               try {
-                                       windowWidth = (int) UInt32.Parse (env);
-                               } catch {
+
+                       /* Try the ioctl first */
+                       if (!ConsoleDriver.GetTtySize (MonoIO.ConsoleOutput, out windowWidth, out windowHeight)) {
+                               windowWidth = reader.Get (TermInfoNumbers.Columns);
+                               string env = Environment.GetEnvironmentVariable ("COLUMNS");
+                               if (env != null) {
+                                       try {
+                                               windowWidth = (int) UInt32.Parse (env);
+                                       } catch {
+                                       }
                                }
-                       }
 
-                       windowHeight = reader.Get (TermInfoNumbers.Lines);
-                       env = Environment.GetEnvironmentVariable ("LINES");
-                       if (env != null) {
-                               try {
-                                       windowHeight = (int) UInt32.Parse (env);
-                               } catch {
+                               windowHeight = reader.Get (TermInfoNumbers.Lines);
+                               env = Environment.GetEnvironmentVariable ("LINES");
+                               if (env != null) {
+                                       try {
+                                               windowHeight = (int) UInt32.Parse (env);
+                                       } catch {
+                                       }
                                }
                        }
 
@@ -543,8 +553,11 @@ namespace System {
                        bool shift = false;
                        bool ctrl = false;
                        bool alt = false;
-                       // For Ctrl-a to Ctrl-z. Exception: those values in ConsoleKey
-                       if (n >= 1 && n <= 26 && !(n == 8 || n == 9 || n == 12 || n == 13 || n == 19)) {
+
+                       if (n == 10) {
+                               key = ConsoleKey.Enter;
+                       } else if (n >= 1 && n <= 26 && !(n == 8 || n == 9 || n == 12 || n == 13 || n == 19)) {
+                               // For Ctrl-a to Ctrl-z. Exception: those values in ConsoleKey
                                ctrl = true;
                                key = ConsoleKey.A + n - 1;
                        } else if (n == 27) {