Skip to content

Console output truncated with an ellipsis causes remaining text to shift to the left when using $PSStyle #16700

Closed
@nmbell

Description

@nmbell

Prerequisites

Steps to reproduce

Console output truncated with an ellipsis causes remaining text to shift to the left when using $PSStyle

I have a .ps1xml format file that defines a view for file and directory objects which uses $PSStyle to highlight parts of the output, e.g.:

<?xml version="1.0" encoding="utf-8"?>
<Configuration>
    <SelectionSets>
        <SelectionSet>
            <Name>FileSystemTypes</Name>
            <Types>
                <TypeName>System.IO.DirectoryInfo</TypeName>
                <TypeName>System.IO.FileInfo</TypeName>
            </Types>
        </SelectionSet>
    </SelectionSets>
    <ViewDefinitions>
        <View>
            <Name>children</Name>
            <ViewSelectedBy>
                <SelectionSetName>FileSystemTypes</SelectionSetName>
            </ViewSelectedBy>
            <TableControl>
                <TableHeaders>
                    <TableColumnHeader> <Label>Name</Label>                <Width>30</Width>  <Alignment>Left</Alignment>  </TableColumnHeader>
                    <TableColumnHeader> <Label>LastWriteTime      </Label> <Width>19</Width>  <Alignment>Left</Alignment>  </TableColumnHeader>
                    <TableColumnHeader> <Label>Size      </Label>          <Width>10</Width>  <Alignment>Right</Alignment> </TableColumnHeader>
                    <TableColumnHeader> <Label>FullName</Label>                               <Alignment>Left</Alignment>  </TableColumnHeader>
                </TableHeaders>
                <TableRowEntries>
                    <TableRowEntry>
                        <TableColumnItems>
                            <TableColumnItem>
                                <ScriptBlock>
                                    "$($PSStyle.Reverse)$($_.Name)$($PSStyle.Reset)"
                                </ScriptBlock>
                            </TableColumnItem>
                            <TableColumnItem>
                                <ScriptBlock>
                                    $_.LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
                                </ScriptBlock>
                            </TableColumnItem>
                            <TableColumnItem>
                                <ScriptBlock>
                                    ($_.Length/1MB).ToString('0.000')+' MB'
                                </ScriptBlock>
                            </TableColumnItem>
                            <TableColumnItem>
                                <ScriptBlock>
                                    $_.FullName
                                </ScriptBlock>
                            </TableColumnItem>
                        </TableColumnItems>
                    </TableRowEntry>
                </TableRowEntries>
            </TableControl>
        </View>
    </ViewDefinitions>
</Configuration>
$filePath = 'D:\my.format.ps1xml'
Update-FormatData -PrependPath $filePath
Get-ChildItem -Path $PSHOME -File

When the Name column contains a long file name, the console truncates the name and adds an ellipsis to indicate that there are truncated characters. When this happens, the remaining characters on the line are shifted 3 spaces to the left:
image

Removing the references to $PSStyle in the .ps1xml format file gives the expected layout:
image

The shift effect is present for any value of $PSStyle.OutputRendering.

Expected behavior

Output text on lines with a truncation ellipsis should remain aligned with its column header.

Actual behavior

Output text on lines with a truncation ellipsis is shifted to the left.

Error details

n/a

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions