Author: gonzalo
Date: 2006-11-27 20:00:08 -0500 (Mon, 27 Nov 2006)
New Revision: 68547

Modified:
   trunk/mcs/class/corlib/System/ChangeLog
   trunk/mcs/class/corlib/System/Console.cs
   trunk/mcs/class/corlib/System/TermInfoDriver.cs
Log:
2006-11-27 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * TermInfoDriver.cs:
        * Console.cs: lazy initialization of Console 2.0 (also when
        CancelKeyPress is used).



Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog     2006-11-28 00:58:24 UTC (rev 
68546)
+++ trunk/mcs/class/corlib/System/ChangeLog     2006-11-28 01:00:08 UTC (rev 
68547)
@@ -1,3 +1,9 @@
+2006-11-27 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * TermInfoDriver.cs:
+       * Console.cs: lazy initialization of Console 2.0 (also when
+       CancelKeyPress is used).
+
 2006-11-27  Miguel de Icaza  <[EMAIL PROTECTED]>
 
        * Exception.cs (GetType): New method in 2.x, Another Moma catch. 

Modified: trunk/mcs/class/corlib/System/Console.cs
===================================================================
--- trunk/mcs/class/corlib/System/Console.cs    2006-11-28 00:58:24 UTC (rev 
68546)
+++ trunk/mcs/class/corlib/System/Console.cs    2006-11-28 01:00:08 UTC (rev 
68547)
@@ -114,7 +114,6 @@
                                w.AutoFlush = true;
                                stdout = w;
                                stdin = new CStreamReader (OpenStandardInput 
(0), inputEncoding);
-                               ConsoleDriver.Init ();
                        } else {
 #endif
                                stdout = new UnexceptionalStreamWriter 
(OpenStandardOutput (0), outputEncoding);
@@ -646,17 +645,31 @@
                        ConsoleDriver.SetWindowSize (width, height);
                }
 
-               public static event ConsoleCancelEventHandler CancelKeyPress;
+               static ConsoleCancelEventHandler cancel_event;
+               public static event ConsoleCancelEventHandler CancelKeyPress {
+                       add {
+                               if (ConsoleDriver.Initialized == false)
+                                       ConsoleDriver.Init ();
 
+                               cancel_event += value;
+                       }
+                       remove {
+                               if (ConsoleDriver.Initialized == false)
+                                       ConsoleDriver.Init ();
+
+                               cancel_event -= value;
+                       }
+               }
+
                delegate void InternalCancelHandler ();
                static InternalCancelHandler cancel_handler = new 
InternalCancelHandler (DoConsoleCancelEvent);
 
                internal static void DoConsoleCancelEvent ()
                {
                        bool exit = true;
-                       if (CancelKeyPress != null) {
+                       if (cancel_event != null) {
                                ConsoleCancelEventArgs args = new 
ConsoleCancelEventArgs (ConsoleSpecialKey.ControlC);
-                               Delegate [] delegates = 
CancelKeyPress.GetInvocationList ();
+                               Delegate [] delegates = 
cancel_event.GetInvocationList ();
                                foreach (ConsoleCancelEventHandler d in 
delegates){
                                        try {
                                                // Sender is always null here.

Modified: trunk/mcs/class/corlib/System/TermInfoDriver.cs
===================================================================
--- trunk/mcs/class/corlib/System/TermInfoDriver.cs     2006-11-28 00:58:24 UTC 
(rev 68546)
+++ trunk/mcs/class/corlib/System/TermInfoDriver.cs     2006-11-28 01:00:08 UTC 
(rev 68547)
@@ -149,7 +149,7 @@
                public bool Initialized {
                        get { return inited; }
                }
-               
+
                public void Init ()
                {
                        if (inited)
@@ -281,6 +281,9 @@
 
                public bool NotifyWrite (ConsoleKeyInfo key)
                {
+                       if (!inited)
+                               return true;
+
                        switch (key.Key) {
                        case ConsoleKey.Backspace:
                                if (cursorLeft > 0) {
@@ -329,16 +332,36 @@
                }
 
                public ConsoleColor BackgroundColor {
-                       get { return bgcolor; }
+                       get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
+                               return bgcolor;
+                       }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                bgcolor = value;
                                WriteConsole (String.Format (setabcolor, 
TranslateColor (value)));
                        }
                }
 
                public ConsoleColor ForegroundColor {
-                       get { return fgcolor; }
+                       get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
+                               return fgcolor;
+                       }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                fgcolor = value;
                                WriteConsole (String.Format (setafcolor, 
TranslateColor (value)));
                        }
@@ -405,31 +428,61 @@
 
                public int BufferHeight {
                        get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                return bufferHeight;
                        }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                throw new NotSupportedException ();
                        }
                }
 
                public int BufferWidth {
                        get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                return bufferWidth;
                        }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                throw new NotSupportedException ();
                        }
                }
 
                public bool CapsLock {
-                       get { throw new NotSupportedException (); }
+                       get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
+                               throw new NotSupportedException ();
+                       }
                }
 
                public int CursorLeft {
                        get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                return cursorLeft;
                        }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                SetCursorPosition (value, CursorTop);
                                cursorLeft = value;
                        }
