Skip to content

Commit 5fd9efd

Browse files
committed
Got SOT working + code cleanup
Refactored `ConsoleGui` and `ShowObjectView` classes to improve readability, maintainability, and adherence to modern C# conventions. Key changes include: - Updated `FILTER_LABEL` to `_Filter` for UI consistency. - Simplified `ConsoleGui` initialization logic and removed redundant `SetNeedsDraw` call. - Rewrote `ShowObjectView` to use nullable fields, modern syntax, and dynamic regex validation. - Refactored `GetChildren` to handle nested objects with a `while` loop. - Improved `CachedMemberResult` and `CachedMemberResultElement` with better encapsulation and naming conventions. - Enhanced `RegexTreeViewTextFilter` with a primary constructor and better regex error handling. - Simplified `Run` method in `ShowObjectView` for cleaner application lifecycle management. - Fixed typos in comments and replaced redundant comments with concise explanations. - General cleanup using modern C# features like expression-bodied methods, pattern matching, and `null`-coalescing operators.
1 parent 4245236 commit 5fd9efd

File tree

2 files changed

+166
-233
lines changed

2 files changed

+166
-233
lines changed

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace OutGridView.Cmdlet;
1818

1919
internal sealed class ConsoleGui : IDisposable
2020
{
21-
private const string FILTER_LABEL = "Filter";
21+
private const string FILTER_LABEL = "_Filter";
2222

2323
// This adjusts the left margin of all controls
2424
private const int MARGIN_LEFT = 1;
@@ -48,10 +48,9 @@ internal sealed class ConsoleGui : IDisposable
4848
public HashSet<int> Start(ApplicationData applicationData)
4949
{
5050
_applicationData = applicationData;
51-
// In Terminal.Gui v2, Application.Init() no longer accepts a driver parameter.
52-
// Instead, use Application.ForceDriver to specify the driver.
5351
if (_applicationData.UseNetDriver) Application.ForceDriver = "NetDriver";
5452
Application.Init();
53+
5554
_gridViewDetails = new GridViewDetails
5655
{
5756
// If OutputMode is Single or Multiple, then we make items selectable. If we make them selectable,
@@ -67,7 +66,7 @@ public HashSet<int> Start(ApplicationData applicationData)
6766
var gridHeaders = _applicationData.DataTable.DataColumns.Select(c => c.Label).ToList();
6867

6968
// Copy the input DataTable into our master ListView source list; upon exit any items
70-
// that are IsMarked are returned (if Outputmode is set)
69+
// that are IsMarked are returned (if OutputMode is set)
7170
_inputSource = LoadData();
7271

7372
if (!_applicationData.MinUI)
@@ -85,8 +84,8 @@ public HashSet<int> Start(ApplicationData applicationData)
8584
AddStatusBar(win, !_applicationData.MinUI);
8685

8786
// We *always* apply a filter, even if the -Filter parameter is not set or Filtering is not
88-
// available. The ListView always shows a fitlered version of _inputSource even if there is no
89-
// actual fitler.
87+
// available. The ListView always shows a filtered version of _inputSource even if there is no
88+
// actual filter.
9089
//ApplyFilter();
9190

9291
_listView?.SetFocus();
@@ -383,7 +382,6 @@ private void AddFilter(Window win)
383382
try
384383
{
385384
_filterErrorView.Text = string.Empty;
386-
_filterErrorView.SetNeedsDraw();
387385
_applicationData!.Filter = filterText!;
388386
ApplyFilter();
389387
}

0 commit comments

Comments
 (0)