Skip to content

Commit 6cf129e

Browse files
Add the "Dynamic Help" feature to PSReadLine (#1777)
- Adds a way to view help on alternate screen buffer for full help and uses a Pager from `Microsoft.PowerShell.Pager`. - Implements dynamic help for parameters by showing it below the current command line like `MenuComplete`.
1 parent 9e09968 commit 6cf129e

16 files changed

+721
-42
lines changed

.vsts-ci/releaseBuild.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ stages:
7676
*.ps1xml
7777
**\*.dll
7878
!System.Runtime.InteropServices.RuntimeInformation.dll
79+
!Microsoft.PowerShell.Pager.dll
7980
useMinimatch: true
8081

8182
# Replace the *.psm1, *.ps1, *.psd1, *.dll files with the signed ones

MockPSConsole/MockPSConsole.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</ItemGroup>
1919

2020
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
21-
<PackageReference Include="Microsoft.PowerShell.SDK" version="7.1.0-rc.2" />
21+
<PackageReference Include="Microsoft.PowerShell.SDK" version="7.1.0" />
2222
</ItemGroup>
2323

2424
<ItemGroup>

PSReadLine.build.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ task LayoutModule BuildPolyfiller, BuildMainModule, {
142142

143143
$binPath = "PSReadLine/bin/$Configuration/$Framework/publish"
144144
Copy-Item $binPath/Microsoft.PowerShell.PSReadLine2.dll $targetDir
145+
Copy-Item $binPath/Microsoft.PowerShell.Pager.dll $targetDir
145146

146147
if (Test-Path $binPath/System.Runtime.InteropServices.RuntimeInformation.dll) {
147148
Copy-Item $binPath/System.Runtime.InteropServices.RuntimeInformation.dll $targetDir

PSReadLine/Completion.cs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,15 @@ private static string HandleNewlinesForPossibleCompletions(string s)
422422
return s;
423423
}
424424

425-
private class Menu
425+
private class Menu : DisplayBlockBase
426426
{
427-
internal PSConsoleReadLine Singleton;
428-
internal int Top;
429-
430427
internal int PreviousTop;
431428
internal int ColumnWidth;
432429
internal int BufferLines;
433430
internal int Rows;
434431
internal int Columns;
435432
internal int ToolTipLines;
433+
436434
internal Collection<CompletionResult> MenuItems;
437435
internal CompletionResult CurrentMenuItem => MenuItems[CurrentSelection];
438436
internal int CurrentSelection;
@@ -701,39 +699,6 @@ public void MoveN(int n)
701699
CurrentSelection += MenuItems.Count;
702700
}
703701
}
704-
705-
private void MoveCursorDown(int cnt)
706-
{
707-
IConsole console = Singleton._console;
708-
while (cnt-- > 0)
709-
{
710-
console.Write("\n");
711-
}
712-
}
713-
714-
private void AdjustForPossibleScroll(int cnt)
715-
{
716-
IConsole console = Singleton._console;
717-
var scrollCnt = console.CursorTop + cnt + 1 - console.BufferHeight;
718-
if (scrollCnt > 0)
719-
{
720-
Top -= scrollCnt;
721-
_singleton._initialY -= scrollCnt;
722-
_savedCursorTop -= scrollCnt;
723-
}
724-
}
725-
726-
private int _savedCursorLeft;
727-
private int _savedCursorTop;
728-
729-
public void SaveCursor()
730-
{
731-
IConsole console = Singleton._console;
732-
_savedCursorLeft = console.CursorLeft;
733-
_savedCursorTop = console.CursorTop;
734-
}
735-
736-
public void RestoreCursor() => Singleton._console.SetCursorPosition(_savedCursorLeft, _savedCursorTop);
737702
}
738703

739704
private Menu CreateCompletionMenu(Collection<CompletionResult> matches)

PSReadLine/DisplayBlockBase.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/********************************************************************++
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
--********************************************************************/
4+
5+
using System;
6+
using Microsoft.PowerShell.Internal;
7+
8+
namespace Microsoft.PowerShell
9+
{
10+
public partial class PSConsoleReadLine
11+
{
12+
private class DisplayBlockBase
13+
{
14+
internal PSConsoleReadLine Singleton;
15+
internal int Top;
16+
17+
protected void MoveCursorDown(int cnt)
18+
{
19+
IConsole console = Singleton._console;
20+
while (cnt-- > 0)
21+
{
22+
console.Write("\n");
23+
}
24+
}
25+
26+
protected void AdjustForPossibleScroll(int cnt)
27+
{
28+
IConsole console = Singleton._console;
29+
var scrollCnt = console.CursorTop + cnt + 1 - console.BufferHeight;
30+
if (scrollCnt > 0)
31+
{
32+
Top -= scrollCnt;
33+
_singleton._initialY -= scrollCnt;
34+
_savedCursorTop -= scrollCnt;
35+
}
36+
}
37+
38+
private int _savedCursorLeft;
39+
private int _savedCursorTop;
40+
41+
public void SaveCursor()
42+
{
43+
IConsole console = Singleton._console;
44+
_savedCursorLeft = console.CursorLeft;
45+
_savedCursorTop = console.CursorTop;
46+
}
47+
48+
public void RestoreCursor() => Singleton._console.SetCursorPosition(_savedCursorLeft, _savedCursorTop);
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)