diff --git a/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs b/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs index 52ea70efe..71accf212 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs @@ -62,7 +62,7 @@ public override IReadOnlyList Run(CancellationToken cancellationToken) if (PowerShellExecutionOptions.WriteInputToHost) { - _psesHost.UI.WriteLine(_psCommand.GetInvocationText()); + _psesHost.WriteWithPrompt(_psCommand, cancellationToken); } return _pwsh.Runspace.Debugger.InBreakpoint diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs index 8b2fd79ad..0d674b64c 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs @@ -770,7 +770,7 @@ private void DoOneRepl(CancellationToken cancellationToken) // one, but we do not want to print one if the ReadLine task was canceled. if (string.IsNullOrEmpty(userInput)) { - if (LastKeyWasCtrlC()) + if (cancellationToken.IsCancellationRequested || LastKeyWasCtrlC()) { UI.WriteLine(); } @@ -836,6 +836,19 @@ private string GetPrompt(CancellationToken cancellationToken) return prompt; } + /// + /// This is used to write the invocation text of a command with the user's prompt so that, + /// for example, F8 (evaluate selection) appears as if the user typed it. Used when + /// 'WriteInputToHost' is true. + /// + /// The PSCommand we'll print after the prompt. + /// + public void WriteWithPrompt(PSCommand command, CancellationToken cancellationToken) + { + UI.Write(GetPrompt(cancellationToken)); + UI.WriteLine(command.GetInvocationText()); + } + private string InvokeReadLine(CancellationToken cancellationToken) { try