From c1677053b8337a263ba702a42007505330a9fcad Mon Sep 17 00:00:00 2001 From: "Tyler Leonhardt (POWERSHELL)" Date: Thu, 6 Feb 2020 15:31:42 -0800 Subject: [PATCH 1/3] mitigate prompt issue --- .../Host/EditorServicesPSHostUserInterface.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs index 1c23dabb7..68c845fb8 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs @@ -852,12 +852,14 @@ private async Task StartReplLoopAsync(CancellationToken cancellationToken) } finally { - // This supplies the newline in the Legacy ReadLine when executing code in the terminal via hitting the ENTER key. - // Without this, hitting ENTER with a no input looks like it does nothing (no new prompt is written) + // This supplies the newline in the Legacy ReadLine when executing code in the terminal via hitting the ENTER key + // or Ctrl+C. Without this, hitting ENTER with a no input looks like it does nothing (no new prompt is written) // and also the output would show up on the same line as the code you wanted to execute (the prompt line). - // Since PSReadLine handles ENTER internally to itself, we only want to do this when using the Legacy ReadLine. - if (!_isPSReadLineEnabled && - !cancellationToken.IsCancellationRequested && + // This is AlSO applied to PSReadLine for the Ctrl+C scenario which appears like it does nothing... + // TODO: This still gives an extra newline when you hit ENTER in the PSReadLine experience. We should figure + // out if there's any way to avoid that... but unfortunately, in both scenarios, we only see that empty + // string is returned. + if (!cancellationToken.IsCancellationRequested && originalCursorTop == await ConsoleProxy.GetCursorTopAsync(cancellationToken).ConfigureAwait(false)) { this.WriteLine(); From 27df18cac6aa9bbd68ce4cbd2dbc1c78147af3fc Mon Sep 17 00:00:00 2001 From: "Tyler Leonhardt (POWERSHELL)" Date: Thu, 6 Feb 2020 15:43:42 -0800 Subject: [PATCH 2/3] remove field no longer needed --- .../Services/PowerShellContext/PowerShellContextService.cs | 2 +- .../Session/Host/EditorServicesPSHostUserInterface.cs | 3 --- .../Session/Host/ProtocolPSHostUserInterface.cs | 1 - .../Session/Host/TerminalPSHostUserInterface.cs | 2 -- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs index 599453546..6262c1a7e 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs @@ -199,7 +199,7 @@ public static PowerShellContextService Create( EditorServicesPSHostUserInterface hostUserInterface = hostStartupInfo.ConsoleReplEnabled - ? (EditorServicesPSHostUserInterface) new TerminalPSHostUserInterface(powerShellContext, hostStartupInfo.PSHost, shouldUsePSReadLine, logger) + ? (EditorServicesPSHostUserInterface) new TerminalPSHostUserInterface(powerShellContext, hostStartupInfo.PSHost, logger) : new ProtocolPSHostUserInterface(languageServer, powerShellContext, logger); EditorServicesPSHost psHost = diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs index 68c845fb8..4a7be8951 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs @@ -35,7 +35,6 @@ public abstract class EditorServicesPSHostUserInterface : private readonly ConcurrentDictionary currentProgressMessages = new ConcurrentDictionary(); - private readonly bool _isPSReadLineEnabled; private PromptHandler activePromptHandler; private PSHostRawUserInterface rawUserInterface; private CancellationTokenSource commandLoopCancellationToken; @@ -106,13 +105,11 @@ public abstract class EditorServicesPSHostUserInterface : public EditorServicesPSHostUserInterface( PowerShellContextService powerShellContext, PSHostRawUserInterface rawUserInterface, - bool isPSReadLineEnabled, ILogger logger) { this.Logger = logger; this.powerShellContext = powerShellContext; this.rawUserInterface = rawUserInterface; - _isPSReadLineEnabled = isPSReadLineEnabled; this.powerShellContext.DebuggerStop += PowerShellContext_DebuggerStop; this.powerShellContext.DebuggerResumed += PowerShellContext_DebuggerResumed; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/ProtocolPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/ProtocolPSHostUserInterface.cs index 32415922e..b45f0d4a4 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/ProtocolPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/ProtocolPSHostUserInterface.cs @@ -33,7 +33,6 @@ public ProtocolPSHostUserInterface( : base ( powerShellContext, new SimplePSHostRawUserInterface(logger), - isPSReadLineEnabled: false, logger) { _languageServer = languageServer; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs index ce6edee46..20e5398c4 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs @@ -38,12 +38,10 @@ public class TerminalPSHostUserInterface : EditorServicesPSHostUserInterface public TerminalPSHostUserInterface( PowerShellContextService powerShellContext, PSHost internalHost, - bool isPSReadLineEnabled, ILogger logger) : base ( powerShellContext, new TerminalPSHostRawUserInterface(logger, internalHost), - isPSReadLineEnabled, logger) { this.internalHostUI = internalHost.UI; From d16fdb3394fb5513c699ea0bc3d749e062e2c699 Mon Sep 17 00:00:00 2001 From: "Tyler Leonhardt (POWERSHELL)" Date: Mon, 10 Feb 2020 11:24:25 -0800 Subject: [PATCH 3/3] remove the GetCursorTops --- .../Session/Host/EditorServicesPSHostUserInterface.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs index 4a7be8951..a404398ce 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs @@ -809,7 +809,6 @@ private async Task StartReplLoopAsync(CancellationToken cancellationToken) while (!cancellationToken.IsCancellationRequested) { string commandString = null; - int originalCursorTop = 0; try { @@ -822,7 +821,6 @@ private async Task StartReplLoopAsync(CancellationToken cancellationToken) try { - originalCursorTop = await ConsoleProxy.GetCursorTopAsync(cancellationToken).ConfigureAwait(false); commandString = await this.ReadCommandLineAsync(cancellationToken).ConfigureAwait(false); } catch (PipelineStoppedException) @@ -856,8 +854,7 @@ private async Task StartReplLoopAsync(CancellationToken cancellationToken) // TODO: This still gives an extra newline when you hit ENTER in the PSReadLine experience. We should figure // out if there's any way to avoid that... but unfortunately, in both scenarios, we only see that empty // string is returned. - if (!cancellationToken.IsCancellationRequested && - originalCursorTop == await ConsoleProxy.GetCursorTopAsync(cancellationToken).ConfigureAwait(false)) + if (!cancellationToken.IsCancellationRequested) { this.WriteLine(); }