Skip to content

Bring back WriteWithPrompt() #1781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override IReadOnlyList<TResult> Run(CancellationToken cancellationToken)

if (PowerShellExecutionOptions.WriteInputToHost)
{
_psesHost.UI.WriteLine(_psCommand.GetInvocationText());
_psesHost.WriteWithPrompt(_psCommand, cancellationToken);
}

return _pwsh.Runspace.Debugger.InBreakpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -836,6 +836,19 @@ private string GetPrompt(CancellationToken cancellationToken)
return prompt;
}

/// <summary>
/// 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.
/// </summary>
/// <param name="command">The PSCommand we'll print after the prompt.</param>
/// <param name="cancellationToken"></param>
public void WriteWithPrompt(PSCommand command, CancellationToken cancellationToken)
{
UI.Write(GetPrompt(cancellationToken));
UI.WriteLine(command.GetInvocationText());
}

private string InvokeReadLine(CancellationToken cancellationToken)
{
try
Expand Down