From a9f6fd69b362f0c4f986bd7bf241bf5ef7d06dce Mon Sep 17 00:00:00 2001 From: Mitchell Hwang Date: Fri, 4 Sep 2020 17:31:48 -0400 Subject: [PATCH] [wasm] Mark System.Console APIs as unsupported on Browser (#41184) * [wasm] Mark System.Console APIs as unsupported on Browser * System.Console remove unsupported attribute from Console.Clear() * System.Console mark SetIn as unsupported on Browser * System.Console move UnsupportedOSPlatform attributes down to the accessor Co-authored-by: Mitchell Hwang --- src/libraries/System.Console/ref/System.Console.cs | 35 +++++++++++++++++----- src/libraries/System.Console/src/System/Console.cs | 28 +++++++++++++++++ 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Console/ref/System.Console.cs b/src/libraries/System.Console/ref/System.Console.cs index b3faa64..7a342d5 100644 --- a/src/libraries/System.Console/ref/System.Console.cs +++ b/src/libraries/System.Console/ref/System.Console.cs @@ -8,40 +8,52 @@ namespace System { public static partial class Console { + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.ConsoleColor BackgroundColor { get { throw null; } set { } } - public static int BufferHeight { get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } - public static int BufferWidth { get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } + public static int BufferHeight { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } + public static int BufferWidth { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public static bool CapsLock { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static int CursorLeft { get { throw null; } set { } } - public static int CursorSize { get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } + public static int CursorSize { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static int CursorTop { get { throw null; } set { } } - public static bool CursorVisible { [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] get { throw null; } set { } } + public static bool CursorVisible { [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] get { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] set { } } public static System.IO.TextWriter Error { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.ConsoleColor ForegroundColor { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.IO.TextReader In { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.Text.Encoding InputEncoding { get { throw null; } set { } } public static bool IsErrorRedirected { get { throw null; } } public static bool IsInputRedirected { get { throw null; } } public static bool IsOutputRedirected { get { throw null; } } public static bool KeyAvailable { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static int LargestWindowHeight { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static int LargestWindowWidth { get { throw null; } } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public static bool NumberLock { get { throw null; } } public static System.IO.TextWriter Out { get { throw null; } } public static System.Text.Encoding OutputEncoding { get { throw null; } set { } } - public static string Title { [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] get { throw null; } set { } } + public static string Title { [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] get { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool TreatControlCAsInput { get { throw null; } set { } } - public static int WindowHeight { get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } + public static int WindowHeight { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } public static int WindowLeft { get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } public static int WindowTop { get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } - public static int WindowWidth { get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } + public static int WindowWidth { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static event System.ConsoleCancelEventHandler? CancelKeyPress { add { } remove { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static void Beep() { } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public static void Beep(int frequency, int duration) { } public static void Clear() { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static (int Left, int Top) GetCursorPosition() { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public static void MoveBufferArea(int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop) { } @@ -49,19 +61,28 @@ namespace System public static void MoveBufferArea(int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop, char sourceChar, System.ConsoleColor sourceForeColor, System.ConsoleColor sourceBackColor) { } public static System.IO.Stream OpenStandardError() { throw null; } public static System.IO.Stream OpenStandardError(int bufferSize) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.IO.Stream OpenStandardInput() { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.IO.Stream OpenStandardInput(int bufferSize) { throw null; } public static System.IO.Stream OpenStandardOutput() { throw null; } public static System.IO.Stream OpenStandardOutput(int bufferSize) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static int Read() { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.ConsoleKeyInfo ReadKey() { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.ConsoleKeyInfo ReadKey(bool intercept) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static string? ReadLine() { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static void ResetColor() { } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public static void SetBufferSize(int width, int height) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static void SetCursorPosition(int left, int top) { } public static void SetError(System.IO.TextWriter newError) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static void SetIn(System.IO.TextReader newIn) { } public static void SetOut(System.IO.TextWriter newOut) { } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] diff --git a/src/libraries/System.Console/src/System/Console.cs b/src/libraries/System.Console/src/System/Console.cs index ec58985..b4f2270 100644 --- a/src/libraries/System.Console/src/System/Console.cs +++ b/src/libraries/System.Console/src/System/Console.cs @@ -33,6 +33,7 @@ namespace System private static ConsoleCancelEventHandler? s_cancelCallbacks; private static ConsolePal.ControlCHandlerRegistrar? s_registrar; + [UnsupportedOSPlatform("browser")] public static TextReader In { get @@ -56,6 +57,7 @@ namespace System } } + [UnsupportedOSPlatform("browser")] public static Encoding InputEncoding { get @@ -152,11 +154,13 @@ namespace System } } + [UnsupportedOSPlatform("browser")] public static ConsoleKeyInfo ReadKey() { return ConsolePal.ReadKey(false); } + [UnsupportedOSPlatform("browser")] public static ConsoleKeyInfo ReadKey(bool intercept) { return ConsolePal.ReadKey(intercept); @@ -276,6 +280,7 @@ namespace System public static int CursorSize { + [UnsupportedOSPlatform("browser")] get { return ConsolePal.CursorSize; } [SupportedOSPlatform("windows")] set { ConsolePal.CursorSize = value; } @@ -295,18 +300,21 @@ namespace System internal const ConsoleColor UnknownColor = (ConsoleColor)(-1); + [UnsupportedOSPlatform("browser")] public static ConsoleColor BackgroundColor { get { return ConsolePal.BackgroundColor; } set { ConsolePal.BackgroundColor = value; } } + [UnsupportedOSPlatform("browser")] public static ConsoleColor ForegroundColor { get { return ConsolePal.ForegroundColor; } set { ConsolePal.ForegroundColor = value; } } + [UnsupportedOSPlatform("browser")] public static void ResetColor() { ConsolePal.ResetColor(); @@ -314,6 +322,7 @@ namespace System public static int BufferWidth { + [UnsupportedOSPlatform("browser")] get { return ConsolePal.BufferWidth; } [SupportedOSPlatform("windows")] set { ConsolePal.BufferWidth = value; } @@ -321,6 +330,7 @@ namespace System public static int BufferHeight { + [UnsupportedOSPlatform("browser")] get { return ConsolePal.BufferHeight; } [SupportedOSPlatform("windows")] set { ConsolePal.BufferHeight = value; } @@ -348,6 +358,7 @@ namespace System public static int WindowWidth { + [UnsupportedOSPlatform("browser")] get { return ConsolePal.WindowWidth; } [SupportedOSPlatform("windows")] set { ConsolePal.WindowWidth = value; } @@ -355,6 +366,7 @@ namespace System public static int WindowHeight { + [UnsupportedOSPlatform("browser")] get { return ConsolePal.WindowHeight; } [SupportedOSPlatform("windows")] set { ConsolePal.WindowHeight = value; } @@ -372,11 +384,13 @@ namespace System ConsolePal.SetWindowSize(width, height); } + [UnsupportedOSPlatform("browser")] public static int LargestWindowWidth { get { return ConsolePal.LargestWindowWidth; } } + [UnsupportedOSPlatform("browser")] public static int LargestWindowHeight { get { return ConsolePal.LargestWindowHeight; } @@ -386,15 +400,18 @@ namespace System { [SupportedOSPlatform("windows")] get { return ConsolePal.CursorVisible; } + [UnsupportedOSPlatform("browser")] set { ConsolePal.CursorVisible = value; } } + [UnsupportedOSPlatform("browser")] public static int CursorLeft { get { return ConsolePal.GetCursorPosition().Left; } set { SetCursorPosition(value, CursorTop); } } + [UnsupportedOSPlatform("browser")] public static int CursorTop { get { return ConsolePal.GetCursorPosition().Top; } @@ -406,6 +423,7 @@ namespace System /// /// Columns are numbered from left to right starting at 0. Rows are numbered from top to bottom starting at 0. /// + [UnsupportedOSPlatform("browser")] public static (int Left, int Top) GetCursorPosition() { return ConsolePal.GetCursorPosition(); @@ -415,12 +433,14 @@ namespace System { [SupportedOSPlatform("windows")] get { return ConsolePal.Title; } + [UnsupportedOSPlatform("browser")] set { ConsolePal.Title = value ?? throw new ArgumentNullException(nameof(value)); } } + [UnsupportedOSPlatform("browser")] public static void Beep() { ConsolePal.Beep(); @@ -449,6 +469,7 @@ namespace System ConsolePal.Clear(); } + [UnsupportedOSPlatform("browser")] public static void SetCursorPosition(int left, int top) { // Basic argument validation. The PAL implementation may provide further validation. @@ -460,6 +481,7 @@ namespace System ConsolePal.SetCursorPosition(left, top); } + [UnsupportedOSPlatform("browser")] public static event ConsoleCancelEventHandler? CancelKeyPress { add @@ -493,17 +515,20 @@ namespace System } } + [UnsupportedOSPlatform("browser")] public static bool TreatControlCAsInput { get { return ConsolePal.TreatControlCAsInput; } set { ConsolePal.TreatControlCAsInput = value; } } + [UnsupportedOSPlatform("browser")] public static Stream OpenStandardInput() { return ConsolePal.OpenStandardInput(); } + [UnsupportedOSPlatform("browser")] public static Stream OpenStandardInput(int bufferSize) { // bufferSize is ignored, other than in argument validation, even in the .NET Framework @@ -544,6 +569,7 @@ namespace System return OpenStandardError(); } + [UnsupportedOSPlatform("browser")] public static void SetIn(TextReader newIn) { CheckNonNull(newIn, nameof(newIn)); @@ -590,12 +616,14 @@ namespace System // the inlined console writelines from them. // [MethodImplAttribute(MethodImplOptions.NoInlining)] + [UnsupportedOSPlatform("browser")] public static int Read() { return In.Read(); } [MethodImplAttribute(MethodImplOptions.NoInlining)] + [UnsupportedOSPlatform("browser")] public static string? ReadLine() { return In.ReadLine(); -- 2.7.4