-
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
Description
Description
When piping [pscustomobject]s and binding by property name, the Label node is missing on TableColumnHeader causing certain formatting issues like the Label ends up being the plain text of the [scriptblock].
I'd expect the Label to match name in -Property [array] if no AliasProperty. I assume the last [pscustomobject] in the [array] will determine the TableColumnHeader structure.
Workaround
Use -AliasProperty @{ Name = 'Name'; Mode = 'Mode'} on the last [pscustomobject] in the @().
Notes
I don't think Write-FormatListView shows this same behavior. Loving getting my formatting set up in my build.ps1. Thanks for the time on this!
Reproducable Steps
Install-PSResource PowershellHumanizer, Terminal-Icons
$formatList = [System.Collections.Generic.List[string]]::new()
$grpSetCtrlName = 'FileSystemTypes-GroupingFormat'
$writeFormatCustomViewSplat = @{
Name = $grpSetCtrlName
AsControl = $true
Frame = $true
LeftIndent = 4
Action = {
Write-FormatViewExpression -AssemblyName 'System.Management.Automation' -BaseName 'FileSystemProviderStrings' -ResourceID 'DirectoryDisplayGrouping'
Write-FormatViewExpression -ScriptBlock {$_.PSParentPath.Replace("Microsoft.PowerShell.Core\FileSystem::", "")}
Write-FormatViewExpression -Newline
}
}
$formatList.Add( (Write-FormatCustomView @writeFormatCustomViewSplat) )
$writeFormatDeserDirInfoNamespace = 'Deserialized.System.IO.DirectoryInfo'
$writeFormatDeserFileInfoNamespace = 'Deserialized.System.IO.FileInfo'
$writeFormatDirInfoNamespace = 'System.IO.DirectoryInfo'
$writeFormatFileInfoNamespace = 'System.IO.FileInfo'
$writeFormatSelSetName = 'FileSystemTypes'
$writeFormatDeserSelSetName = 'FileSystemTypesDeserialized'
$writeFormatViewSplat = @{
FormatXml = @"
<SelectionSet>
<Name>$writeFormatSelSetName</Name>
<Types>
<TypeName>$writeFormatDirInfoNamespace</TypeName>
<TypeName>$writeFormatFileInfoNamespace</TypeName>
<TypeName>$writeFormatDeserDirInfoNamespace</TypeName>
<TypeName>$writeFormatDeserFileInfoNamespace</TypeName>
</Types>
</SelectionSet>
"@
TypeName = 'NotApplicable'
}
$formatList.Add( (Write-FormatView @writeFormatViewSplat) )
$writeFormatViewSplat = @{
FormatXml = @"
<SelectionSet>
<Name>$writeFormatDeserSelSetName</Name>
<Types>
<TypeName>$writeFormatDeserDirInfoNamespace</TypeName>
<TypeName>$writeFormatDeserFileInfoNamespace</TypeName>
</Types>
</SelectionSet>
"@
TypeName = 'NotApplicable'
}
$formatList.Add( (Write-FormatView @writeFormatViewSplat) )
$writeFormatWidth = [Int32[]]@(7, 25, 14)
$writeFormatAlign = @{
Mode = 'Left'
LastWriteTime = 'Right'
Length = 'Right'
Name = 'Left'
}
$writeFormatLengthSb = {
if ($_.Attributes.HasFlag( [System.IO.FileAttributes]::Offline) ) {
"($([Humanizer.ByteSizeExtensions]::Humanize($_.Length, '0.00')))"
}
else {
[Humanizer.ByteSizeExtensions]::Humanize($_.Length, '0.00')
}
}
$writeFormatFileAndDirInfoProperty = 'ModeWithoutHardLink', 'LastWriteTime', 'Length', 'Name'
$writeFormatFileAndDirInfoAliasProperty = @{
ModeWithoutHardLink = 'Mode'
}
$writeFormatDeserFileAndDirInfoProperty = 'Mode', 'LastWriteTime', 'Length', 'Name'
$writeFormatTable = @(
[PSCustomObject]@{
Property = $writeFormatFileAndDirInfoProperty
AlignProperty = $writeFormatAlign
Width = $writeFormatWidth
Wrap = $true
VirtualProperty = @{
LastWriteTime = { [Humanizer.DateHumanizeExtensions]::Humanize($_.LastWriteTime, $false) }
Length = $writeFormatLengthSb
Name = { Terminal-Icons\Format-TerminalIcons $_ }
}
AliasProperty = $writeFormatFileAndDirInfoAliasProperty
},
[PSCustomObject]@{
ViewTypeName = $writeFormatDeserDirInfoNamespace
Property = $writeFormatDeserFileAndDirInfoProperty
AlignProperty = $writeFormatAlign
Width = $writeFormatWidth
Wrap = $true
VirtualProperty = @{
LastWriteTime = { [Humanizer.DateHumanizeExtensions]::Humanize($_.LastWriteTime, $false) }
Length = { [string]::Empty }
}
},
[PSCustomObject]@{
ViewTypeName = $writeFormatDirInfoNamespace
Property = $writeFormatFileAndDirInfoProperty
AlignProperty = $writeFormatAlign
Width = $writeFormatWidth
Wrap = $true
VirtualProperty = @{
LastWriteTime = { [Humanizer.DateHumanizeExtensions]::Humanize($_.LastWriteTime, $false) }
Length = { [string]::Empty }
Name = { Terminal-Icons\Format-TerminalIcons $_ }
}
AliasProperty = $writeFormatFileAndDirInfoAliasProperty
},
[PSCustomObject]@{
ViewTypeName = $writeFormatDeserFileInfoNamespace
Property = $writeFormatDeserFileAndDirInfoProperty
AlignProperty = $writeFormatAlign
Width = $writeFormatWidth
Wrap = $true
VirtualProperty = @{
LastWriteTime = { [Humanizer.DateHumanizeExtensions]::Humanize($_.LastWriteTime, $false) }
Length = { [Humanizer.ByteSizeExtensions]::Humanize($_.Length, '0.00') }
}
}
)
$writeFormatViewSplat = @{
FormatXml = ( $writeFormatTable | Write-FormatTableView )
IsSelectionSet = $true
Name = 'children'
TypeName = $writeFormatSelSetName
GroupByProperty = 'PSParentPath'
GroupAction = $grpSetCtrlName
}
$formatList.Add( ( Write-FormatView @writeFormatViewSplat ) )
$file = "$env:USERPROFILE\mattcargile_235.format.ps1xml"
$formatList | Out-FormatData | Set-Content $file -Confirm
Import-Module PowerShellHumanizer, Terminal-Icons
Update-FormatData -PrependPath $file
Get-ChildItem # Look at the header where Name would be. You will see the [scriptblock]
Remove-Item $file -Confirm
Links
N/A
Reactions are currently unavailable
