Skip to content

Commit 40380f6

Browse files
mitigate prompt issue (#1178)
* mitigate prompt issue * remove field no longer needed * remove the GetCursorTops
1 parent f5ba912 commit 40380f6

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public static PowerShellContextService Create(
199199

200200
EditorServicesPSHostUserInterface hostUserInterface =
201201
hostStartupInfo.ConsoleReplEnabled
202-
? (EditorServicesPSHostUserInterface) new TerminalPSHostUserInterface(powerShellContext, hostStartupInfo.PSHost, shouldUsePSReadLine, logger)
202+
? (EditorServicesPSHostUserInterface) new TerminalPSHostUserInterface(powerShellContext, hostStartupInfo.PSHost, logger)
203203
: new ProtocolPSHostUserInterface(languageServer, powerShellContext, logger);
204204

205205
EditorServicesPSHost psHost =

src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public abstract class EditorServicesPSHostUserInterface :
3535
private readonly ConcurrentDictionary<ProgressKey, object> currentProgressMessages =
3636
new ConcurrentDictionary<ProgressKey, object>();
3737

38-
private readonly bool _isPSReadLineEnabled;
3938
private PromptHandler activePromptHandler;
4039
private PSHostRawUserInterface rawUserInterface;
4140
private CancellationTokenSource commandLoopCancellationToken;
@@ -106,13 +105,11 @@ public abstract class EditorServicesPSHostUserInterface :
106105
public EditorServicesPSHostUserInterface(
107106
PowerShellContextService powerShellContext,
108107
PSHostRawUserInterface rawUserInterface,
109-
bool isPSReadLineEnabled,
110108
ILogger logger)
111109
{
112110
this.Logger = logger;
113111
this.powerShellContext = powerShellContext;
114112
this.rawUserInterface = rawUserInterface;
115-
_isPSReadLineEnabled = isPSReadLineEnabled;
116113

117114
this.powerShellContext.DebuggerStop += PowerShellContext_DebuggerStop;
118115
this.powerShellContext.DebuggerResumed += PowerShellContext_DebuggerResumed;
@@ -808,7 +805,6 @@ private async Task StartReplLoopAsync(CancellationToken cancellationToken)
808805
while (!cancellationToken.IsCancellationRequested)
809806
{
810807
string commandString = null;
811-
int originalCursorTop = 0;
812808

813809
try
814810
{
@@ -821,7 +817,6 @@ private async Task StartReplLoopAsync(CancellationToken cancellationToken)
821817

822818
try
823819
{
824-
originalCursorTop = await ConsoleProxy.GetCursorTopAsync(cancellationToken).ConfigureAwait(false);
825820
commandString = await this.ReadCommandLineAsync(cancellationToken).ConfigureAwait(false);
826821
}
827822
catch (PipelineStoppedException)
@@ -848,13 +843,14 @@ private async Task StartReplLoopAsync(CancellationToken cancellationToken)
848843
}
849844
finally
850845
{
851-
// This supplies the newline in the Legacy ReadLine when executing code in the terminal via hitting the ENTER key.
852-
// Without this, hitting ENTER with a no input looks like it does nothing (no new prompt is written)
846+
// This supplies the newline in the Legacy ReadLine when executing code in the terminal via hitting the ENTER key
847+
// or Ctrl+C. Without this, hitting ENTER with a no input looks like it does nothing (no new prompt is written)
853848
// and also the output would show up on the same line as the code you wanted to execute (the prompt line).
854-
// Since PSReadLine handles ENTER internally to itself, we only want to do this when using the Legacy ReadLine.
855-
if (!_isPSReadLineEnabled &&
856-
!cancellationToken.IsCancellationRequested &&
857-
originalCursorTop == await ConsoleProxy.GetCursorTopAsync(cancellationToken).ConfigureAwait(false))
849+
// This is AlSO applied to PSReadLine for the Ctrl+C scenario which appears like it does nothing...
850+
// TODO: This still gives an extra newline when you hit ENTER in the PSReadLine experience. We should figure
851+
// out if there's any way to avoid that... but unfortunately, in both scenarios, we only see that empty
852+
// string is returned.
853+
if (!cancellationToken.IsCancellationRequested)
858854
{
859855
this.WriteLine();
860856
}

src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/ProtocolPSHostUserInterface.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public ProtocolPSHostUserInterface(
3333
: base (
3434
powerShellContext,
3535
new SimplePSHostRawUserInterface(logger),
36-
isPSReadLineEnabled: false,
3736
logger)
3837
{
3938
_languageServer = languageServer;

src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ public class TerminalPSHostUserInterface : EditorServicesPSHostUserInterface
3838
public TerminalPSHostUserInterface(
3939
PowerShellContextService powerShellContext,
4040
PSHost internalHost,
41-
bool isPSReadLineEnabled,
4241
ILogger logger)
4342
: base (
4443
powerShellContext,
4544
new TerminalPSHostRawUserInterface(logger, internalHost),
46-
isPSReadLineEnabled,
4745
logger)
4846
{
4947
this.internalHostUI = internalHost.UI;

0 commit comments

Comments
 (0)