Skip to content

Commit b564b6c

Browse files
committed
Most basic suggestion UI
1 parent cfffd0a commit b564b6c

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

PSReadLine/DummySuggestion.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,32 @@ namespace Pseudo
55
{
66
internal class DummySuggestion
77
{
8-
private static readonly Dictionary<string, string> s_suggestions = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
8+
private static readonly List<string> s_suggestions;
9+
10+
static DummySuggestion()
11+
{
12+
s_suggestions = new List<string>()
13+
{
14+
"git branch -r",
15+
"git checkout -b",
16+
"git checkout master",
17+
"git fetch --all -p",
18+
"git status",
19+
"git diff",
20+
"git diff --cached",
21+
"git add -u",
22+
"git add -A"
23+
};
24+
}
25+
926
internal static string GetCommandLineSuggestion(string text)
1027
{
11-
if (s_suggestions.TryGetValue(text, out string suggestion))
28+
foreach (string candidate in s_suggestions)
1229
{
13-
return suggestion;
30+
if (candidate.StartsWith(text, StringComparison.OrdinalIgnoreCase))
31+
{
32+
return candidate;
33+
}
1434
}
1535

1636
return null;

PSReadLine/Render.cs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void MaybeEmphasize(int i, string currColor)
320320
}
321321

322322
currentLogicalLine += 1;
323-
if (currentLogicalLine > _consoleBufferLines.Count - 1)
323+
if (currentLogicalLine == _consoleBufferLines.Count)
324324
{
325325
_consoleBufferLines.Add(new StringBuilder(COMMON_WIDEST_CONSOLE_WIDTH));
326326
}
@@ -333,10 +333,7 @@ void MaybeEmphasize(int i, string currColor)
333333
activeColor = string.Empty;
334334

335335
UpdateColorsIfNecessary(Options._continuationPromptColor);
336-
foreach (char c in Options.ContinuationPrompt)
337-
{
338-
_consoleBufferLines[currentLogicalLine].Append(c);
339-
}
336+
_consoleBufferLines[currentLogicalLine].Append(Options.ContinuationPrompt);
340337

341338
if (inSelectedRegion)
342339
{
@@ -365,6 +362,39 @@ void MaybeEmphasize(int i, string currColor)
365362
_consoleBufferLines[currentLogicalLine].Append("\x1b[0m");
366363
}
367364

365+
if (suggestion != null)
366+
{
367+
// TODO: write suggestion out in dark black by default, but it needs to be configurable.
368+
color = "\x1b[90m";
369+
UpdateColorsIfNecessary(color);
370+
371+
foreach (char charToRender in suggestion)
372+
{
373+
if (charToRender == '\n')
374+
{
375+
currentLogicalLine += 1;
376+
if (currentLogicalLine == _consoleBufferLines.Count)
377+
{
378+
_consoleBufferLines.Add(new StringBuilder(COMMON_WIDEST_CONSOLE_WIDTH));
379+
}
380+
381+
_consoleBufferLines[currentLogicalLine].Append(Options.ContinuationPrompt);
382+
}
383+
else
384+
{
385+
if (char.IsControl(charToRender))
386+
{
387+
_consoleBufferLines[currentLogicalLine].Append('^');
388+
_consoleBufferLines[currentLogicalLine].Append((char)('@' + charToRender));
389+
}
390+
else
391+
{
392+
_consoleBufferLines[currentLogicalLine].Append(charToRender);
393+
}
394+
}
395+
}
396+
}
397+
368398
if (_statusLinePrompt != null)
369399
{
370400
currentLogicalLine += 1;

0 commit comments

Comments
 (0)