Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vsts-ci/templates/ci-general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ steps:
pwsh: ${{ parameters.pwsh }}

- task: UseDotNet@2
displayName: Install .NET 6.0.x SDK
displayName: Install .NET 7.0.x SDK
inputs:
packageType: sdk
version: 6.0.x
version: 7.0.x
performMultiLevelLookup: true

- task: PowerShell@2
Expand Down
50 changes: 47 additions & 3 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,56 @@
# GraphicalTools includes two modules: Microsoft.PowerShell.GraphicalTools and Microsoft.PowerShell.ConsoleGuiTools
# To build them all leave -ModuleName off the `InvokeBuild` command (e.g. Invoke-Build Build).
# To build only one, specify it using the -ModuleName paramater (e.g. Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools).
$ModuleName = "Microsoft.PowerShell.ConsoleGuiTools"
$BuildPath = "$PSScriptRoot/module/$ModuleName"
$PsdPath = "src/$ModuleName/$ModulePath/$($ModuleName).psd1"

# Assume this is the first build
$build = 0

$psd1Content = Get-Content $PsdPath -Raw -ErrorAction SilentlyContinue
if ($psd1Content) {
# Extract the ModuleVersion from the .psd1 content using regular expression
if ($psd1Content -match "ModuleVersion\s+=\s+'(.*?)'") {
$prevVersion = $Matches[1]
$prevVersionParts = $prevVersion -split '\.'
$build = [int]$prevVersionParts[3] + 1
$ModuleVersion = "{0}.{1}.{2}.{3}" -f $prevVersionParts[0], $prevVersionParts[1], $prevVersionParts[2], $build
}
else {
"No previous version found. Assuming this is the first build."
# Get the ModuleVersion using dotnet-gitversion
$prevVersion = "1.0.0.0"
$ModuleVersion = "$($prevVersion)"
}
"Rewriting $PsdPath with new ModuleVersion: $ModuleVersion"
$updatedpsd1Content = $psd1Content -replace "ModuleVersion\s+=\s+'([\d\.]+)'", "ModuleVersion = '$ModuleVersion'"
$updatedpsd1Content | Out-File -FilePath $PsdPath -Encoding ascii
}
else {
throw "$PsdPath not found."
}

"Buildihg $ModuleName..."
Invoke-Build Build -ModuleName $ModuleName

# Publish to a local PSRepository to enable downstream dependenies to use development builds
# - If `local` doesn't exist, create with `Register-PSRepository -Name local -SourceLocation "~/psrepo" -InstallationPolicy Trusted`
$localRepository = Get-PSRepository | Where-Object { $_.Name -eq 'local' }
if ($localRepository) {
$localRepositoryPath = $localRepository | Select-Object -ExpandProperty SourceLocation
# Un-publishing $ModuleName from local repository at $localRepositoryPath"
Remove-Item "${localRepositoryPath}/${ModuleName}.{$ModuleVersion}.nupkg" -Recurse -Force -ErrorAction SilentlyContinue
"Publishing ${localRepositoryPath}/${ModuleName}.$ModuleVersion.nupkg to `local'"
Publish-Module -Path $BuildPath -Repository 'local'
}

# Build...
Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools

# Run what was built as a bit of test of:
# - Scale: recursive ls of the project
# - Filter: proving regex works
# - SelectMultiple
pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.ConsoleGuiTools'; Get-ChildItem -Recurse | Out-ConsoleGridView -OutputMode Multiple -Title 'Imported Modules' -Filter \.xml"
$testCommand = "Get-ChildItem -Recurse | Out-ConsoleGridView -Debug -OutputMode Multiple -Title 'Imported Modules' -Filter \.xml"
"Running test in new pwsh session: $testCommand"
pwsh -noprofile -command "Import-Module -verbose $BuildPath; $testCommand"
"Test exited. Build complete."
2 changes: 1 addition & 1 deletion GraphicalTools.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ param(

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

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

$script:ModuleLayouts = @{}
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "6.0.400"
"version": "7.0.401"
}
}
13 changes: 12 additions & 1 deletion src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using NStack;
using OutGridView.Models;
Expand Down Expand Up @@ -36,8 +38,11 @@ internal class ConsoleGui : IDisposable

