Skip to content

Commit 3c189cd

Browse files
tigTylerLeonhardt
andauthored
Adds Filter switch (#110)
* Fixed #58: Multi-line commands rendering wrong * Fixed #58 - Newlines in commands render incorrectly * Added debug instructions to readme * Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs Co-Authored-By: Tyler James Leonhardt <[email protected]> * simplified stripping of newline/linefeed * fixes to support gui.cs 0.89.3 * enhanced docs * formatting * partialy updated docs * fixed Single mode * fixed bug with filtering * updated build to also run ocgv * fixed f7 docs * fixed comment regarding selection mode formatting * Adds -Filter * undid spell check cahnge * undid spell check cahnge * undid spell check cahnge * removed orig file * per tylers feedback * updated .md * fixed md * Updated to pull FINAL gui.cs v0.90 release * updated psd to 0.60.0 and added release notes * fixed typo; added tags; hopefully this will unsick the mac build * fixed another typo Co-authored-by: Tyler James Leonhardt <[email protected]>
1 parent c43c923 commit 3c189cd

File tree

6 files changed

+83
-140
lines changed

6 files changed

+83
-140
lines changed

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

Lines changed: 64 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,43 @@ title: Out-ConsoleGridView
1111
# Out-ConsoleGridView
1212

1313
## SYNOPSIS
14+
1415
Sends output to an interactive table in the same console window.
1516

1617
## SYNTAX
1718

1819
```PowerShell
19-
Out-ConsoleGridView [-InputObject <psobject>] [-Title <string>] [-OutputMode {None | Single | Multiple}] [<CommonParameters>]
20+
Out-ConsoleGridView [-InputObject <psobject>] [-Title <string>] [-OutputMode {None | Single |
21+
Multiple}] [-Filter <string>] [<CommonParameters>]
2022
```
2123

2224
## DESCRIPTION
25+
2326
The **Out-ConsoleGridView** cmdlet sends the output from a command to a grid view window where the output is displayed in an interactive table.
2427

2528
You can use the following features of the table to examine your data:
2629

27-
- Hide, Show, and Reorder Columns: To hide, show, use the columns dropdown. Drag and drop column headers to reorder.
28-
- Sort. To sort the data, click a column header. Click again to toggle from ascending to descending order.
29-
- Quick Filter. Use the Filter box at the top of the window to search the text in the table. You can search for text in a particular column, search for literals, and search for multiple words.
30-
- Column Filter. Use the Add Column Filter drop-down to create rules to filter the data. This is very useful for very large data sets, such as event logs.
30+
- Quick Filter. Use the Filter box at the top of the window to search the text in the table. You can search for text in a particular column, search for literals, and search for multiple words. You can use the `-Filter` command to pre-populate the Filter box.
3131

3232
For instructions for using these features, type `Get-Help Out-ConsoleGridView -Full` and see How to Use the Grid View Window Features in the Notes section.
3333

34+
To send items from the interactive window down the pipeline, click to select the items (either the the mouse in terminals that support mouse or the `SPACE` key) and then press `ENTER`. `ESC` cancels.
35+
3436
## EXAMPLES
3537

3638
### Example 1: Output processes to a grid view
39+
3740
```PowerShell
3841
PS C:\> Get-Process | Out-ConsoleGridView
3942
```
4043

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

4346
### Example 2: Use a variable to output processes to a grid view
47+
4448
```PowerShell
4549
PS C:\> $P = Get-Process
46-
PS C:\> $P | Out-ConsoleGridView
50+
PS C:\> $P | Out-ConsoleGridView -OutputMode Single
4751
```
4852

4953
This command also gets the processes running on the local computer and sends them to a grid view window.
@@ -52,8 +56,11 @@ The first command uses the Get-Process cmdlet to get the processes on the comput
5256

5357
The second command uses a pipeline operator to send the $P variable to **Out-ConsoleGridView**.
5458

59+
By specifying `-OutputMode Single` the grid view window will be restricted to a single selection, ensuring now more than a single object is returned.
60+
5561
### Example 3: Display a formatted table in a grid view
56-
```
62+
63+
```PowerShell
5764
PS C:\> Get-Process | Select-Object -Property Name, WorkingSet, PeakWorkingSet | Sort-Object -Property WorkingSet -Descending | Out-ConsoleGridView
5865
```
5966

@@ -71,7 +78,8 @@ The final part of the command uses a pipeline operator (|) to send the formatted
7178
You can now use the features of the grid view to search, sort, and filter the data.
7279

7380
### Example 4: Save output to a variable, and then output a grid view
74-
```
81+
82+
```PowerShell
7583
PS C:\> ($A = Get-ChildItem -Path $pshome -Recurse) | Out-ConsoleGridView
7684
```
7785

@@ -86,29 +94,28 @@ The parentheses in the command establish the order of operations.
8694
As a result, the output from the Get-ChildItem command is saved in the $A variable before it is sent to **Out-ConsoleGridView**.
8795

8896
### Example 5: Output processes for a specified computer to a grid view
89-
```
97+
98+
```PowerShell
9099
PS C:\> Get-Process -ComputerName "Server01" | ocgv -Title "Processes - Server01"
91100
```
92101

93102
This command displays the processes that are running on the Server01 computer in a grid view window.
94103

95104
The command uses `ocgv`, which is the built-in alias for the **Out-ConsoleGridView** cmdlet, it uses the *Title* parameter to specify the window title.
96105

97-
### Example 6: Output data from remote computers to a grid view
98-
```
99-
PS C:\> Invoke-Command -ComputerName S1, S2, S3 -ScriptBlock {Get-Culture} | Out-ConsoleGridView
100-
```
101-
102-
This example shows the correct format for sending data collected from remote computers to the **Out-ConsoleGridView** cmdlet.
106+
### Example 6: Define a function to kill processes using a graphical chooser
103107

104-
The command uses the Invoke-Command cmdlet to run a Get-Culture command on three remote computers.
105-
It uses a pipeline operator to send the data that is returned to the **Out-ConsoleGridView** cmdlet.
108+
```PowerShell
109+
PS C:\> function killp { Get-Process | Out-ConsoleGridView -OutputMode Single -Filter $args[0] | Stop-Process -Id {$_.Id} }
110+
PS C:\> killp note
111+
```
112+
This example shows defining a function named `killp` that shows a grid view of all running processes and allows the user to select one to kill it.
106113

107-
Notice that the script block that contains the commands that are run remotely does not include the **Out-ConsoleGridView** command.
108-
If it did, the command would fail when it tried to open a grid view window on each of the remote computers.
114+
The example uses the `-Filter` paramter to filter for all proceses with a name that includes `note` (thus highlighting `Notepad` if it were running. Selecting an item in the grid view and pressing `ENTER` will kill that process.
109115

110116
### Example 7: Pass multiple items through Out-ConsoleGridView
111-
```
117+
118+
```PowerShell
112119
PS C:\> Get-Process | Out-ConsoleGridView -PassThru | Export-Csv -Path .\ProcessLog.csv
113120
```
114121

@@ -120,28 +127,38 @@ The *PassThru* parameter is equivalent to using the Multiple value of the *Outpu
120127

121128
### Example 8: Use F7 as "Show Command History"
122129

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 | Sort-Object -Property Id -Descending | 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-
```
130+
Save See [this gist](https://gist.github.com/tig/cbbeab7f53efd73e329afd6d4b838191) as `F7History.ps111 and run `F7History.ps1` in your `$profile`.
131+
132+
Press `F7` to see the history for the current PowerShell instance
133+
134+
Press `Shift-F7` to see the history for all PowerShell instances.
135+
136+
Whatever you select within `Out-ConsoleGridView` will be inserted on your command line.
137+
138+
Whatever was typed on the command line prior to hitting `F7` or `Shift-F7` will be used as a filter.
138139

139140
## PARAMETERS
140141

142+
### -Filter
143+
Pre-populates the Filter edit box, allowing filtering to be specified on the command line.
144+
145+
```yaml
146+
Type: String
147+
Parameter Sets: (All)
148+
Aliases:
149+
150+
Required: False
151+
Position: Named
152+
Default value: None
153+
Accept pipeline input: False
154+
Accept wildcard characters: False
155+
```
156+
141157
### -InputObject
142158
Specifies that the cmdlet accepts input for **Out-ConsoleGridView**.
143159
144160
When you use the **InputObject** parameter to send a collection of objects to **Out-ConsoleGridView**, **Out-ConsoleGridView** treats the collection as one collection object, and it displays one row that represents the collection.
161+
145162
To display the each object in the collection, use a pipeline operator (|) to send objects to **Out-ConsoleGridView**.
146163
147164
```yaml
@@ -159,13 +176,14 @@ Accept wildcard characters: False
159176
### -OutputMode
160177
Specifies the items that the interactive window sends down the pipeline as input to other commands.
161178
By default, this cmdlet does not generate any output.
162-
To send items from the interactive window down the pipeline, click to select the items and then click OK.
179+
180+
To send items from the interactive window down the pipeline, click to select the items (either the the mouse in terminals that support mouse or the `SPACE` key) and then press `ENTER`. `ESC` cancels.
163181

164182
The values of this parameter determine how many items you can send down the pipeline.
165183

166-
- None. No items. This is the default value.
184+
- None. No items.
167185
- Single. Zero items or one item. Use this value when the next command can take only one input object.
168-
- Multiple. Zero, one, or many items. Use this value when the next command can take multiple input objects. This value is equivalent to the *Passthru* parameter.
186+
- Multiple. Zero, one, or many items. Use this value when the next command can take multiple input objects. This is the default value.
169187

170188
```yaml
171189
Type: OutputModeOption
@@ -175,27 +193,7 @@ Accepted values: None, Single, Multiple
175193
176194
Required: False
177195
Position: Named
178-
Default value: None
179-
Accept pipeline input: False
180-
Accept wildcard characters: False
181-
```
182-
183-
### -PassThru
184-
Indicates that the cmdlet sends items from the interactive window down the pipeline as input to other commands.
185-
By default, this cmdlet does not generate any output.
186-
This parameter is equivalent to using the Multiple value of the *OutputMode* parameter.
187-
188-
To send items from the interactive window down the pipeline, click to select the items and then click OK.
189-
Shift-click and Ctrl-click are supported.
190-
191-
```yaml
192-
Type: SwitchParameter
193-
Parameter Sets: PassThru
194-
Aliases:
195-
196-
Required: False
197-
Position: Named
198-
Default value: None
196+
Default value: Multiple
199197
Accept pipeline input: False
200198
Accept wildcard characters: False
201199
```
@@ -223,96 +221,25 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
223221
## INPUTS
224222

225223
### System.Management.Automation.PSObject
224+
226225
You can send any object to this cmdlet.
227226

228227
## OUTPUTS
229228

230-
### None
229+
### System.Object
231230

232-
Normally, `Out-ConsoleGridView` does not return any objects. When using the `PassThru` parameter, the objects representing the selected rows are returned to the pipeline.
231+
By default `Out-ConsoleGridView` returns objects representing the selected rows to the pipeline. Use `-OutputMode` to change this behavior.
233232

234233
## NOTES
235-
* The command output that you send to **Out-ConsoleGridView** cannot be formatted, such as by using the Format-Table or Format-Wide cmdlets. To select properties, use the Select-Object cmdlet.
236-
* Deserialized output from remote commands might not be formatted correctly in the grid view window.
237-
How to Use the Grid View Window Features
238-
239-
The following topics explain how to use the features of the window that **Out-ConsoleGridView** displays.
240-
241-
**How to Hide, Show, and Reorder Columns**
242-
243-
**To hide or show a column:**
244-
245-
1. Click on the Columns expander.
246-
247-
2. In the Columns expander, toggle Columns that should appear.
248-
Only selected columns appear in the grid view window.
249-
250-
**To reorder columns:**
251-
252-
- Drag and drop the column into the desired location.
253-
254-
**How to Sort Table Data**
255-
256-
- To sort the data, click a column header.
257234

258-
- To change the sort order, click the column header again.
259-
Each time you click the same header, the sort order toggles between ascending to descending order.
260-
The current order is indicated by a triangle in the column header.
235+
* The command output that you send to **Out-ConsoleGridView** should not be formatted, such as by using the Format-Table or Format-Wide cmdlets. To select properties, use the Select-Object cmdlet.
261236

262-
**How to Search in the Table (Quick Filter)**
263-
264-
Use the Filter box to search for data in the table.
265-
When you type in the box, only items that include the typed text appear in the table.
266-
267-
- Search for text.
268-
To search for text in the table, in the Filter box, type the text to find.
269-
270-
- Search for multiple words.
271-
To search for multiple words in the table, type the words separated by spaces.
272-
**Out-ConsoleGridView** displays rows that include all of the words (logical AND).
273-
274-
- Search for literal phrases.
275-
To search for phrases that include spaces or special characters, enclose the phrase in quotation marks.
276-
**Out-ConsoleGridView** displays rows that include an exact match for the phrase.
277-
278-
**Use Column Filters to Filter the Table**
279-
280-
You can use column filters to determine which items are displayed in the table.
281-
Items appear only when they satisfy all of the column filters that you establish.
282-
283-
Each column filter has the following format:
284-
285-
\<column\> \<operator\> \<value\>
286-
287-
Column filters for different properties are connected by AND.
288-
Column filters for the same property are connected by OR.
289-
You cannot change the logical connectors.
290-
291-
The column filters only affects the display.
292-
It does not delete items from the table.
293-
294-
**How to Add Column Filters**
295-
296-
1. Click the Add Column Filters menu button.
297-
298-
2. Click the column (property) you wish to add.
299-
300-
**How to Edit a Column Filter**
301-
302-
- To change an operator, click the operator drop down, and then click to select a different operator from the drop-down list.
303-
304-
- To enter or change a value, type a value in the value box.
305-
306-
- To create an OR statement, add a column filter with the same property.
307-
308-
**How to Delete Column Filters**
309-
310-
- To delete selected column filters, click the remove button beside each column filter.
311-
312-
- To delete all column filters, click the Clear Filters button.
237+
* Deserialized output from remote commands might not be formatted correctly in the grid view window.
313238

314239
## RELATED LINKS
315240

241+
[Out-GridView](Out-GridView.md)
242+
316243
[Out-File](Out-File.md)
317244

318245
[Out-Printer](Out-Printer.md)

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public HashSet<int> Start(ApplicationData applicationData)
4747
LoadData();
4848
AddRows(win);
4949

50+
_filterField.Text = _applicationData.Filter ?? string.Empty;
51+
_filterField.CursorPosition = _filterField.Text.Length;
5052
// Run the GUI.
5153
Application.Run();
5254
Application.Shutdown();

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.89.4" />
9+
<PackageReference Include="Terminal.Gui" Version="0.90.2" />
1010
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.2.1" />
1111
</ItemGroup>
1212

src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
RootModule = 'Microsoft.PowerShell.ConsoleGuiTools.dll'
1010

1111
# Version number of this module.
12-
ModuleVersion = '0.5.0'
12+
ModuleVersion = '0.6.0'
1313

1414
# Supported PSEditions
1515
CompatiblePSEditions = @( 'Core' )
@@ -92,7 +92,7 @@ PrivateData = @{
9292
PSData = @{
9393

9494
# Tags applied to this module. These help with module discovery in online galleries.
95-
Tags = @('Console', 'Gui', 'Out-GridView', 'MacOS', 'Windows', 'Linux', 'PSEdition_Core')
95+
Tags = @('Console', 'Gui', 'Out-GridView', 'Out-ConsoleGridView', 'Terminal.Gui', 'gui.cs', 'MacOS', 'Windows', 'Linux', 'PSEdition_Core')
9696

9797
# A URL to the license for this module.
9898
LicenseUri = 'https://github.com/PowerShell/GraphicalTools/blob/master/LICENSE.txt'
@@ -106,6 +106,12 @@ PrivateData = @{
106106
# ReleaseNotes of this module
107107
ReleaseNotes = '# Release Notes
108108
109+
## v0.6.0
110+
111+
Now supports `-Filter` parameter.
112+
113+
Updated to use the final release of `Terminal.Gui` v0.90 (which is feature complete for 1.0).
114+
109115
## v0.5.0
110116
111117
`Out-ConsoleGridView` has been totally refactored!

src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable
4646
[Parameter()]
4747
public OutputModeOption OutputMode { set; get; } = OutputModeOption.Multiple;
4848

49+
/// <summary>
50+
/// gets or sets the initial value for the filter in the GUI
51+
/// </summary>
52+
[Parameter()]
53+
public string Filter { set; get; }
54+
4955
#endregion Input Parameters
5056

5157
// This method gets called once for each cmdlet in the pipeline when the pipeline starts executing
@@ -126,6 +132,7 @@ protected override void EndProcessing()
126132
{
127133
Title = Title ?? "Out-ConsoleGridView",
128134
OutputMode = OutputMode,
135+
Filter = Filter,
129136
DataTable = dataTable
130137
};
131138

src/OutGridView.Models/ApplicationData.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class ApplicationData
1111
public string Title { get; set; }
1212
public OutputModeOption OutputMode { get; set; }
1313
public bool PassThru { get; set; }
14+
public string Filter { get; set; }
1415
public DataTable DataTable { get; set; }
1516
}
1617
}

0 commit comments

Comments
 (0)