From dfb2523835b1bb3b06ce02aa82283e96f29f29a5 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 11 Jul 2022 14:28:17 -0700 Subject: [PATCH 1/2] Remove ANSI escape characters from strings in object properties --- .../OutConsoleGridviewCmdletCommand.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs index 3f8a623..6fd0e58 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs @@ -111,6 +111,16 @@ baseObject is PSReference || ThrowTerminatingError(error); } + // Remove any potential ANSI escape codes from strings + foeach (var property in input.Properties) + { + if (property.Value is string) + { + var stringDecorated = new StringDecorated(property.Value as string); + property.Value = stringDecorated.ToString(OutputRendering.PlainText); + } + } + _psObjects.Add(input); } From cde05d4366419045d650b98de8bef37ede6dc555 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL)" Date: Mon, 11 Jul 2022 15:47:22 -0700 Subject: [PATCH 2/2] Change build to .NET 6.0 to use PS7.2 to remove ANSI from string properties --- .vscode/launch.json | 4 ++-- GraphicalTools.build.ps1 | 14 +++++++------- global.json | 2 +- .../Microsoft.PowerShell.ConsoleGuiTools.csproj | 8 ++++---- .../Microsoft.PowerShell.ConsoleGuiTools.psd1 | 2 +- .../OutConsoleGridviewCmdletCommand.cs | 10 ---------- .../TypeGetter.cs | 6 ++++-- .../Microsoft.PowerShell.GraphicalTools.csproj | 2 +- .../Microsoft.PowerShell.OutGridView.Models.csproj | 2 +- src/OutGridView.Gui/OutGridView.Gui.csproj | 2 +- 10 files changed, 22 insertions(+), 30 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d7be52a..17f330a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/Cmdlet/bin/Debug/netcoreapp3.0/win10-x64/OutGridViewCmdlet.dll", + "program": "${workspaceFolder}/Cmdlet/bin/Debug/net6.0/win10-x64/OutGridViewCmdlet.dll", "args": [], "cwd": "${workspaceFolder}/Cmdlet", "console": "internalConsole", @@ -20,7 +20,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/Application/bin/Debug/netcoreapp3.0/win10-x64/OutGridViewApplication.dll", + "program": "${workspaceFolder}/Application/bin/Debug/net6.0/win10-x64/OutGridViewApplication.dll", "args": [], "cwd": "${workspaceFolder}/Application", "console": "internalConsole", diff --git a/GraphicalTools.build.ps1 b/GraphicalTools.build.ps1 index dbbeef9..ce56bc1 100644 --- a/GraphicalTools.build.ps1 +++ b/GraphicalTools.build.ps1 @@ -3,14 +3,14 @@ param( [ValidateSet("Debug", "Release")] [string]$Configuration = "Debug", - [string[]]$ModuleName = @( - "Microsoft.PowerShell.GraphicalTools", - "Microsoft.PowerShell.ConsoleGuiTools" ) + [string[]]$ModuleName = @( + #"Microsoft.PowerShell.GraphicalTools", + "Microsoft.PowerShell.ConsoleGuiTools" ) ) $script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows -$script:TargetFramework = "netcoreapp3.0" +$script:TargetFramework = "net6.0" $script:RequiredSdkVersion = (Get-Content (Join-Path $PSScriptRoot 'global.json') | ConvertFrom-Json).sdk.version $script:ModuleLayouts = @{} @@ -152,12 +152,12 @@ task LayoutModule -After Build { foreach ($projectName in $moduleLayout.NativeBuildAssets.Keys) { foreach ($targetPlatform in $moduleLayout.NativeBuildAssets[$projectName]) { $destDir = Join-Path $moduleBinPath $projectName $targetPlatform - + $null = New-Item -Force $destDir -Type Directory - + # Get the project build dir path $publishPath = [System.IO.Path]::Combine($PSScriptRoot, 'src', $projectName, 'bin', $Configuration, $script:TargetFramework, $targetPlatform, "publish\*" ) - + Write-Host $publishPath # Binplace the asset Copy-Item -Recurse -Force $publishPath $destDir diff --git a/global.json b/global.json index 1e85f0e..fe0b480 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "3.1.102" + "version": "6.0.100" } } diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj index c957b30..2bd6ac6 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj @@ -1,13 +1,13 @@ - netcoreapp3.0 + net6.0 - - - + + + diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 index 4f65515..cd72692 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 @@ -30,7 +30,7 @@ Copyright = '(c) Microsoft Corporation.' Description = 'Cross-platform Console Gui Tools for PowerShell' # Minimum version of the PowerShell engine required by this module -PowerShellVersion = '6.2' +PowerShellVersion = '7.2' # Name of the PowerShell host required by this module # PowerShellHostName = '' diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs index 6fd0e58..3f8a623 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs @@ -111,16 +111,6 @@ baseObject is PSReference || ThrowTerminatingError(error); } - // Remove any potential ANSI escape codes from strings - foeach (var property in input.Properties) - { - if (property.Value is string) - { - var stringDecorated = new StringDecorated(property.Value as string); - property.Value = stringDecorated.ToString(OutputRendering.PlainText); - } - } - _psObjects.Add(input); } diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs index c9bbbff..d1c57a7 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs @@ -3,6 +3,7 @@ using System; using System.Management.Automation; +using System.Management.Automation.Internal; using System.Linq; using System.Globalization; using System.Collections.Generic; @@ -26,7 +27,7 @@ public FormatViewDefinition GetFormatViewDefinitionForObject(PSObject obj) var types = _cmdlet.InvokeCommand.InvokeScript(@"Microsoft.PowerShell.Utility\Get-FormatData " + typeName).ToList(); //No custom type definitions found - try the PowerShell specific format data - if (types == null || types.Count == 0) + if (types == null || types.Count == 0) { types = _cmdlet.InvokeCommand .InvokeScript(@"Microsoft.PowerShell.Utility\Get-FormatData -PowerShellVersion $PSVersionTable.PSVersion " + typeName).ToList(); @@ -62,7 +63,8 @@ public DataTableRow CastObjectToDataTableRow(PSObject ps, List } else { - valuePairs[dataColumn.ToString()] = new StringValue { DisplayValue = stringValue }; + var stringDecorated = new StringDecorated(stringValue); + valuePairs[dataColumn.ToString()] = new StringValue { DisplayValue = stringDecorated.ToString(OutputRendering.PlainText) }; } } diff --git a/src/Microsoft.PowerShell.GraphicalTools/Microsoft.PowerShell.GraphicalTools.csproj b/src/Microsoft.PowerShell.GraphicalTools/Microsoft.PowerShell.GraphicalTools.csproj index 45b17d0..b762ac9 100644 --- a/src/Microsoft.PowerShell.GraphicalTools/Microsoft.PowerShell.GraphicalTools.csproj +++ b/src/Microsoft.PowerShell.GraphicalTools/Microsoft.PowerShell.GraphicalTools.csproj @@ -1,7 +1,7 @@ - netcoreapp3.0 + net6.0 diff --git a/src/Microsoft.PowerShell.OutGridView.Models/Microsoft.PowerShell.OutGridView.Models.csproj b/src/Microsoft.PowerShell.OutGridView.Models/Microsoft.PowerShell.OutGridView.Models.csproj index 4c6378b..c7ed7c6 100644 --- a/src/Microsoft.PowerShell.OutGridView.Models/Microsoft.PowerShell.OutGridView.Models.csproj +++ b/src/Microsoft.PowerShell.OutGridView.Models/Microsoft.PowerShell.OutGridView.Models.csproj @@ -1,7 +1,7 @@ - netcoreapp3.0 + net6.0 diff --git a/src/OutGridView.Gui/OutGridView.Gui.csproj b/src/OutGridView.Gui/OutGridView.Gui.csproj index e8e8818..a275569 100644 --- a/src/OutGridView.Gui/OutGridView.Gui.csproj +++ b/src/OutGridView.Gui/OutGridView.Gui.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.0 + net6.0