Skip to content

Format-Table -Wrap produces strange output for a mix of long lines and lines containing tabs #6313

Description

@Arnavion

Steps to reproduce

Windows 7, with pwsh.exe's window size set to 200x75. The width is the relevant thing. Choice of font does not seem to matter.

Edit: Also repros on openSUSE Tumbleweed in a similarly sized ssh window or konsole window.

@((
	New-Object psobject | Add-Member -Passthru Foo "a`tb"
), (
	New-Object psobject | Add-Member -Passthru Foo ("c`t" + 'd' * 200)
), (
	New-Object psobject | Add-Member -Passthru Foo "e`tf"
)) | Format-Table -Wrap

Expected behavior

image

(from PS 5)

Actual behavior

image

  • There is an extra line after the first and last element (in fact there is an extra line after every row except the one with the wrapping value)

  • The row that has the long value is wrapped strangely.

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.1
PSEdition                      Core
GitCommitId                    v6.0.1
OS                             Microsoft Windows 6.1.7601 S
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

and

Name                           Value
----                           -----
PSVersion                      6.0.1
PSEdition                      Core
GitCommitId                    v6.0.1
OS                             Linux 4.15.6-1-default #1 SMP PREEMPT Sun Feb 25 18:51:57 UTC 2018 (06f0b06)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Removing the tab character from the first object's property (or even replacing it with 8 spaces) fixes the extra line between the rows but does not fix the strange wrapping of the long row.

Shortening the long row so that it does not need to wrap also fixes the extra line between the rows.

Activity

  1. Arnavion commented on Mar 5, 2018

    @Arnavion
    Author

    Anotehr bit of strange behavior for

    @((
    	New-Object psobject | Add-Member -Passthru Foo "a`tb"
    ), (
    	New-Object psobject | Add-Member -Passthru Foo ("c`t" + 'd' * 100 + ' ' + 'd' * 100)
    ), (
    	New-Object psobject | Add-Member -Passthru Foo "e`tf"
    )) | ft -Wrap

    PS 5.0:

    image

    PS Core:

    image

    There is now also an empty line between the two parts of the wrapping second row. This line does not go away if I replace the tab in the first row with spaces, but does go away if I replace the tab in the second row with spaces.

  2. iSazonov commented on Mar 6, 2018

    @iSazonov
    Collaborator

    Arnav Singh (@Arnavion) Thanks for you report. Could you please repo with later daily build?

  3. Arnavion commented on Mar 6, 2018

    @Arnavion
    Author

    With current master (GitCommitId: v6.0.1-230-g20b0e9cc61af122f95225568f54e290793fa78c8) on Windows 7, it doesn't have the empty lines for both test cases, but does still have the strange wrapping for the first test case.

    image

  4. iSazonov commented on Mar 6, 2018

    @iSazonov
    Collaborator

    Arnav Singh (@Arnavion) Thanks for the repo.

    /cc Steve Lee (@SteveL-MSFT) Could you please comment the Issue?

  5. SteveL-MSFT commented on Mar 6, 2018

    @SteveL-MSFT
    Member

    Looks like a bug in the wrapping logic. I'll look into this.

  6. SteveL-MSFT commented on Mar 9, 2018

    @SteveL-MSFT
    Member

    The way -Wrap works is that it tries not to split a word. So in the second case above (w/ latest master), the wrap inserts a newline after the first 'd' * 100 since it fits, but puts the second one on a new line rather than split it. In the first case, the tab character's display size isn't taken into account, so it treats it as size 1. 'd' * 200 is wider than the width of the console, so it has to split it in half, but due to the wrong total length calculation of the tab, it inserts the newline in the wrong place.

    Not sure how to fix this for all cases. On macOS, the default tab stop is 8, so a`tb would show "a<seven spaces>b". However you can use tabs -4 to change the tab stop to 4 or even set different sizes for tab stop 1, 2, ... so we can't make assumptions about the tab stops.

    I suppose one option is when using format-table -wrap, we convert the tabs to four spaces.

  7. iSazonov commented on Mar 12, 2018

    @iSazonov
    Collaborator

    I guess there is many kinds of terminals with exclusive settings - easiest way for PowerShell is to ignore a terminal (tab) settings and use its own settings. (We could have PSTabExpansion.) Although this may not work well when the window size is changed.

    /cc Michael Klement (@mklement0)

  8. SteveL-MSFT commented on Mar 12, 2018

    @SteveL-MSFT
    Member

    There are already some places in the PowerShell code base that replaces tabs with four spaces, although it's not consistent everywhere.

  9. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  10. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  11. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  12. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions