Skip to content

Commit 459d717

Browse files
Bring back WriteWithPrompt() (#1781)
We were running into a situation where we'd print the prompt on the same line that we had previously printed it. This was especially noticable when stepping through the debugger. So we add the `WriteWithPrompt` work-around back in.
1 parent 381e7fe commit 459d717

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public override IReadOnlyList<TResult> Run(CancellationToken cancellationToken)
6262

6363
if (PowerShellExecutionOptions.WriteInputToHost)
6464
{
65-
_psesHost.UI.WriteLine(_psCommand.GetInvocationText());
65+
_psesHost.WriteWithPrompt(_psCommand, cancellationToken);
6666
}
6767

6868
return _pwsh.Runspace.Debugger.InBreakpoint

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ private void DoOneRepl(CancellationToken cancellationToken)
770770
// one, but we do not want to print one if the ReadLine task was canceled.
771771
if (string.IsNullOrEmpty(userInput))
772772
{
773-
if (LastKeyWasCtrlC())
773+
if (cancellationToken.IsCancellationRequested || LastKeyWasCtrlC())
774774
{
775775
UI.WriteLine();
776776
}
@@ -836,6 +836,19 @@ private string GetPrompt(CancellationToken cancellationToken)
836836
return prompt;
837837
}
838838

839+
/// <summary>
840+
/// This is used to write the invocation text of a command with the user's prompt so that,
841+
/// for example, F8 (evaluate selection) appears as if the user typed it. Used when
842+
/// 'WriteInputToHost' is true.
843+
/// </summary>
844+
/// <param name="command">The PSCommand we'll print after the prompt.</param>
845+
/// <param name="cancellationToken"></param>
846+
public void WriteWithPrompt(PSCommand command, CancellationToken cancellationToken)
847+
{
848+
UI.Write(GetPrompt(cancellationToken));
849+
UI.WriteLine(command.GetInvocationText());
850+
}
851+
839852
private string InvokeReadLine(CancellationToken cancellationToken)
840853
{
841854
try

0 commit comments

Comments
 (0)