Add -RepeatHeader to Format-Table to enable repeating header for each screen full (#8481)

When using a screen reader or just getting the output of a table with lots of rows, the header is no longer on the screen and the columns may no longer make sense without the context.  This change adds a `-RepeatHeader` switch to `Format-Table` to enable re-outputting the header after every screen full (minus 1 row).  Expectation is that the user is piping the output to a pager (e.g. less) which uses the bottom row for pager information.  I followed the `AutoSize` parameter as the way to get the parameter from the cmdlet into the deep formatting object where it's needed.
This commit is contained in:
Steve Lee
2018-12-20 11:05:34 -08:00
committed by Dongbo Wang
parent 64bbdbe61c
commit 110f78b818
11 changed files with 163 additions and 47 deletions
@@ -791,4 +791,12 @@ A Name B
[system.management.automation.internal.internaltesthooks]::SetTestHook('SetConsoleWidthToZero', $false)
}
}
It "-RepeatHeader should output the header at every screen full" -Skip:([Console]::WindowHeight -eq 0) {
$numHeaders = 4
$numObjects = [Console]::WindowHeight * $numHeaders
$out = 1..$numObjects | ForEach-Object { @{foo=$_} } | Format-Table -RepeatHeader | Out-String
$lines = $out.Split([System.Environment]::NewLine)
($lines | Select-String "Name\s*Value").Count | Should -Be ($numHeaders + 1)
}
}