public HashSet<int> Start(ApplicationData applicationData)
{
Application.Init();
_applicationData = applicationData;
// Note, in Terminal.Gui v2, this property is renamed to Application.UseNetDriver, hence
// using that terminology here.
Application.UseSystemConsole = _applicationData.UseNetDriver;
Application.Init();
_gridViewDetails = new GridViewDetails
{
// If OutputMode is Single or Multiple, then we make items selectable. If we make them selectable,
Expand Down Expand Up @@ -235,6 +240,12 @@ private void AddStatusBar(bool visible)
}

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

var statusBar = new StatusBar(statusItems.ToArray());
statusBar.Visible = visible;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\GraphicalTools.Common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<!-- To pull Terminal.Gui from a local nuget source:
- Build Terminal.Gui locally in ../../gui-cs/Terminal.Gui
- Change Terminal.Gui Version= to "major.minor.patch-*"
- Add ';https://api.nuget.org/v3/index.json' to the end of the RestoreSources property group below
- Uncomment the RestoreSources property group below
-->
<!-- <RestoreSources>$(RestoreSources);../../../gui-cs/Terminal.Gui/Terminal.Gui/bin/Debug</RestoreSources> -->
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
RootModule = 'Microsoft.PowerShell.ConsoleGuiTools.dll'

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

# Supported PSEditions
CompatiblePSEditions = @( 'Core' )
Expand Down Expand Up @@ -105,6 +106,11 @@ PrivateData = @{

# ReleaseNotes of this module
ReleaseNotes = '# Release Notes
## v0.7.5
* Adds support for -Diagnostic switch to Out-ConsoleGridView #208
* Adds support for -UseNetDriver switch to Out-ConsoleGridView #208
## v0.7.4
* Fixes last line not cleared on exit in WT by updating to Terminal.Gui v1.13.5 #205
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable
[Parameter(HelpMessage = "If specified no window frame, filter box, or status bar will be displayed in the GUI.")]
public SwitchParameter MinUI { set; get; }

/// <summary>
/// gets or sets the whether the Terminal.Gui System.Net.Console-based ConsoleDriver will be used instead of the
/// default platform-specific (Windows or Curses) ConsoleDriver.
/// </summary>
[Parameter(HelpMessage = "If specified the Terminal.Gui System.Net.Console-based ConsoleDriver (NetDriver) will be used.")]
public SwitchParameter UseNetDriver { set; get; }

/// <summary>
/// For the -Verbose switch
/// </summary>
public bool Verbose => MyInvocation.BoundParameters.TryGetValue("Verbose", out var o);

/// <summary>
/// For the -Debug switch
/// </summary>
public bool Debug => MyInvocation.BoundParameters.TryGetValue("Debug", out var o);

#endregion Input Parameters

// This method gets called once for each cmdlet in the pipeline when the pipeline starts executing
Expand Down Expand Up @@ -140,7 +157,11 @@ protected override void EndProcessing()
OutputMode = OutputMode,
Filter = Filter,
MinUI = MinUI,
DataTable = dataTable
DataTable = dataTable,
UseNetDriver = UseNetDriver,
Verbose = Verbose,
Debug = Debug,
ModuleVersion = MyInvocation.MyCommand.Version.ToString()
};


Expand Down
5 changes: 0 additions & 5 deletions src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ public DataTable CastObjectsToTableView(List<PSObject> psObjects)

var dataTableColumns = GetDataColumnsForObject(psObjects);

foreach (var dataColumn in dataTableColumns)
{
_cmdlet.WriteVerbose(dataColumn.ToString());
}

List<DataTableRow> dataTableRows = new List<DataTableRow>();
for (var i = 0; i < objectFormats.Count; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@ public class ApplicationData
public string Filter { get; set; }
public bool MinUI { get; set; }
public DataTable DataTable { get; set; }

public bool UseNetDriver { get; set; }
public bool Verbose { get; set; }
public bool Debug { get; set; }

public string ModuleVersion { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\GraphicalTools.Common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down