Skip to content

Commit 4175dc0

Browse files
committed
Merge branch 'master' of tig:PowerShell/GraphicalTools into master
2 parents 49b9559 + 4141604 commit 4175dc0

File tree

6 files changed

+40
-19
lines changed

6 files changed

+40
-19
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The GraphicalTools repo contains several different graphical-related PowerShell modules including:
44

55
* `Microsoft.PowerShell.GraphicalTools` - A module that provides GUI experiences based on Avalonia.
6-
* `Microsoft.PowerShell.ConsoleGuiTools` - A module that provides console-based GUI experiences based on gui.cs.
6+
* `Microsoft.PowerShell.ConsoleGuiTools` - A module that provides console-based GUI experiences based on [Terminal.Gui (gui.cs)](https://github.com/migueldeicaza/gui.cs).
77

88
## Installation
99

@@ -23,6 +23,8 @@ Install-Module Microsoft.PowerShell.ConsoleGuiTools
2323

2424
### Microsoft.PowerShell.GraphicalTools
2525

26+
[Out-GridView documentation](docs/Microsoft.PowerShell.ConsoleGuiTools/Out-GridView.md)
27+
2628
#### Cross-Platform
2729
|Linux |Windows |Mac |
2830
|---|---|---|
@@ -34,7 +36,9 @@ Install-Module Microsoft.PowerShell.ConsoleGuiTools
3436

3537
### Microsoft.PowerShell.ConsoleGuiTools
3638

37-
![screenshot of Out-ConsoleGridView](https://pbs.twimg.com/media/ESyWfiqUYAA_t6q?format=jpg&name=medium)
39+
[Out-ConsoleGridView documentation](docs/Microsoft.PowerShell.ConsoleGuiTools/Out-ConsoleGridView.md)
40+
41+
![screenshot of Out-ConsoleGridView](docs/Microsoft.PowerShell.ConsoleGuiTools/ocgv.gif)
3842

3943
#### Cross-Platform
4044

@@ -116,7 +120,6 @@ In the Powershell session run your commands; breakpoints will be hit, etc...
116120

117121
When done, run `exit` to exit the nested PowerShell and run `pwsh` again. This unloads the DLL. Repeat.
118122

119-
120123
## Contributions Welcome!
121124

122125
We would love to incorporate community contributions into this project. If you would like to

docs/Microsoft.PowerShell.ConsoleGuiTools/Out-ConsoleGridView.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@ Sends output to an interactive table in the same console window.
1515

1616
## SYNTAX
1717

18-
### PassThru (Default)
19-
```
20-
Out-ConsoleGridView [-InputObject <PSObject>] [-Title <String>] [-PassThru] [<CommonParameters>]
21-
```
22-
23-
### OutputMode
24-
```
25-
Out-ConsoleGridView [-InputObject <PSObject>] [-Title <String>] [-OutputMode <OutputModeOption>] [<CommonParameters>]
18+
```PowerShell
19+
Out-ConsoleGridView [-InputObject <psobject>] [-Title <string>] [-OutputMode {None | Single | Multiple}] [<CommonParameters>]
2620
```
2721

2822
## DESCRIPTION
@@ -40,14 +34,14 @@ For instructions for using these features, type `Get-Help Out-ConsoleGridView -F
4034
## EXAMPLES
4135

4236
### Example 1: Output processes to a grid view
43-
```
37+
```PowerShell
4438
PS C:\> Get-Process | Out-ConsoleGridView
4539
```
4640

4741
This command gets the processes running on the local computer and sends them to a grid view window.
4842

4943
### Example 2: Use a variable to output processes to a grid view
50-
```
44+
```PowerShell
5145
PS C:\> $P = Get-Process
5246
PS C:\> $P | Out-ConsoleGridView
5347
```
@@ -124,6 +118,24 @@ The processes that you select are passed to the **Export-Csv** command and writt
124118
The command uses the *PassThru* parameter of **Out-ConsoleGridView**, which lets you send multiple items down the pipeline.
125119
The *PassThru* parameter is equivalent to using the Multiple value of the *OutputMode* parameter.
126120

121+
### Example 8: Use F7 as "Show Command History"
122+
123+
```PowerShell
124+
$parameters = @{
125+
Key = 'F7'
126+
BriefDescription = 'ShowHistoryOcgv'
127+
LongDescription = 'Show History using Out-ConsoleGridView'
128+
ScriptBlock = {
129+
param($key, $arg) # The arguments are ignored in this example
130+
$history = Get-History -Count 100 | Out-ConsoleGridView -Title "Select Command" -OutputMode Single
131+
if (-Not [string]::IsNullOrWhiteSpace($history)){
132+
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($history)
133+
}
134+
}
135+
}
136+
Set-PSReadLineKeyHandler @parameters
137+
```
138+
127139
## PARAMETERS
128140

129141
### -InputObject
2.17 MB
Loading

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public HashSet<int> Start(ApplicationData applicationData)
4848

4949
// Run the GUI.
5050
Application.Run();
51+
Application.Shutdown();
5152

5253
// Return results of selection if required.
5354
HashSet<int> selectedIndexes = new HashSet<int>();
@@ -106,7 +107,7 @@ private void AddStatusBar()
106107
Accept();
107108
}
108109
else if (Application.Top.MostFocused == _filterField){
109-
Application.Top.SetFocus(_listView);
110+
_listView.SetFocus();
110111
}
111112
}),
112113
new StatusItem(Key.Esc, "~ESC~ Close", () => Close())
@@ -193,11 +194,10 @@ private void AddFilter(Window win)
193194
Width = Dim.Fill() - filterLabel.Text.Length
194195
};
195196

196-
_filterField.Changed += (object sender, ustring e) =>
197+
_filterField.TextChanged += (str) =>
197198
{
198-
// NOTE: `ustring e` seems to contain the text _before_ the added character...
199-
// so we convert the `sender` into a TextField and grab the text from that.
200-
string filterText = (sender as TextField)?.Text?.ToString();
199+
// str is the OLD value
200+
string filterText = _filterField.Text?.ToString();
201201
try
202202
{
203203
filterErrorLabel.Text = " ";

src/Microsoft.PowerShell.ConsoleGuiTools/GridViewDataSource.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Collections;
56
using System.Collections.Generic;
67
using NStack;
78
using Terminal.Gui;
@@ -32,6 +33,11 @@ public void SetMark(int item, bool value)
3233
GridViewRowList[item].IsMarked = value;
3334
}
3435

36+
public IList ToList()
37+
{
38+
return GridViewRowList;
39+
}
40+
3541
// A slightly adapted method from gui.cs: https://github.com/migueldeicaza/gui.cs/blob/fc1faba7452ccbdf49028ac49f0c9f0f42bbae91/Terminal.Gui/Views/ListView.cs#L433-L461
3642
private void RenderUstr(ConsoleDriver driver, ustring ustr, int col, int line, int width)
3743
{

src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="Nstack.Core" Version="0.14.0" />
9-
<PackageReference Include="Terminal.Gui" Version="0.81.0" />
9+
<PackageReference Include="Terminal.Gui" Version="0.89.4" />
1010
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.2.1" />
1111
</ItemGroup>
1212

0 commit comments

Comments
 (0)