From f04940b76c648c60371b161626e18225d08ecdf6 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 30 Dec 2022 23:00:00 -0800 Subject: [PATCH] Fix `Format-Table -RepeatHeader` for property derived tables (#18870) --- .../FormatAndOutput/common/FormatViewGenerator_Table.cs | 1 + .../Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/System.Management.Automation/FormatAndOutput/common/FormatViewGenerator_Table.cs b/src/System.Management.Automation/FormatAndOutput/common/FormatViewGenerator_Table.cs index 7c661a5169..c6fc9887c9 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/FormatViewGenerator_Table.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/FormatViewGenerator_Table.cs @@ -223,6 +223,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format TableHeaderInfo thi = new TableHeaderInfo(); thi.hideHeader = this.HideHeaders; + thi.repeatHeader = this.RepeatHeader; for (int k = 0; k < this.activeAssociationList.Count; k++) { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 index 6eb1e4fa3c..f5bbae4b0b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 @@ -813,6 +813,14 @@ A Name B ($lines | Select-String "Name\s*Value").Count | Should -Be ($numHeaders + 1) } + It "-RepeatHeader should output the header at every screen full for custom table" -Skip:([Console]::WindowHeight -eq 0) { + $numHeaders = 4 + $numObjects = [Console]::WindowHeight * $numHeaders + $out = 1..$numObjects | ForEach-Object { [pscustomobject]@{foo=$_;bar=$_;hello=$_;world=$_} } | Format-Table -Property hello, world -RepeatHeader | Out-String + $lines = $out.Split([System.Environment]::NewLine) + ($lines | Select-String "Hello\s*World").Count | Should -Be ($numHeaders + 1) + } + It "Should be formatted correctly if width is declared and using center alignment" { $expectedTable = @"