Skip to content

Commit 1b27eda

Browse files
authored
Remove .NET 6 Console Key Parser (#77977)
1 parent 8918adf commit 1b27eda

File tree

11 files changed

+22
-245
lines changed

11 files changed

+22
-245
lines changed

src/libraries/Common/src/Interop/Unix/System.Native/Interop.ReadStdinUnbuffered.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal static partial class Sys
1212
internal static unsafe partial int ReadStdin(byte* buffer, int bufferSize);
1313

1414
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_InitializeConsoleBeforeRead")]
15-
internal static partial void InitializeConsoleBeforeRead([MarshalAs(UnmanagedType.Bool)] bool distinguishNewLines, byte minChars = 1, byte decisecondsTimeout = 0);
15+
internal static partial void InitializeConsoleBeforeRead(byte minChars = 1, byte decisecondsTimeout = 0);
1616

1717
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_UninitializeConsoleAfterRead")]
1818
internal static partial void UninitializeConsoleAfterRead();

src/libraries/Common/src/Interop/Unix/System.Native/Interop.SetSignalForBreak.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ internal static partial class Sys
1212
internal static partial int GetSignalForBreak();
1313

1414
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetSignalForBreak")]
15-
internal static partial int SetSignalForBreak(int signalForBreak, [MarshalAs(UnmanagedType.Bool)] bool distinguishNewLines);
15+
internal static partial int SetSignalForBreak(int signalForBreak);
1616
}
1717
}

src/libraries/Common/src/Interop/Unix/System.Native/Interop.StdinReady.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ internal static partial class Sys
99
{
1010
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_StdinReady")]
1111
[return: MarshalAs(UnmanagedType.Bool)]
12-
internal static partial bool StdinReady([MarshalAs(UnmanagedType.Bool)] bool distinguishNewLines);
12+
internal static partial bool StdinReady();
1313
}
1414
}

src/libraries/Common/src/System/Console/ConsoleUtils.cs

-30
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
5-
64
namespace System
75
{
86
internal static partial class ConsoleUtils
97
{
108
/// <summary>Whether to output ansi color strings.</summary>
119
private static volatile int s_emitAnsiColorCodes = -1;
1210

13-
private static volatile int s_useNet6KeyParser = -1;
14-
1511
/// <summary>Get whether to emit ANSI color codes.</summary>
1612
public static bool EmitAnsiColorCodes
1713
{
@@ -51,31 +47,5 @@ public static bool EmitAnsiColorCodes
5147
return enabled;
5248
}
5349
}
54-
55-
internal static bool UseNet6KeyParser
56-
{
57-
get
58-
{
59-
int useNet6KeyParser = s_useNet6KeyParser;
60-
61-
if (useNet6KeyParser == -1)
62-
{
63-
useNet6KeyParser = s_useNet6KeyParser = GetNet6CompatReadKeySetting() ? 1 : 0;
64-
}
65-
66-
return useNet6KeyParser == 1;
67-
68-
static bool GetNet6CompatReadKeySetting()
69-
{
70-
if (AppContext.TryGetSwitch("System.Console.UseNet6CompatReadKey", out bool fileConfig))
71-
{
72-
return fileConfig;
73-
}
74-
75-
string? envVar = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_CONSOLE_USENET6COMPATREADKEY");
76-
return envVar is not null && (envVar == "1" || envVar.Equals("true", StringComparison.OrdinalIgnoreCase));
77-
}
78-
}
79-
}
8050
}
8151
}

src/libraries/System.Console/src/System.Console.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@
169169
<Compile Include="System\IO\StdInReader.cs" />
170170
<Compile Include="System\IO\SyncTextReader.Unix.cs" />
171171
<Compile Include="System\IO\KeyParser.cs" />
172-
<Compile Include="System\IO\Net6KeyParser.cs" />
173172
<Compile Include="$(CoreLibSharedDir)System\IO\PersistedFiles.Unix.cs"
174173
Link="Common\System\IO\PersistedFiles.Unix.cs" />
175174
<Compile Include="$(CoreLibSharedDir)System\IO\PersistedFiles.Names.Unix.cs"

