mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user