Skip to content

Commit 7a56514

Browse files
committed
Do not show suggestion for history commands; also remove extra suggestion text when accepting the line
1 parent 51be412 commit 7a56514

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

PSReadLine/BasicEditing.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ public static void DeleteCharOrExit(ConsoleKeyInfo? key = null, object arg = nul
208208

209209
private bool AcceptLineImpl(bool validate)
210210
{
211+
using var _ = ChangeSuggestionMode(showSuggestion: false);
212+
211213
ParseInput();
212214
if (_parseErrors.Any(e => e.IncompleteInput))
213215
{
@@ -268,6 +270,12 @@ private bool AcceptLineImpl(bool validate)
268270

269271
// Let public API set cursor to end of line incase end of line is end of buffer
270272
SetCursorPosition(_current);
273+
if (_suggestionText != null)
274+
{
275+
_suggestionText = null;
276+
_console.BlankRestOfLine();
277+
}
278+
271279
_console.Write("\n");
272280
_inputAccepted = true;
273281
return true;

PSReadLine/History.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ private void UpdateFromHistory(HistoryMoveCursor moveCursor)
502502
}
503503
break;
504504
}
505+
506+
using var _ = ChangeSuggestionMode(showSuggestion: false);
505507
Render();
506508
}
507509

PSReadLine/PSReadLine.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<InformationalVersion>2.0.1</InformationalVersion>
1010
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
1111
<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks>
12+
<LangVersion>8.0</LangVersion>
1213
</PropertyGroup>
1314

1415
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">

PSReadLine/Render.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private string GetSuggestion(string text)
110110
_lastRenderedTextHash = FNV1a32Hash.ComputeHash(text);
111111
if (textHash != _lastRenderedTextHash)
112112
{
113-
_suggestionText = Pseudo.DummySuggestion.GetCommandLineSuggestion(text);
113+
_suggestionText = DummySuggestion.GetCommandLineSuggestion(text);
114114
}
115115
}
116116
catch

PSReadLine/DummySuggestion.cs renamed to PSReadLine/Suggestion.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33

4-
namespace Pseudo
4+
namespace Microsoft.PowerShell
55
{
66
internal class DummySuggestion
77
{
@@ -11,6 +11,8 @@ static DummySuggestion()
1111
{
1212
s_suggestions = new List<string>()
1313
{
14+
"ildasm",
15+
"git",
1416
"git branch -r",
1517
"git checkout -b",
1618
"git checkout master",
@@ -36,4 +38,28 @@ internal static string GetCommandLineSuggestion(string text)
3638
return null;
3739
}
3840
}
41+
42+
public partial class PSConsoleReadLine
43+
{
44+
private class SuggestionModeRestore : IDisposable
45+
{
46+
private bool oldSuggestionMode;
47+
48+
internal SuggestionModeRestore(bool showSuggestion)
49+
{
50+
oldSuggestionMode = _singleton._showSuggestion;
51+
_singleton._showSuggestion = showSuggestion;
52+
}
53+
54+
public void Dispose()
55+
{
56+
_singleton._showSuggestion = oldSuggestionMode;
57+
}
58+
}
59+
60+
private SuggestionModeRestore ChangeSuggestionMode(bool showSuggestion)
61+
{
62+
return new SuggestionModeRestore(showSuggestion);
63+
}
64+
}
3965
}

0 commit comments

Comments
 (0)