@@ -437,9 +490,17 @@
 
                public int CursorTop {
                        get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                return cursorTop;
                        }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                SetCursorPosition (CursorLeft, value);
                                cursorTop = value;
                        }
@@ -447,9 +508,17 @@
 
                public bool CursorVisible {
                        get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                return cursorVisible;
                        }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                cursorVisible = value;
                                WriteConsole ((value ? csrVisible : 
csrInvisible));
                        }
@@ -458,13 +527,33 @@
                // we have CursorNormal vs. CursorVisible...
                [MonoTODO]
                public int CursorSize {
-                       get { return 1; }
-                       set {}
+                       get {
+                               if (!inited) {
+                                       Init ();
+                               }
+                               return 1;
+                       }
+                       set {
+                               if (!inited) {
+                                       Init ();
+                               }
+                       }
+
                }
 
                public bool Echo {
-                       get { return !noEcho; }
+                       get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
+                               return !noEcho;
+                       }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                if (value != noEcho)
                                        return;
 
@@ -474,6 +563,10 @@
 
                public bool KeyAvailable {
                        get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                return (writepos > readpos || 
ConsoleDriver.InternalKeyAvailable (0) > 0);
                        }
                }
@@ -488,21 +581,45 @@
                }
 
                public bool NumberLock {
-                       get { throw new NotSupportedException (); }
+                       get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
+                               throw new NotSupportedException ();
+                       }
                }
 
                public string Title {
-                       get { return title; }
+                       get {
+                               if (!inited) {
+                                       Init ();
+                               }
+                               return title;
+                       }
                        
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                title = value;
                                WriteConsole (String.Format (titleFormat, 
value));
                        }
                }
 
                public bool TreatControlCAsInput {
-                       get { return controlCAsInput; }
+                       get {
+                               if (!inited) {
+                                       Init ();
+                               }
+                               return controlCAsInput;
+                       }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                if (controlCAsInput == value)
                                        return;
 
@@ -541,51 +658,91 @@
 
                public int WindowHeight {
                        get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                GetWindowDimensions ();
                                return windowHeight;
                        }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                throw new NotSupportedException ();
                        }
                }
 
                public int WindowLeft {
                        get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                //GetWindowDimensions ();
                                return 0;
                        }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                throw new NotSupportedException ();
                        }
                }
 
                public int WindowTop {
                        get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                //GetWindowDimensions ();
                                return 0;
                        }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                throw new NotSupportedException ();
                        }
                }
 
                public int WindowWidth {
                        get {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                GetWindowDimensions ();
                                return windowWidth;
                        }
                        set {
+                               if (!inited) {
+                                       Init ();
+                               }
+
                                throw new NotSupportedException ();
                        }
                }
 
                public void Clear ()
                {
+                       if (!inited) {
+                               Init ();
+                       }
+
                        WriteConsole (clear);
                }
 
                public void Beep (int frequency, int duration)
                {
+                       if (!inited) {
+                               Init ();
+                       }
+
                        WriteConsole (bell);
                }
 
@@ -593,6 +750,10 @@
                                        int targetLeft, int targetTop, Char 
sourceChar,
                                        ConsoleColor sourceForeColor, 
ConsoleColor sourceBackColor)
                {
+                       if (!inited) {
+                               Init ();
+                       }
+
                        throw new NotImplementedException ();
                }
 
@@ -667,6 +828,10 @@
 
                ConsoleKeyInfo ReadKeyInternal ()
                {
+                       if (!inited) {
+                               Init ();
+                       }
+
                        InitKeys ();
                        object o = null;
                        while (o == null) {
@@ -689,6 +854,9 @@
 
                public ConsoleKeyInfo ReadKey (bool intercept)
                {
+                       if (!inited)
+                               Init ();
+
                        bool prevEcho = Echo;
                        if (prevEcho == intercept)
                                Echo  = !intercept;
@@ -702,6 +870,9 @@
 
                public string ReadLine ()
                {
+                       if (!inited)
+                               Init ();
+
                        bool prevEcho = Echo;
                        if (prevEcho == false)
                                Echo  = true;
@@ -730,17 +901,29 @@
 
                public void ResetColor ()
                {
+                       if (!inited) {
+                               Init ();
+                       }
+
                        string str = (origPair != null) ? origPair : origColors;
                        WriteConsole (str);
                }
 
                public void SetBufferSize (int width, int height)
                {
+                       if (!inited) {
+                               Init ();
+                       }
+
                        throw new NotImplementedException (String.Empty);
                }
 
                public void SetCursorPosition (int left, int top)
                {
+                       if (!inited) {
+                               Init ();
+                       }
+
                        if (bufferWidth == 0)
                                GetWindowDimensions ();
 
@@ -763,12 +946,20 @@
 
                public void SetWindowPosition (int left, int top)
                {
+                       if (!inited) {
+                               Init ();
+                       }
+
                        // No need to throw exceptions here.
                        //throw new NotSupportedException ();
                }
 
                public void SetWindowSize (int width, int height)
                {
+                       if (!inited) {
+                               Init ();
+                       }
+
                        // No need to throw exceptions here.
                        //throw new NotSupportedException ();
                }

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

Reply via email to