static Console() { #if NET_2_1 Encoding inputEncoding; Encoding outputEncoding; #endif if (Environment.IsRunningOnWindows) { // // On Windows, follow the Windows tradition // #if NET_2_1 // should never happen since Moonlight does not run on windows inputEncoding = outputEncoding = Encoding.Default; #else try { inputEncoding = Encoding.GetEncoding(WindowsConsole.GetInputCodePage()); outputEncoding = Encoding.GetEncoding(WindowsConsole.GetOutputCodePage()); // ArgumentException and NotSupportedException can be thrown as well } catch { // FIXME: I18N assemblies are not available when compiling mcs // Use Latin 1 as it is fast and UTF-8 is never used as console code page inputEncoding = outputEncoding = Encoding.Default; } #endif } else { // // On Unix systems (128), do not output the // UTF-8 ZWNBSP (zero-width non-breaking space). // int code_page = 0; Encoding.InternalCodePage(ref code_page); if (code_page != -1 && ((code_page & 0x0fffffff) == 3 || // UTF8Encoding.UTF8_CODE_PAGE ((code_page & 0x10000000) != 0))) { inputEncoding = outputEncoding = Encoding.UTF8Unmarked; } else { inputEncoding = outputEncoding = Encoding.Default; } } SetupStreams(inputEncoding, outputEncoding); }
static Console() { #if NET_2_1 Encoding inputEncoding; Encoding outputEncoding; #endif if (Environment.IsRunningOnWindows) { // // On Windows, follow the Windows tradition // #if NET_2_1 // should never happen since Moonlight does not run on windows inputEncoding = outputEncoding = Encoding.Default; #else try { inputEncoding = Encoding.GetEncoding(WindowsConsole.GetInputCodePage()); outputEncoding = Encoding.GetEncoding(WindowsConsole.GetOutputCodePage()); // ArgumentException and NotSupportedException can be thrown as well } catch { // FIXME: I18N assemblies are not available when compiling mcs // Use Latin 1 as it is fast and UTF-8 is never used as console code page inputEncoding = outputEncoding = Encoding.Default; } #endif } else { // // On Unix systems (128), do not output the // UTF-8 ZWNBSP (zero-width non-breaking space). // int code_page = 0; Encoding.InternalCodePage(ref code_page); if (code_page != -1 && ( (code_page & 0x0fffffff) == 3 || // UTF8Encoding.UTF8_CODE_PAGE ((code_page & 0x10000000) != 0) ) ) { inputEncoding = outputEncoding = Encoding.UTF8Unmarked; } else { inputEncoding = outputEncoding = Encoding.Default; } } stderr = new UnexceptionalStreamWriter(OpenStandardError(0), outputEncoding); ((StreamWriter)stderr).AutoFlush = true; stderr = TextWriter.Synchronized(stderr, true); #if !NET_2_1 if (!Environment.IsRunningOnWindows && ConsoleDriver.IsConsole) { StreamWriter w = new CStreamWriter(OpenStandardOutput(0), outputEncoding); w.AutoFlush = true; stdout = TextWriter.Synchronized(w, true); stdin = new CStreamReader(OpenStandardInput(0), inputEncoding); } else { #endif stdout = new UnexceptionalStreamWriter(OpenStandardOutput(0), outputEncoding); ((StreamWriter)stdout).AutoFlush = true; stdout = TextWriter.Synchronized(stdout, true); stdin = new UnexceptionalStreamReader(OpenStandardInput(0), inputEncoding); stdin = TextReader.Synchronized(stdin); #if !NET_2_1 } #endif GC.SuppressFinalize(stdout); GC.SuppressFinalize(stderr); GC.SuppressFinalize(stdin); }