internal static bool TryGetPSReadLineProxy( ILogger logger, Runspace runspace, out PSReadLineProxy readLineProxy) { readLineProxy = null; using (var pwsh = PowerShell.Create()) { pwsh.Runspace = runspace; var psReadLineType = pwsh .AddScript(ReadLineInitScript) .Invoke <Type>() .FirstOrDefault(); if (psReadLineType == null) { return(false); } try { readLineProxy = new PSReadLineProxy(psReadLineType, logger); } catch (InvalidOperationException) { // The Type we got back from PowerShell doesn't have the members we expected. // Could be an older version, a custom build, or something a newer version with // breaking changes. return(false); } } return(true); }
internal PSReadLinePromptContext( PowerShellContext powerShellContext, PromptNest promptNest, InvocationEventQueue invocationEventQueue, PSReadLineProxy readLineProxy) { _promptNest = promptNest; _powerShellContext = powerShellContext; _invocationEventQueue = invocationEventQueue; _consoleReadLine = new ConsoleReadLine(powerShellContext); _readLineProxy = readLineProxy; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return; } _readLineProxy.OverrideReadKey( intercept => ConsoleProxy.UnixReadKey( intercept, _readLineCancellationSource.Token)); }