Skip to content

Commit f23c77f

Browse files
committed
Update to .NET 10 and Terminal.Gui 2.0 API
- Bump TargetFramework to net10.0 and update SDK to 10.0.101 - Switch NuGet source to nuget.org; comment out PowerShell feed - Replace UseNetDriver with ForceDriver for driver selection - Refactor app startup for Terminal.Gui 2.0 (IApplication, driver API) - Update UI code for Terminal.Gui 2.0: focus, events, property names - Add support for specifying driver (ansi, windows, unix) via cmdlet - Modernize code with C# 12 features and improve nullability - Standardize help text to "TUI" and clean up comments - Update package references and launch settings for debugging
1 parent 1432452 commit f23c77f

15 files changed

+161
-148
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
3+
<!-- <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> -->
44
</PropertyGroup>
55
</Project>

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<PackageVersion Include="Microsoft.PowerShell.SDK" Version="7.4.7" />
44
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
55
<PackageVersion Include="System.Management.Automation" Version="7.4.7" />
6-
<PackageVersion Include="Terminal.Gui" Version="2.0.0-develop.4636" />
6+
<PackageVersion Include="Terminal.Gui" Version="2.0.0-alpha.3390" />
77
</ItemGroup>
88
</Project>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.405",
3+
"version": "10.0.101",
44
"rollForward": "latestFeature",
55
"allowPrerelease": false
66
}

nuget.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<configuration>
33
<packageSources>
44
<clear />
5-
<add key="PowerShellCore_PublicPackages" value="https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v3/index.json" />
5+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
6+
<!-- <add key="PowerShellCore_PublicPackages" value="https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v3/index.json" /> -->
67
</packageSources>
78
</configuration>

src/Microsoft.PowerShell.ConsoleGuiTools/GridViewDataSource.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,19 @@ public void Render(ListView listView, bool selected, int item, int col, int line
6565
{
6666
listView.Move(col - start, line);
6767

68-
var driver = Application.Driver;
68+
var driver = listView.App?.Driver;
6969
var row = GridViewRowList[item];
70-
driver!.AddStr(row.DisplayString ?? string.Empty);
70+
string displayString = row.DisplayString ?? string.Empty;
71+
// Pad right of display string with spaces to fill width
72+
if (displayString.Length < width)
73+
{
74+
displayString = displayString.PadRight(width);
75+
}
76+
else if (displayString.Length > width)
77+
{
78+
displayString = displayString[..width];
79+
}
80+
driver!.AddStr(displayString);
7181
}
7282

7383
/// <summary>

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\..\ConsoleGuiTools.Common.props" />
33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<LangVersion>preview</LangVersion>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
@@ -13,13 +13,14 @@
1313
- Add ';https://api.nuget.org/v3/index.json' to the end of the RestoreSources property group below
1414
- Uncomment the RestoreSources property group below
1515
-->
16-
<!-- <RestoreSources>$(RestoreSources);../../../gui-cs/Terminal.Gui/Terminal.Gui/bin/Debug</RestoreSources> -->
16+
<!--<RestoreSources>https://api.nuget.org/v3/index.json;$(RestoreSources);../../../gui-cs/Terminal.Gui/Terminal.Gui/bin/Debug</RestoreSources>-->
1717
</PropertyGroup>
1818

1919
<ItemGroup>
2020
<!-- Using local Terminal.Gui build for debugging -->
21-
<ProjectReference Include="..\..\..\gui-cs\Terminal.Gui\Terminal.Gui\Terminal.Gui.csproj" />
22-
<PackageReference Include="Microsoft.PowerShell.SDK" />
21+
<!--<ProjectReference Include="..\..\..\gui-cs\Terminal.Gui\Terminal.Gui\Terminal.Gui.csproj" />-->
22+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.4" />
23+
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4766" />
2324
</ItemGroup>
2425

2526
<ItemGroup>

src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridView.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Configuration;
67
using Microsoft.PowerShell.OutGridView.Models;
78
using Terminal.Gui.App;
89

@@ -19,7 +20,6 @@ namespace Microsoft.PowerShell.ConsoleGuiTools;
1920
/// </remarks>
2021
internal sealed class OutConsoleGridView : IDisposable
2122
{
22-
private bool _cancelled;
2323
private ApplicationData? _applicationData;
2424

2525
/// <summary>
@@ -35,21 +35,13 @@ internal sealed class OutConsoleGridView : IDisposable
3535
public HashSet<int> Run(ApplicationData applicationData)
3636
{
3737
_applicationData = applicationData;
38-
if (_applicationData.UseNetDriver) Application.ForceDriver = "NetDriver";
3938

40-
var window = new OutGridViewWindow(_applicationData);
41-
try
42-
{
43-
Application.Init();
44-
Application.Run(window);
45-
_cancelled = window.Cancelled;
46-
return window.GetSelectedIndexes();
47-
}
48-
finally
49-
{
50-
window?.Dispose();
51-
Application.Shutdown();
52-
}
39+
Terminal.Gui.Configuration.ConfigurationManager.Enable(Terminal.Gui.Configuration.ConfigLocations.All);
40+
41+
using OutGridViewWindow window = new(_applicationData);
42+
using IApplication app = Application.Create().Init(driverName: _applicationData.ForceDriver);
43+
HashSet<int>? selectedIndexes = app.Run(window) as HashSet<int>;
44+
return selectedIndexes ?? [];
5345
}
5446

5547
public void Dispose()

src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable
5050
/// and if it should be possible to select multiple or single list items.
5151
/// </summary>
5252
[Parameter(HelpMessage =
53-
"Determines whether a single item (Single), multiple items (Multiple; default), or no items (None) will be written to the pipeline. Also determines selection behavior in the GUI.")]
53+
"Determines whether a single item (Single), multiple items (Multiple; default), or no items (None) will be written to the pipeline. Also determines selection behavior in the TUI.")]
5454
public OutputModeOption OutputMode { set; get; } = OutputModeOption.Multiple;
5555

