Skip to content

Commit c43c923

Browse files
rev to 0.5.0 and misc style changes (#108)
1 parent 18be2ce commit c43c923

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public HashSet<int> Start(ApplicationData applicationData)
2828
_gridViewDetails = new GridViewDetails
2929
{
3030
// If OutputMode is Single or Multiple, then we make items selectable. If we make them selectable,
31-
// they have a 8 character addition of a checkbox (" [ ]" or ".....( )")
31+
// they have a 8 character addition of a checkbox (".....[ ]" or ".....( )")
3232
// that we have to factor in.
3333
ListViewOffset = _applicationData.OutputMode != OutputModeOption.None ? 8 : 4
3434
};
@@ -69,11 +69,13 @@ public HashSet<int> Start(ApplicationData applicationData)
6969
return selectedIndexes;
7070
}
7171

72-
private void Accept(){
72+
private void Accept()
73+
{
7374
Application.RequestStop();
7475
}
7576

76-
private void Close(){
77+
private void Close()
78+
{
7779
_cancelled = true;
7880
Application.RequestStop();
7981
}
@@ -98,29 +100,33 @@ private void AddStatusBar()
98100
{
99101
var statusBar = new StatusBar(
100102
_applicationData.OutputMode != OutputModeOption.None
101-
? new StatusItem []
103+
? new StatusItem[]
102104
{
103105
// Use Key.Unknown for SPACE with no delegate because ListView already
104106
// handles SPACE
105107
new StatusItem(Key.Unknown, "~SPACE~ Mark Item", null),
106-
new StatusItem(Key.Enter, "~ENTER~ Accept", () => {
107-
if (Application.Top.MostFocused == _listView){
108+
new StatusItem(Key.Enter, "~ENTER~ Accept", () =>
109+
{
110+
if (Application.Top.MostFocused == _listView)
111+
{
108112
// If nothing was explicitly marked, we return the item that was selected
109113
// when ENTER is pressed in Single mode. If something was previously selected
110114
// (using SPACE) then honor that as the single item to return
111115
if (_applicationData.OutputMode == OutputModeOption.Single &&
112-
_itemSource.GridViewRowList.Find(i => i.IsMarked) == null) {
116+
_itemSource.GridViewRowList.Find(i => i.IsMarked) == null)
117+
{
113118
_listView.MarkUnmarkRow();
114119
}
115120
Accept();
116121
}
117-
else if (Application.Top.MostFocused == _filterField){
122+
else if (Application.Top.MostFocused == _filterField)
123+
{
118124
_listView.SetFocus();
119125
}
120126
}),
121127
new StatusItem(Key.Esc, "~ESC~ Close", () => Close())
122128
}
123-
: new StatusItem []
129+
: new StatusItem[]
124130
{
125131
new StatusItem(Key.Esc, "~ESC~ Close", () => Close())
126132
}

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

Lines changed: 10 additions & 1 deletion
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.4.1'
12+
ModuleVersion = '0.5.0'
1313

1414
# Supported PSEditions
1515
CompatiblePSEditions = @( 'Core' )
@@ -106,6 +106,15 @@ PrivateData = @{
106106
# ReleaseNotes of this module
107107
ReleaseNotes = '# Release Notes
108108
109+
## v0.5.0
110+
111+
`Out-ConsoleGridView` has been totally refactored!
112+
113+
First off, no more silly F9 menu to accept!
114+
All you have to do is hit `ENTER` to accept your selection or `ESC` to cancel.
115+
116+
Also, `-OutputMode` works as expected now. `Single` lets you only select one item. `Multiple` is the default.
117+
109118
## v0.4.1
110119
111120
* Fix filter indexing to return correct selected objects

src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77
using System.Management.Automation;
88
using System.Management.Automation.Internal;
99
using OutGridView.Models;
10-
using System.Runtime.InteropServices;
1110

1211
namespace OutGridView.Cmdlet
1312
{
14-
/// Enum for SelectionMode parameter.
15-
/// </summary>
1613
[Cmdlet(VerbsData.Out, "ConsoleGridView")]
1714
[Alias("ocgv")]
1815
public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable
@@ -62,7 +59,7 @@ protected override void BeginProcessing()
6259
ErrorCategory.NotImplemented,
6360
null);
6461

65-
this.ThrowTerminatingError(error);
62+
ThrowTerminatingError(error);
6663
}
6764
}
6865

@@ -74,8 +71,7 @@ protected override void ProcessRecord()
7471
return;
7572
}
7673

77-
IDictionary dictionary = InputObject.BaseObject as IDictionary;
78-
if (dictionary != null)
74+
if (InputObject.BaseObject is IDictionary dictionary)
7975
{
8076
// Dictionaries should be enumerated through because the pipeline does not enumerate through them.
8177
foreach (DictionaryEntry entry in dictionary)
@@ -106,7 +102,7 @@ baseObject is PSReference ||
106102
ErrorCategory.InvalidType,
107103
null);
108104

109-
this.ThrowTerminatingError(error);
105+
ThrowTerminatingError(error);
110106
}
111107

112108
_psObjects.Add(input);
@@ -135,15 +131,14 @@ protected override void EndProcessing()
135131

136132

137133
var selectedIndexes = _consoleGui.Start(applicationData);
138-
139134
foreach (int idx in selectedIndexes)
140135
{
141136
var selectedObject = _psObjects[idx];
142137
if (selectedObject == null)
143138
{
144139
continue;
145140
}
146-
this.WriteObject(selectedObject, false);
141+
WriteObject(selectedObject, false);
147142
}
148143
}
149144

0 commit comments

Comments
 (0)