src/libraries/System.Console/src/System/ConsolePal.Unix.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public static bool TreatControlCAsInput
153153
if (!Console.IsInputRedirected)
154154
{
155155
EnsureConsoleInitialized();
156-
if (Interop.Sys.SetSignalForBreak(Convert.ToInt32(!value), distinguishNewLines: !ConsoleUtils.UseNet6KeyParser) == 0)
156+
if (Interop.Sys.SetSignalForBreak(Convert.ToInt32(!value)) == 0)
157157
throw Interop.GetExceptionForIoErrno(Interop.Sys.GetLastErrorInfo());
158158
}
159159
}
@@ -481,7 +481,7 @@ internal static bool TryGetCursorPosition(out int left, out int top, bool reinit
481481
// involved in reading/writing, such as when accessing a remote system. We also extend
482482
// the timeout on the very first request to 15 seconds, to account for potential latency
483483
// before we know if we will receive a response.
484-
Interop.Sys.InitializeConsoleBeforeRead(distinguishNewLines: !ConsoleUtils.UseNet6KeyParser, minChars: (byte)(s_everReceivedCursorPositionResponse ? 1 : 0), decisecondsTimeout: (byte)(s_firstCursorPositionRequest ? 100 : 10));
484+
Interop.Sys.InitializeConsoleBeforeRead(minChars: (byte)(s_everReceivedCursorPositionResponse ? 1 : 0), decisecondsTimeout: (byte)(s_firstCursorPositionRequest ? 100 : 10));
485485
try
486486
{
487487
// Write out the cursor position report request.
@@ -556,7 +556,7 @@ internal static bool TryGetCursorPosition(out int left, out int top, bool reinit
556556
{
557557
if (reinitializeForRead)
558558
{
559-
Interop.Sys.InitializeConsoleBeforeRead(distinguishNewLines: !ConsoleUtils.UseNet6KeyParser);
559+
Interop.Sys.InitializeConsoleBeforeRead();
560560
}
561561
else
562562
{

src/libraries/System.Console/src/System/IO/Net6KeyParser.cs

-180
This file was deleted.

src/libraries/System.Console/src/System/IO/StdInReader.cs

+4-7
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private bool ReadLineCore(bool consumeKeys)
151151
// Don't carry over chars from previous ReadLine call.
152152
_readLineSB.Clear();
153153

154-
Interop.Sys.InitializeConsoleBeforeRead(distinguishNewLines: !ConsoleUtils.UseNet6KeyParser);
154+
Interop.Sys.InitializeConsoleBeforeRead();
155155
try
156156
{
157157
// Read key-by-key until we've read a line.
@@ -327,8 +327,7 @@ private unsafe ConsoleKeyInfo ReadKey()
327327
{
328328
Debug.Assert(_availableKeys.Count == 0);
329329

330-
bool useNet6KeyParser = ConsoleUtils.UseNet6KeyParser;
331-
Interop.Sys.InitializeConsoleBeforeRead(distinguishNewLines: !useNet6KeyParser);
330+
Interop.Sys.InitializeConsoleBeforeRead();
332331
try
333332
{
334333
if (IsUnprocessedBufferEmpty())
@@ -354,9 +353,7 @@ private unsafe ConsoleKeyInfo ReadKey()
354353
}
355354
}
356355

357-
return useNet6KeyParser
358-
? Net6KeyParser.Parse(_unprocessedBufferToBeRead, ConsolePal.TerminalFormatStringsInstance, ConsolePal.s_posixDisableValue, ConsolePal.s_veraseCharacter, ref _startIndex, _endIndex)
359-
: KeyParser.Parse(_unprocessedBufferToBeRead, ConsolePal.TerminalFormatStringsInstance, ConsolePal.s_posixDisableValue, ConsolePal.s_veraseCharacter, ref _startIndex, _endIndex);
356+
return KeyParser.Parse(_unprocessedBufferToBeRead, ConsolePal.TerminalFormatStringsInstance, ConsolePal.s_posixDisableValue, ConsolePal.s_veraseCharacter, ref _startIndex, _endIndex);
360357
}
361358
finally
362359
{
@@ -365,6 +362,6 @@ private unsafe ConsoleKeyInfo ReadKey()
365362
}
366363

367364
/// <summary>Gets whether there's input waiting on stdin.</summary>
368-
internal static bool StdinReady => Interop.Sys.StdinReady(distinguishNewLines: !ConsoleUtils.UseNet6KeyParser);
365+
internal static bool StdinReady => Interop.Sys.StdinReady();
369366
}
370367
}

src/libraries/System.Console/tests/System.Console.Tests.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<Compile Include="..\src\System\TermInfo.Database.cs" Link="src\System\TermInfo.Database.cs" />
3939
<Compile Include="..\src\System\TerminalFormatStrings.cs" Link="src\System\TerminalFormatStrings.cs" />
4040
<Compile Include="..\src\System\IO\KeyParser.cs" Link="src\System\IO\KeyParser.cs" />
41-
<Compile Include="..\src\System\IO\Net6KeyParser.cs" Link="src\System\IO\Net6KeyParser.cs" />
4241
<Compile Include="$(CommonPath)System\Text\ConsoleEncoding.cs" Link="src\System\Text\ConsoleEncoding.cs" />
4342
<Compile Include="KeyParserTests.cs" />
4443
</ItemGroup>

0 commit comments

Comments
 (0)