Skip to content

Commit 2ac4823

Browse files
Track cursor position when writing prompt
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. This change ensures that we always write a new line if that situation occurs.
1 parent 381e7fe commit 2ac4823

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
using System;
@@ -77,6 +77,8 @@ internal class PsesInternalHost : PSHost, IHostSupportsInteractiveSession, IRuns
7777

7878
private bool _resettingRunspace;
7979

80+
private (int x, int y)? _lastPromptPosition;
81+
8082
public PsesInternalHost(
8183
ILoggerFactory loggerFactory,
8284
ILanguageServerFacade languageServer,
@@ -757,7 +759,20 @@ private void DoOneRepl(CancellationToken cancellationToken)
757759
try
758760
{
759761
string prompt = GetPrompt(cancellationToken);
762+
763+
// Check cursor position to see if we're in the exact same spot as the last time we
764+
// wrote the prompt. If we are, write a new line.
765+
if (_lastPromptPosition is not null)
766+
{
767+
(int x, int y) current = (System.Console.CursorLeft, System.Console.CursorTop);
768+
if (current == _lastPromptPosition.Value)
769+
{
770+
UI.WriteLine();
771+
}
772+
}
773+
760774
UI.Write(prompt);
775+
_lastPromptPosition = (System.Console.CursorLeft, System.Console.CursorTop);
761776
string userInput = InvokeReadLine(cancellationToken);
762777

763778
// If the user input was empty it's because:

0 commit comments

Comments
 (0)