Skip to content

Commit 492321b

Browse files
committed
Don't print extra prompt on cancellation of ReadLine
1 parent 58a6db5 commit 492321b

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
@@ -62,7 +62,7 @@ public override IReadOnlyList<TResult> Run(CancellationToken cancellationToken)
6262

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

6868
return _pwsh.Runspace.Debugger.InBreakpoint

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

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

742742
// If the user input was empty it's because:
743743
// - the user provided no input
744-
// - the readline task was canceled
745-
// - CtrlC was sent to readline (which does not propagate a cancellation)
744+
// - the ReadLine task was canceled
745+
// - CtrlC was sent to ReadLine (which does not propagate a cancellation)
746746
//
747-
// In any event there's nothing to run in PowerShell, so we just loop back to the prompt again.
748-
// However, we must distinguish the last two scenarios, since PSRL will not print a new line in those cases.
749-
if (string.IsNullOrEmpty(userInput))
747+
// In any event there's nothing to run in PowerShell, so we just loop back to the
748+
// prompt again. However, PSReadLine will not print a newline for CtrlC, so we print
749+
// one, but we do not want to print one if the ReadLine task was canceled.
750+
if (string.IsNullOrEmpty(userInput) && LastKeyWasCtrlC())
750751
{
751-
if (cancellationToken.IsCancellationRequested || LastKeyWasCtrlC())
752-
{
753-
UI.WriteLine();
754-
}
752+
UI.WriteLine();
755753
return;
756754
}
757755

@@ -813,19 +811,6 @@ private string GetPrompt(CancellationToken cancellationToken)
813811
return prompt;
814812
}
815813

816-
/// <summary>
817-
/// This is used to write the invocation text of a command with the user's prompt so that,
818-
/// for example, F8 (evaluate selection) appears as if the user typed it. Used when
819-
/// 'WriteInputToHost' is true.
820-
/// </summary>
821-
/// <param name="command">The PSCommand we'll print after the prompt.</param>
822-
/// <param name="cancellationToken"></param>
823-
public void WriteWithPrompt(PSCommand command, CancellationToken cancellationToken)
824-
{
825-
UI.Write(GetPrompt(cancellationToken));
826-
UI.WriteLine(command.GetInvocationText());
827-
}
828-
829814
private string InvokeReadLine(CancellationToken cancellationToken)
830815
{
831816
try

0 commit comments

Comments
 (0)