Skip to content

Commit 4714dd4

Browse files
authored
Fix clear last line on Windows Terminal Issue again (#207)
* Added more debug flags including -UseSystemConsole * Added more debug flags including -UseNetDriver * Reverted temp package refs; requires Terminal.Gui 1.13.6 * Support local nuget feed for Terminal.Gui for dev * Update local build script further * Enhanced Build script to publish module locally * Enhanced Build script to increment build number automatically * Undo local build; set Terminal.Gui v to 1.14.0 * Tweaked build scripts * Removed local build setting * Verifying CI failure is due to new Terminal.Gui version requirement * Bump to .NET 7.0.401 * Removed old verbose mode code * Removed extra lines * Removed unneeded sln file
1 parent b5a4bcd commit 4714dd4

File tree

11 files changed

+110
-17
lines changed

11 files changed

+110
-17
lines changed

.vsts-ci/templates/ci-general.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ steps:
1212
pwsh: ${{ parameters.pwsh }}
1313

1414
- task: UseDotNet@2
15-
displayName: Install .NET 6.0.x SDK
15+
displayName: Install .NET 7.0.x SDK
1616
inputs:
1717
packageType: sdk
18-
version: 6.0.x
18+
version: 7.0.x
1919
performMultiLevelLookup: true
2020

2121
- task: PowerShell@2

Build.ps1

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,56 @@
22
# GraphicalTools includes two modules: Microsoft.PowerShell.GraphicalTools and Microsoft.PowerShell.ConsoleGuiTools
33
# To build them all leave -ModuleName off the `InvokeBuild` command (e.g. Invoke-Build Build).
44
# To build only one, specify it using the -ModuleName paramater (e.g. Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools).
5+
$ModuleName = "Microsoft.PowerShell.ConsoleGuiTools"
6+
$BuildPath = "$PSScriptRoot/module/$ModuleName"
7+
$PsdPath = "src/$ModuleName/$ModulePath/$($ModuleName).psd1"
8+
9+
# Assume this is the first build
10+
$build = 0
11+
12+
$psd1Content = Get-Content $PsdPath -Raw -ErrorAction SilentlyContinue
13+
if ($psd1Content) {
14+
# Extract the ModuleVersion from the .psd1 content using regular expression
15+
if ($psd1Content -match "ModuleVersion\s+=\s+'(.*?)'") {
16+
$prevVersion = $Matches[1]
17+
$prevVersionParts = $prevVersion -split '\.'
18+
$build = [int]$prevVersionParts[3] + 1
19+
$ModuleVersion = "{0}.{1}.{2}.{3}" -f $prevVersionParts[0], $prevVersionParts[1], $prevVersionParts[2], $build
20+
}
21+
else {
22+
"No previous version found. Assuming this is the first build."
23+
# Get the ModuleVersion using dotnet-gitversion
24+
$prevVersion = "1.0.0.0"
25+
$ModuleVersion = "$($prevVersion)"
26+
}
27+
"Rewriting $PsdPath with new ModuleVersion: $ModuleVersion"
28+
$updatedpsd1Content = $psd1Content -replace "ModuleVersion\s+=\s+'([\d\.]+)'", "ModuleVersion = '$ModuleVersion'"
29+
$updatedpsd1Content | Out-File -FilePath $PsdPath -Encoding ascii
30+
}
31+
else {
32+
throw "$PsdPath not found."
33+
}
34+
35+
"Buildihg $ModuleName..."
36+
Invoke-Build Build -ModuleName $ModuleName
37+
38+
# Publish to a local PSRepository to enable downstream dependenies to use development builds
39+
# - If `local` doesn't exist, create with `Register-PSRepository -Name local -SourceLocation "~/psrepo" -InstallationPolicy Trusted`
40+
$localRepository = Get-PSRepository | Where-Object { $_.Name -eq 'local' }
41+
if ($localRepository) {
42+
$localRepositoryPath = $localRepository | Select-Object -ExpandProperty SourceLocation
43+
# Un-publishing $ModuleName from local repository at $localRepositoryPath"
44+
Remove-Item "${localRepositoryPath}/${ModuleName}.{$ModuleVersion}.nupkg" -Recurse -Force -ErrorAction SilentlyContinue
45+
"Publishing ${localRepositoryPath}/${ModuleName}.$ModuleVersion.nupkg to `local'"
46+
Publish-Module -Path $BuildPath -Repository 'local'
47+
}
548

6-
# Build...
7-
Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools
849

950
# Run what was built as a bit of test of:
1051
# - Scale: recursive ls of the project
1152
# - Filter: proving regex works
1253
# - SelectMultiple
13-
pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.ConsoleGuiTools'; Get-ChildItem -Recurse | Out-ConsoleGridView -OutputMode Multiple -Title 'Imported Modules' -Filter \.xml"
54+
$testCommand = "Get-ChildItem -Recurse | Out-ConsoleGridView -Debug -OutputMode Multiple -Title 'Imported Modules' -Filter \.xml"
55+
"Running test in new pwsh session: $testCommand"
56+
pwsh -noprofile -command "Import-Module -verbose $BuildPath; $testCommand"
57+
"Test exited. Build complete."

GraphicalTools.build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ param(
88

99
$script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows
1010

11-
$script:TargetFramework = "net6.0"
11+
$script:TargetFramework = "net7.0"
1212
$script:RequiredSdkVersion = (Get-Content (Join-Path $PSScriptRoot 'global.json') | ConvertFrom-Json).sdk.version
1313

1414
$script:ModuleLayouts = @{}

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "6.0.400"
3+
"version": "7.0.401"
44
}
55
}

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Linq;
8+
using System.Reflection;
79
using System.Text;
810
using NStack;
911
using OutGridView.Models;
@@ -36,8 +38,11 @@ internal class ConsoleGui : IDisposable
3638

