Skip to content

Commit b0ff32b

Browse files
committed
Update the basic UI
1 parent b564b6c commit b0ff32b

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

PSReadLine/BasicEditing.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,18 @@ public static void SelfInsert(ConsoleKeyInfo? key = null, object arg = null)
3737
count = 1;
3838
}
3939

40-
try
40+
if (_singleton._visualSelectionCommandCount > 0)
4141
{
42-
_singleton._showSuggestion = true;
43-
44-
if (_singleton._visualSelectionCommandCount > 0)
45-
{
46-
_singleton.GetRegion(out var start, out var length);
47-
Replace(start, length, new string(keyChar, count));
48-
}
49-
else if (count > 1)
50-
{
51-
Insert(new string(keyChar, count));
52-
}
53-
else
54-
{
55-
Insert(keyChar);
56-
}
42+
_singleton.GetRegion(out var start, out var length);
43+
Replace(start, length, new string(keyChar, count));
5744
}
58-
finally
45+
else if (count > 1)
46+
{
47+
Insert(new string(keyChar, count));
48+
}
49+
else
5950
{
60-
_singleton._showSuggestion = false;
51+
Insert(keyChar);
6152
}
6253
}
6354

PSReadLine/PublicAPI.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,13 @@ public static bool TryGetArgAsInt(object arg, out int numericArg, int defaultNum
235235
numericArg = 0;
236236
return false;
237237
}
238+
239+
public static void AcceptSuggestion()
240+
{
241+
if (_singleton._suggestionText != null)
242+
{
243+
244+
}
245+
}
238246
}
239247
}

PSReadLine/ReadLine.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ public partial class PSConsoleReadLine : IPSConsoleReadLineMockableMethods
6363

6464
private readonly StringBuilder _buffer;
6565
private readonly StringBuilder _statusBuffer;
66-
private string _suggestionText;
67-
private bool _showSuggestion;
6866
private bool _statusIsErrorMessage;
6967
private string _statusLinePrompt;
7068
private List<EditItem> _edits;

PSReadLine/Render.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class RenderData
6969
private int _emphasisStart;
7070
private int _emphasisLength;
7171

72+
private string _suggestionText;
73+
private uint _lastRenderedTextHash;
74+
private bool _showSuggestion = true;
75+
7276
private class SavedTokenState
7377
{
7478
internal Token[] Tokens { get; set; }
@@ -93,24 +97,26 @@ private string ParseInput()
9397

9498
private string GetSuggestion(string text)
9599
{
96-
if (!_showSuggestion || LineIsMultiLine())
100+
if (!_showSuggestion || LineIsMultiLine() || string.IsNullOrWhiteSpace(text))
97101
{
98-
_suggestionText = null;
102+
return null;
99103
}
100-
else
101-
{
102-
bool reuseSuggestionBuffer =
103-
_suggestionText != null &&
104-
_suggestionText.Length >= text.Length &&
105-
_suggestionText.StartsWith(text, StringComparison.OrdinalIgnoreCase);
106104

107-
if (!reuseSuggestionBuffer)
105+
try
106+
{
107+
uint textHash = _lastRenderedTextHash;
108+
_lastRenderedTextHash = FNV1a32Hash.ComputeHash(text);
109+
if (textHash != _lastRenderedTextHash)
108110
{
109111
_suggestionText = Pseudo.DummySuggestion.GetCommandLineSuggestion(text);
110112
}
111113
}
114+
catch
115+
{
116+
_suggestionText = null;
117+
}
112118

113-
return _suggestionText == null ? null : _suggestionText.Substring(text.Length);
119+
return _suggestionText?.Substring(text.Length);
114120
}
115121

116122
private void ClearStatusMessage(bool render)
@@ -362,6 +368,7 @@ void MaybeEmphasize(int i, string currColor)
362368
_consoleBufferLines[currentLogicalLine].Append("\x1b[0m");
363369
}
364370

371+
inSelectedRegion = false;
365372
if (suggestion != null)
366373
{
367374
// TODO: write suggestion out in dark black by default, but it needs to be configurable.

0 commit comments

Comments
 (0)