From 6af1903d8c461a02cd94d461a756164d0a3bc888 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Wed, 11 Mar 2020 15:55:02 -0700 Subject: [PATCH 1/9] Fixed #58: Multi-line commands rendering wrong --- src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs index e0e27cd..07eb4bd 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using OutGridView.Models; using Terminal.Gui; @@ -164,6 +165,11 @@ private static string GetPaddedString(List strings, int[] colWidths, int builder.Append(' '); } + // Replace any newlines with encoded newline (`n) + // Note we can't use Environment.Newline because we don't know that the + // Command honors that. + strings[i] = strings[i].Replace("\n", "`n"); + // If the string won't fit in the column, append an ellipsis. if (strings[i].Length > colWidths[i]) { From a69373eae9534aaf1a771f372982b5ea03ecc6de Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Wed, 11 Mar 2020 16:00:25 -0700 Subject: [PATCH 2/9] Fixed #58 - Newlines in commands render incorrectly --- src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs index 07eb4bd..19deced 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Text.RegularExpressions; using OutGridView.Models; using Terminal.Gui; From f155262ca88adaab5c49c16fd232b789d6c32abe Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Wed, 11 Mar 2020 16:30:01 -0700 Subject: [PATCH 3/9] Added debug instructions to readme --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 073a375..5672e70 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,35 @@ Get-Process | Out-ConsoleGridView > NOTE: If you change the code and rebuild the project, you'll need to launch a > _new_ PowerShell process since the dll is already loaded and can't be unloaded. +### Debugging in Visual Studio Code + + +```powershell +PS C:\path\to\GraphicalTools> code . +``` + +Build by hitting `Ctrl-Shift-b` in VS Code. + +To debug: + +In a Powershell session in the `c:\path\to\GraphicalTools` directory, run `pwsh` (thus nesting powershell). + +Then do the folowing: + +```powershell +Import-Module .\module\Microsoft.PowerShell.ConsoleGuiTools +$pid +``` + +This will import the latest built DLL and output the process ID you'll need for debugging. Copy this ID to the clipboard. + +In VScode, set your breakpoints, etc... Then hit `F5`. In the VScode search box, paste the value printed by `$pid`. You'll see something like `pwsh.exe 18328`. Click that and the debug session will start. + +In the Powershell session run your commands; breakpoints will be hit, etc... + +When done, run `exit` to exit the nested PowerShell and run `pwsh` again. This unloads the DLL. Repeat. + + ## Contributions Welcome! We would love to incorporate community contributions into this project. If you would like to From 440833ea33563e47efbb1c2558be67fd125291ef Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Wed, 11 Mar 2020 16:31:28 -0700 Subject: [PATCH 4/9] Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs Co-Authored-By: Tyler James Leonhardt --- src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs index 19deced..e784836 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs @@ -167,6 +167,7 @@ private static string GetPaddedString(List strings, int[] colWidths, int // Replace any newlines with encoded newline (`n) // Note we can't use Environment.Newline because we don't know that the // Command honors that. + strings[i] = strings[i].Replace("\r\n", "`r`n"); strings[i] = strings[i].Replace("\n", "`n"); // If the string won't fit in the column, append an ellipsis. From dd2e765f705d9914aee7ad1b4e6cde2eeafcc432 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Wed, 11 Mar 2020 19:45:23 -0700 Subject: [PATCH 5/9] simplified stripping of newline/linefeed --- src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs index e784836..2692d5b 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs @@ -164,10 +164,10 @@ private static string GetPaddedString(List strings, int[] colWidths, int builder.Append(' '); } - // Replace any newlines with encoded newline (`n) + // Replace any newlines with encoded newline/linefeed (`n or `r) // Note we can't use Environment.Newline because we don't know that the // Command honors that. - strings[i] = strings[i].Replace("\r\n", "`r`n"); + strings[i] = strings[i].Replace("\r", "`r"); strings[i] = strings[i].Replace("\n", "`n"); // If the string won't fit in the column, append an ellipsis. From a54d7d31848985507ec406fd80eb72cd2edad2b4 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Fri, 3 Jun 2022 15:06:29 +1200 Subject: [PATCH 6/9] Updated references to latest Terminal.Gui --- README.md | 4 +++- global.json | 2 +- .../Microsoft.PowerShell.ConsoleGuiTools.csproj | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d762d96..4c9770f 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,10 @@ Now you're ready to build the code. You can do so in one of two ways: PS ./GraphicalTools> Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools ``` -From there you can import the module that you just built for example: +From there you can import the module that you just built for example (start a fresh `pwsh` instance first so you can unload the module with an `exit`; otherwise building again may fail because the `.dll` will be held open): ```powershell +pwsh Import-Module ./module/Microsoft.PowerShell.ConsoleGuiTools ``` @@ -59,6 +60,7 @@ And then run the cmdlet you want to test, for example: ```powershell Get-Process | Out-ConsoleGridView +exit ``` > NOTE: If you change the code and rebuild the project, you'll need to launch a diff --git a/global.json b/global.json index 1e85f0e..b8cfb5c 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "3.1.102" + "version": "3.1.*" } } diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj index c957b30..48dfbd1 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj @@ -5,8 +5,8 @@ - - + + From 7134c167ddac3688435db71917505c60def76a12 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Fri, 3 Jun 2022 22:47:57 +1200 Subject: [PATCH 7/9] Fixed #131 and upgraded to terminal.gui 1.6, pwsh 7.2, and net60 --- .vscode/launch.json | 4 ++-- .vscode/tasks.json | 2 +- Build.ps1 | 2 +- GraphicalTools.build.ps1 | 2 +- global.json | 2 +- .../Microsoft.PowerShell.ConsoleGuiTools.csproj | 5 +++-- .../Microsoft.PowerShell.ConsoleGuiTools.psd1 | 11 +++++++++-- .../TypeGetter.cs | 5 ++++- .../Microsoft.PowerShell.GraphicalTools.csproj | 4 ++-- .../Microsoft.PowerShell.OutGridView.Models.csproj | 2 +- src/OutGridView.Gui/OutGridView.Gui.csproj | 2 +- 11 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d7be52a..b079d9a 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/net60/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/net60/win10-x64/OutGridViewApplication.dll", "args": [], "cwd": "${workspaceFolder}/Application", "console": "internalConsole", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0056896..48c411a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,7 +7,7 @@ "command": "/usr/local/bin/pwsh" }, "windows": { - "command": "pwsh.exe" + "command": "C:/Program Files/PowerShell/7-preview/pwsh.exe" }, "linux": { "command": "/usr/local/bin/pwsh" diff --git a/Build.ps1 b/Build.ps1 index fd2eeff..a2f7bbb 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -8,4 +8,4 @@ Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools # Run what was built... # pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.GraphicalTools'; Get-Module -all | Out-GridView -OutputMode Single -Title 'Imported Modules' -pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.ConsoleGuiTools'; Get-Module -all | Out-ConsoleGridView -OutputMode Single -Title 'Imported Modules' -Filter power" \ No newline at end of file +pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.ConsoleGuiTools'; Get-Module -all | Out-ConsoleGridView -OutputMode Single -Title 'Imported Modules'" \ No newline at end of file diff --git a/GraphicalTools.build.ps1 b/GraphicalTools.build.ps1 index dbbeef9..38a2255 100644 --- a/GraphicalTools.build.ps1 +++ b/GraphicalTools.build.ps1 @@ -10,7 +10,7 @@ param( $script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows -$script:TargetFramework = "netcoreapp3.0" +$script:TargetFramework = "net60" $script:RequiredSdkVersion = (Get-Content (Join-Path $PSScriptRoot 'global.json') | ConvertFrom-Json).sdk.version $script:ModuleLayouts = @{} diff --git a/global.json b/global.json index b8cfb5c..e96609f 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "3.1.*" + "version": "6.0.300" } } diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj index 48dfbd1..329c2d9 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj @@ -1,13 +1,14 @@ - netcoreapp3.0 + net60 - + + diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 index 4f65515..27e839f 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 @@ -9,7 +9,7 @@ RootModule = 'Microsoft.PowerShell.ConsoleGuiTools.dll' # Version number of this module. -ModuleVersion = '0.6.3' +ModuleVersion = '0.7.2' # Supported PSEditions CompatiblePSEditions = @( 'Core' ) @@ -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 = '' @@ -105,6 +105,13 @@ PrivateData = @{ # ReleaseNotes of this module ReleaseNotes = '# Release Notes +## v0.7.0 + +Upugraded to PS 7.2 and net60 + +Updated Terminal.Gui to 1.6 + +Fixed #131 - Strip ANSI ## v0.6.3 diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs index c9bbbff..9b1a5a9 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs @@ -1,13 +1,14 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -using System; +using System; using System.Management.Automation; using System.Linq; using System.Globalization; using System.Collections.Generic; using Microsoft.PowerShell.Commands; using OutGridView.Models; +using System.Text.RegularExpressions; namespace OutGridView.Cmdlet { @@ -62,6 +63,8 @@ public DataTableRow CastObjectToDataTableRow(PSObject ps, List } else { + // Strip ANSI + stringValue = new Regex(@"\x1B\[[^@-~]*[@-~]").Replace(stringValue, ""); valuePairs[dataColumn.ToString()] = new StringValue { DisplayValue = stringValue }; } } diff --git a/src/Microsoft.PowerShell.GraphicalTools/Microsoft.PowerShell.GraphicalTools.csproj b/src/Microsoft.PowerShell.GraphicalTools/Microsoft.PowerShell.GraphicalTools.csproj index 45b17d0..641b030 100644 --- a/src/Microsoft.PowerShell.GraphicalTools/Microsoft.PowerShell.GraphicalTools.csproj +++ b/src/Microsoft.PowerShell.GraphicalTools/Microsoft.PowerShell.GraphicalTools.csproj @@ -1,11 +1,11 @@ - netcoreapp3.0 + net60 - + 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..1de4046 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 + net60 diff --git a/src/OutGridView.Gui/OutGridView.Gui.csproj b/src/OutGridView.Gui/OutGridView.Gui.csproj index e8e8818..e195417 100644 --- a/src/OutGridView.Gui/OutGridView.Gui.csproj +++ b/src/OutGridView.Gui/OutGridView.Gui.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.0 + net60 From 8daadd32bb17d37dc1e7d2c6e1427037a3159ae0 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Fri, 3 Jun 2022 23:20:22 +1200 Subject: [PATCH 8/9] supported .net and reverted change --- global.json | 2 +- src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/global.json b/global.json index e96609f..3cf3f81 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "6.0.300" + "version": "6.0.203" } } diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs index 9b1a5a9..35e5ab9 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs @@ -63,8 +63,6 @@ public DataTableRow CastObjectToDataTableRow(PSObject ps, List } else { - // Strip ANSI - stringValue = new Regex(@"\x1B\[[^@-~]*[@-~]").Replace(stringValue, ""); valuePairs[dataColumn.ToString()] = new StringValue { DisplayValue = stringValue }; } } From c50d5042f70e94b8863ab0547896fb03066464ae Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Fri, 3 Jun 2022 23:23:54 +1200 Subject: [PATCH 9/9] Fixes #131 - Out-ConsoleGridView doesn't handle ANSI escape sequences correctly --- src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs index 35e5ab9..c8fa4fb 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs @@ -63,6 +63,8 @@ public DataTableRow CastObjectToDataTableRow(PSObject ps, List } else { + // Strip ANSI since PS 7.1 started adding it + stringValue = new Regex(@"\x1B\[[^@-~]*[@-~]").Replace(stringValue, ""); valuePairs[dataColumn.ToString()] = new StringValue { DisplayValue = stringValue }; } }