Skip to content

Commit 3daba99

Browse files
Override PSRL ReadKey on Windows as well (#1072)
1 parent bb4244e commit 3daba99

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

Diff for: src/PowerShellEditorServices/Services/PowerShellContext/Console/ConsoleProxy.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,9 @@ public static Task<int> GetCursorTopAsync(CancellationToken cancellationToken) =
163163
s_consoleProxy.GetCursorTopAsync(cancellationToken);
164164

165165
/// <summary>
166-
/// On Unix platforms this method is sent to PSReadLine as a work around for issues
167-
/// with the System.Console implementation for that platform. Functionally it is the
168-
/// same as System.Console.ReadKey, with the exception that it will not lock the
169-
/// standard input stream.
166+
/// This method is sent to PSReadLine as a workaround for issues with the System.Console
167+
/// implementation. Functionally it is the same as System.Console.ReadKey,
168+
/// with the exception that it will not lock the standard input stream.
170169
/// </summary>
171170
/// <param name="intercept">
172171
/// Determines whether to display the pressed key in the console window.
@@ -181,11 +180,11 @@ public static Task<int> GetCursorTopAsync(CancellationToken cancellationToken) =
181180
/// in a bitwise combination of ConsoleModifiers values, whether one or more Shift, Alt,
182181
/// or Ctrl modifier keys was pressed simultaneously with the console key.
183182
/// </returns>
184-
internal static ConsoleKeyInfo UnixReadKey(bool intercept, CancellationToken cancellationToken)
183+
internal static ConsoleKeyInfo SafeReadKey(bool intercept, CancellationToken cancellationToken)
185184
{
186185
try
187186
{
188-
return ((UnixConsoleOperations)s_consoleProxy).ReadKey(intercept, cancellationToken);
187+
return s_consoleProxy.ReadKey(intercept, cancellationToken);
189188
}
190189
catch (OperationCanceledException)
191190
{

Diff for: src/PowerShellEditorServices/Services/PowerShellContext/Session/PSReadLinePromptContext.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,9 @@ internal PSReadLinePromptContext(
6868
_consoleReadLine = new ConsoleReadLine(powerShellContext);
6969
_readLineProxy = readLineProxy;
7070

71-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
72-
{
73-
return;
74-
}
7571

7672
_readLineProxy.OverrideReadKey(
77-
intercept => ConsoleProxy.UnixReadKey(
73+
intercept => ConsoleProxy.SafeReadKey(
7874
intercept,
7975
_readLineCancellationSource.Token));
8076
}

0 commit comments

Comments
 (0)