Add new Is*Redirected properties to Console for the 4.5 profile.
authoralexrp <xtzgzorex@gmail.com>
Thu, 29 Sep 2011 16:43:01 +0000 (18:43 +0200)
committeralexrp <xtzgzorex@gmail.com>
Fri, 30 Sep 2011 10:56:27 +0000 (12:56 +0200)
mcs/class/corlib/System/Console.cs
mcs/class/corlib/System/ConsoleDriver.cs

index 138cb57f924f7e54f25a26b484285d30aa28dc03..98d6bfc47685149cab56e29a9f1de857b841a95e 100644 (file)
@@ -89,10 +89,17 @@ namespace System
                        }
                }
 #endif
+
                internal static TextWriter stdout;
                private static TextWriter stderr;
                private static TextReader stdin;
 
+#if NET_4_5
+               static TextWriter console_stdout;
+               static TextWriter console_stderr;
+               static TextReader console_stdin;
+#endif
+
                static Console ()
                {
 #if NET_2_1
@@ -159,6 +166,12 @@ namespace System
                        }
 #endif
 
+#if NET_4_5
+                       console_stderr = stderr;
+                       console_stdout = stdout;
+                       console_stdin = stdin;
+#endif
+
                        GC.SuppressFinalize (stdout);
                        GC.SuppressFinalize (stderr);
                        GC.SuppressFinalize (stdin);
@@ -182,6 +195,26 @@ namespace System
                        }
                }
 
+#if NET_4_5
+               public static bool IsErrorRedirected {
+                       get {
+                               return stderr != console_stderr || ConsoleDriver.IsErrorRedirected;
+                       }
+               }
+
+               public static bool IsOutputRedirected {
+                       get {
+                               return stdout != console_stdout || ConsoleDriver.IsOutputRedirected;
+                       }
+               }
+
+               public static bool IsInputRedirected {
+                       get {
+                               return stdin != console_stdin || ConsoleDriver.IsInputRedirected;
+                       }
+               }
+#endif
+
                private static Stream Open (IntPtr handle, FileAccess access, int bufferSize)
                {
 #if MOONLIGHT
index f9545e36fe009b75e63e56eb9a7e93d041e89598..fe31d18619a78668e1e39c79e00e53858553efbc 100644 (file)
@@ -177,6 +177,24 @@ namespace System {
                        set { driver.WindowWidth = value; }
                }
 
+               public static bool IsErrorRedirected {
+                       get {
+                               return !Isatty (MonoIO.ConsoleError);
+                       }
+               }
+
+               public static bool IsOutputRedirected {
+                       get {
+                               return !Isatty (MonoIO.ConsoleOutput);
+                       }
+               }
+
+               public static bool IsInputRedirected {
+                       get {
+                               return !Isatty (MonoIO.ConsoleInput);
+                       }
+               }
+
                public static void Beep (int frequency, int duration)
                {
                        driver.Beep (frequency, duration);