3739
public HashSet<int> Start(ApplicationData applicationData)
3840
{
39-
Application.Init();
4041
_applicationData = applicationData;
42+
// Note, in Terminal.Gui v2, this property is renamed to Application.UseNetDriver, hence
43+
// using that terminology here.
44+
Application.UseSystemConsole = _applicationData.UseNetDriver;
45+
Application.Init();
4146
_gridViewDetails = new GridViewDetails
4247
{
4348
// If OutputMode is Single or Multiple, then we make items selectable. If we make them selectable,
@@ -235,6 +240,12 @@ private void AddStatusBar(bool visible)
235240
}
236241

237242
statusItems.Add(new StatusItem(Key.Esc, "~ESC~ Close", () => Close()));
243+
if (_applicationData.Verbose || _applicationData.Debug)
244+
{
245+
statusItems.Add(new StatusItem(Key.Null, $" v{_applicationData.ModuleVersion}", null));
246+
statusItems.Add(new StatusItem(Key.Null,
247+
$"{Application.Driver} v{FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(Application)).Location).ProductVersion}", null));
248+
}
238249

239250
var statusBar = new StatusBar(statusItems.ToArray());
240251
statusBar.Visible = visible;

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\..\GraphicalTools.Common.props" />
33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<!-- To pull Terminal.Gui from a local nuget source:
9+
- Build Terminal.Gui locally in ../../gui-cs/Terminal.Gui
10+
- Change Terminal.Gui Version= to "major.minor.patch-*"
11+
- Add ';https://api.nuget.org/v3/index.json' to the end of the RestoreSources property group below
12+
- Uncomment the RestoreSources property group below
13+
-->
14+
<!-- <RestoreSources>$(RestoreSources);../../../gui-cs/Terminal.Gui/Terminal.Gui/bin/Debug</RestoreSources> -->
515
</PropertyGroup>
616

717
<ItemGroup>

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

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

1111
# Version number of this module.
12-
ModuleVersion = '0.7.4'
12+
# NOTE: This will get updated by build.ps1; the build number will be incremented for each build.
13+
ModuleVersion = '0.7.5.35'
1314

1415
# Supported PSEditions
1516
CompatiblePSEditions = @( 'Core' )
@@ -105,6 +106,11 @@ PrivateData = @{
105106

106107
# ReleaseNotes of this module
107108
ReleaseNotes = '# Release Notes
109+
## v0.7.5
110+
111+
* Adds support for -Diagnostic switch to Out-ConsoleGridView #208
112+
* Adds support for -UseNetDriver switch to Out-ConsoleGridView #208
113+
108114
## v0.7.4
109115
110116
* Fixes last line not cleared on exit in WT by updating to Terminal.Gui v1.13.5 #205

src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable
5858
[Parameter(HelpMessage = "If specified no window frame, filter box, or status bar will be displayed in the GUI.")]
5959
public SwitchParameter MinUI { set; get; }
6060

61+
/// <summary>
62+
/// gets or sets the whether the Terminal.Gui System.Net.Console-based ConsoleDriver will be used instead of the
63+
/// default platform-specific (Windows or Curses) ConsoleDriver.
64+
/// </summary>
65+
[Parameter(HelpMessage = "If specified the Terminal.Gui System.Net.Console-based ConsoleDriver (NetDriver) will be used.")]
66+
public SwitchParameter UseNetDriver { set; get; }
67+
68+
/// <summary>
69+
/// For the -Verbose switch
70+
/// </summary>
71+
public bool Verbose => MyInvocation.BoundParameters.TryGetValue("Verbose", out var o);
72+
73+
/// <summary>
74+
/// For the -Debug switch
75+
/// </summary>
76+
public bool Debug => MyInvocation.BoundParameters.TryGetValue("Debug", out var o);
77+
6178
#endregion Input Parameters
6279

6380
// This method gets called once for each cmdlet in the pipeline when the pipeline starts executing
@@ -140,7 +157,11 @@ protected override void EndProcessing()
140157
OutputMode = OutputMode,
141158
Filter = Filter,
142159
MinUI = MinUI,
143-
DataTable = dataTable
160+
DataTable = dataTable,
161+
UseNetDriver = UseNetDriver,
162+
Verbose = Verbose,
163+
Debug = Debug,
164+
ModuleVersion = MyInvocation.MyCommand.Version.ToString()
144165
};
145166

146167

src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ public DataTable CastObjectsToTableView(List<PSObject> psObjects)
167167

168168
var dataTableColumns = GetDataColumnsForObject(psObjects);
169169

170-
foreach (var dataColumn in dataTableColumns)
171-
{
172-
_cmdlet.WriteVerbose(dataColumn.ToString());
173-
}
174-
175170
List<DataTableRow> dataTableRows = new List<DataTableRow>();
176171
for (var i = 0; i < objectFormats.Count; i++)
177172
{

src/Microsoft.PowerShell.OutGridView.Models/ApplicationData.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,11 @@ public class ApplicationData
1414
public string Filter { get; set; }
1515
public bool MinUI { get; set; }
1616
public DataTable DataTable { get; set; }
17+
18+
public bool UseNetDriver { get; set; }
19+
public bool Verbose { get; set; }
20+
public bool Debug { get; set; }
21+
22+
public string ModuleVersion { get; set; }
1723
}
1824
}

0 commit comments

Comments
 (0)