5656
/// <summary>
57-
/// Gets or sets the initial value for the filter in the GUI.
57+
/// Gets or sets the initial value for the filter in the TUI.
5858
/// </summary>
5959
[Parameter(HelpMessage =
6060
"Pre-populates the Filter edit box, allowing filtering to be specified on the command line. The filter uses regular expressions.")]
@@ -63,17 +63,15 @@ public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable
6363
/// <summary>
6464
/// Gets or sets a value indicating whether "minimum UI" mode will be enabled.
6565
/// </summary>
66-
[Parameter(HelpMessage = "If specified no window frame, filter box, or status bar will be displayed in the GUI.")]
66+
[Parameter(HelpMessage = "If specified no window frame, filter box, or status bar will be displayed in the TUI.")]
6767
public SwitchParameter MinUI { set; get; }
6868

6969
/// <summary>
70-
/// Gets or sets a value indicating whether the Terminal.Gui System.Net.Console-based Driver will be used
71-
/// instead of the
72-
/// default platform-specific (Windows or Curses) Driver.
70+
/// Gets or sets the Terminal.Gui driver to use.
7371
/// </summary>
7472
[Parameter(HelpMessage =
75-
"If specified the Terminal.Gui System.Net.Console-based Driver (NetDriver) will be used.")]
76-
public SwitchParameter UseNetDriver { set; get; }
73+
"Forces the Terminal.Gui driver to use. Valid values are 'ansi', 'windows', or 'unix'.")]
74+
public string? ForceDriver { set; get; }
7775

7876
/// <summary>
7977
/// Gets or sets a value indicating whether all properties should be displayed instead of just the default display properties.
@@ -171,14 +169,14 @@ protected override void EndProcessing()
171169
OutputMode = OutputMode,
172170
Filter = Filter,
173171
MinUI = MinUI,
174-
UseNetDriver = UseNetDriver,
172+
ForceDriver = ForceDriver,
175173
AllProperties = AllProperties,
176174
Verbose = Verbose,
177175
Debug = Debug,
178176
ModuleVersion = MyInvocation.MyCommand.Version.ToString()
179177
};
180178

181-
var selectedIndexes = _outConsoleGridView.Run(applicationData);
179+
HashSet<int> selectedIndexes = _outConsoleGridView.Run(applicationData);
182180
foreach (var idx in selectedIndexes)
183181
{
184182
var selectedObject = _psObjects[idx];

0 commit comments

Comments
 (0)