2008-08-27 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / class / corlib / System / ConsoleDriver.cs
index d2b552d84119aa1d737ebc6fa44052c89e342ca4..50ea05122767e77eccedae6041c71ffc39f0b6d7 100644 (file)
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-#if NET_2_0
+#if (NET_2_0||BOOTSTRAP_NET_2_0) && !NET_2_1
 using System.IO;
 using System.Runtime.CompilerServices;
 
 namespace System {
        class ConsoleDriver {
-               static IConsoleDriver driver;
+               internal static IConsoleDriver driver;
                static bool is_console;
                static bool called_isatty;
 
                static ConsoleDriver ()
                {
-                       if (Environment.IsRunningOnWindows) {
-                               driver = new WindowsConsoleDriver ();
+                       // Put the actual new statements into separate methods to avoid initalizing
+                       // three classes when only one is needed.
+                       if (!IsConsole) {
+                               driver = CreateNullConsoleDriver ();
+                       } else if (Environment.IsRunningOnWindows) {
+                               driver = CreateWindowsConsoleDriver ();
                        } else {
-                               driver = new TermInfoDriver (Environment.GetEnvironmentVariable ("TERM"));
+                               string term = Environment.GetEnvironmentVariable ("TERM");
+
+                               // Perhaps we should let the Terminfo driver return a
+                               // success/failure flag based on the terminal properties
+                               if (term == "dumb"){
+                                       is_console = false;
+                                       driver = CreateNullConsoleDriver ();
+                               } else
+                                       driver = CreateTermInfoDriver (term);
                        }
                }
 
-               public static bool Echo {
-                       get { return driver.Echo; }
-                       set { driver.Echo = value; }
+               [MethodImplAttribute (MethodImplOptions.NoInlining)]
+               static IConsoleDriver CreateNullConsoleDriver () {
+                       return new NullConsoleDriver ();
                }
 
+               [MethodImplAttribute (MethodImplOptions.NoInlining)]
+               static IConsoleDriver CreateWindowsConsoleDriver () {
+                       return new WindowsConsoleDriver ();
+               }
+
+               [MethodImplAttribute (MethodImplOptions.NoInlining)]
+               static IConsoleDriver CreateTermInfoDriver (string term) {
+                       return new TermInfoDriver (term);
+               }
+               
                public static bool Initialized {
                        get { return driver.Initialized; }
                }
@@ -180,6 +202,11 @@ namespace System {
                                        targetLeft, targetTop, sourceChar, sourceForeColor, sourceBackColor);
                }
 
+               public static void Init ()
+               {
+                       driver.Init ();
+               }
+
                public static int Read ()
                {
                        return ReadKey (false).KeyChar;
@@ -238,7 +265,7 @@ namespace System {
                internal static extern int InternalKeyAvailable (int ms_timeout);
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal static extern bool TtySetup (string teardown, out byte verase, out byte vsusp, out byte intr);
+               internal static extern bool TtySetup (string keypadXmit, string teardown, out byte verase, out byte vsusp, out byte intr);
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                internal static extern bool SetEcho (bool wantEcho);
@@ -248,9 +275,6 @@ namespace System {
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                internal static extern bool GetTtySize (IntPtr handle, out int width, out int height);
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal static extern void Suspend ();
        }
 }
 #endif