Skip to content

Override PSRL ReadKey on Windows as well #1072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ public static Task<int> GetCursorTopAsync(CancellationToken cancellationToken) =
s_consoleProxy.GetCursorTopAsync(cancellationToken);

/// <summary>
/// On Unix platforms this method is sent to PSReadLine as a work around for issues
/// with the System.Console implementation for that platform. Functionally it is the
/// same as System.Console.ReadKey, with the exception that it will not lock the
/// standard input stream.
/// This method is sent to PSReadLine as a workaround for issues with the System.Console
/// implementation. Functionally it is the same as System.Console.ReadKey,
/// with the exception that it will not lock the standard input stream.
/// </summary>
/// <param name="intercept">
/// Determines whether to display the pressed key in the console window.
Expand All @@ -181,11 +180,11 @@ public static Task<int> GetCursorTopAsync(CancellationToken cancellationToken) =
/// in a bitwise combination of ConsoleModifiers values, whether one or more Shift, Alt,
/// or Ctrl modifier keys was pressed simultaneously with the console key.
/// </returns>
internal static ConsoleKeyInfo UnixReadKey(bool intercept, CancellationToken cancellationToken)
internal static ConsoleKeyInfo SafeReadKey(bool intercept, CancellationToken cancellationToken)
{
try
{
return ((UnixConsoleOperations)s_consoleProxy).ReadKey(intercept, cancellationToken);
return s_consoleProxy.ReadKey(intercept, cancellationToken);
}
catch (OperationCanceledException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ internal PSReadLinePromptContext(
_consoleReadLine = new ConsoleReadLine(powerShellContext);
_readLineProxy = readLineProxy;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return;
}

_readLineProxy.OverrideReadKey(
intercept => ConsoleProxy.UnixReadKey(
intercept => ConsoleProxy.SafeReadKey(
intercept,
_readLineCancellationSource.Token));
}
Expand Down