Skip to content

Commit 34f9441

Browse files
committed
Don't print extra prompt on cancellation of ReadLine
1 parent 9290afd commit 34f9441

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

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

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

5656
if (PowerShellExecutionOptions.WriteInputToHost)
5757
{
58-
_psesHost.WriteWithPrompt(_psCommand, cancellationToken);
58+
_psesHost.UI.WriteLine(_psCommand.GetInvocationText());
5959
}
6060

6161
return _pwsh.Runspace.Debugger.InBreakpoint

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

+7-22
Original file line numberDiff line numberDiff line change
@@ -617,17 +617,15 @@ private void DoOneRepl(CancellationToken cancellationToken)
617617

618618
// If the user input was empty it's because:
619619
// - the user provided no input
620-
// - the readline task was canceled
621-
// - CtrlC was sent to readline (which does not propagate a cancellation)
620+
// - the ReadLine task was canceled
621+
// - CtrlC was sent to ReadLine (which does not propagate a cancellation)
622622
//
623-
// In any event there's nothing to run in PowerShell, so we just loop back to the prompt again.
624-
// However, we must distinguish the last two scenarios, since PSRL will not print a new line in those cases.
625-
if (string.IsNullOrEmpty(userInput))
623+
// In any event there's nothing to run in PowerShell, so we just loop back to the
624+
// prompt again. However, PSReadLine will not print a newline for CtrlC, so we print
625+
// one, but we do not want to print one if the ReadLine task was canceled.
626+
if (string.IsNullOrEmpty(userInput) && LastKeyWasCtrlC())
626627
{
627-
if (cancellationToken.IsCancellationRequested || LastKeyWasCtrlC())
628-
{
629-
UI.WriteLine();
630-
}
628+
UI.WriteLine();
631629
return;
632630
}
633631

@@ -679,19 +677,6 @@ private string GetPrompt(CancellationToken cancellationToken)
679677
return prompt;
680678
}
681679

682-
/// <summary>
683-
/// This is used to write the invocation text of a command with the user's prompt so that,
684-
/// for example, F8 (evaluate selection) appears as if the user typed it. Used when
685-
/// 'WriteInputToHost' is true.
686-
/// </summary>
687-
/// <param name="command">The PSCommand we'll print after the prompt.</param>
688-
/// <param name="cancellationToken"></param>
689-
public void WriteWithPrompt(PSCommand command, CancellationToken cancellationToken)
690-
{
691-
UI.Write(GetPrompt(cancellationToken));
692-
UI.WriteLine(command.GetInvocationText());
693-
}
694-
695680
private string InvokeReadLine(CancellationToken cancellationToken)
696681
{
697682
try

0 commit comments

Comments
 (0)