Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions PSReadLine/Completion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ public void DrawMenu(Menu previousMenu, bool menuSelect)
// from a previous menu.
if (cells < bufferWidth)
{
// 'BlankRestOfLine' erases rest of the current line, but the cursor is not moved.
console.BlankRestOfLine();
}

Expand All @@ -515,6 +516,14 @@ public void DrawMenu(Menu previousMenu, bool menuSelect)
{
if (Rows < previousMenu.Rows + previousMenu.ToolTipLines)
{
// Rest of the current line was erased, but the cursor was not moved to the next line.
if (console.CursorLeft != 0)
{
// There are lines from the previous rendering that need to be cleared,
// so we are sure there is no need to scroll.
MoveCursorDown(1);
}

Singleton.WriteBlankLines(previousMenu.Rows + previousMenu.ToolTipLines - Rows);
}
}
Expand Down
27 changes: 27 additions & 0 deletions test/CompletionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,33 @@ public void PossibleCompletionsPrompt()
"Get-Many2 Get-Many5 Get-Many8 Get-Many11 Get-Many14"))));
}

[SkippableFact]
public void MenuCompletions()
{
TestSetup(KeyMode.Cmd, new KeyHandler("Ctrl+Spacebar", PSConsoleReadLine.MenuComplete));

_console.Clear();
Test("Get-Many4", Keys(
"Get-Many", _.Ctrl_Spacebar,
CheckThat(() => AssertScreenIs(4,
TokenClassification.Command, "Get-Many",
TokenClassification.Selection, "0", NextLine,
TokenClassification.Selection, "Get-Many0 ",
TokenClassification.None,
"Get-Many3 Get-Many6 Get-Many9 Get-Many12", NextLine,
"Get-Many1 Get-Many4 Get-Many7 Get-Many10 Get-Many13", NextLine,
"Get-Many2 Get-Many5 Get-Many8 Get-Many11 Get-Many14")),
"4",
CheckThat(() => AssertScreenIs(4,
TokenClassification.Command, "Get-Many4", NextLine,
TokenClassification.Selection, "Get-Many4 ", NextLine,
" ", NextLine,
" ", NextLine)),
_.Enter,
_.Enter
));
}

[SkippableFact]
public void ShowTooltips()
{
Expand Down
6 changes: 4 additions & 2 deletions test/UnitTestReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public enum TokenClassification
Type,
Number,
Member,
Selection,
}

public abstract partial class ReadLine
Expand Down Expand Up @@ -99,6 +100,7 @@ private enum KeyMode
/*Type*/ ConsoleColor.Yellow,
/*Number*/ ConsoleColor.DarkBlue,
/*Member*/ ConsoleColor.DarkMagenta,
/*Selection*/ ConsoleColor.Black,
};

internal static readonly ConsoleColor[] BackgroundColors = new[]
Expand All @@ -114,6 +116,7 @@ private enum KeyMode
/*Type*/ ConsoleColor.Black,
/*Number*/ ConsoleColor.Gray,
/*Member*/ ConsoleColor.Yellow,
/*Selection*/ ConsoleColor.Gray
};

class KeyHandler
Expand Down Expand Up @@ -476,7 +479,6 @@ private void TestSetup(KeyMode keyMode, params KeyHandler[] keyHandlers)
{ "ContinuationPrompt", MakeCombinedColor(_console.ForegroundColor, _console.BackgroundColor) },
{ "Emphasis", MakeCombinedColor(PSConsoleReadLineOptions.DefaultEmphasisColor, _console.BackgroundColor) },
{ "Error", MakeCombinedColor(ConsoleColor.Red, ConsoleColor.DarkRed) },
{ "Selection", MakeCombinedColor(ConsoleColor.Black, ConsoleColor.Gray) },
}
};

Expand All @@ -503,7 +505,7 @@ private void TestSetup(KeyMode keyMode, params KeyHandler[] keyHandlers)
var tokenTypes = new[]
{
"Default", "Comment", "Keyword", "String", "Operator", "Variable",
"Command", "Parameter", "Type", "Number", "Member"
"Command", "Parameter", "Type", "Number", "Member", "Selection"
};
var colors = new Hashtable();
for (var i = 0; i < tokenTypes.Length; i++)
Expand Down