Skip to content

Table width not calculated correct when using VT100 #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thordreier opened this issue Jan 4, 2019 · 4 comments · Fixed by #1571
Closed

Table width not calculated correct when using VT100 #840

thordreier opened this issue Jan 4, 2019 · 4 comments · Fixed by #1571

Comments

@thordreier
Copy link

Table width not calculated correct when using VT100.

https://docs.microsoft.com/en-us/powershell/wmf/5.1/console-improvements states "PowerShell will ignore certain VT100 formatting escape sequences when calculating table widths". This is true in "plain" PowerShell, but not in VSCode.

This example demonstrates the problem:

# Create object with VT100 escape sequences
$x = [PSCustomObject]@{
    A = 'NoColor'
    B = "$([char](27))[33;1mColor$([char](27))[0m"
    C = 'NoColor'
}

# Auto size the columns
$x

# Set column width to 10
$x | Format-Table -Property @{L='A';E={$_.A};W=10},@{L='B';E={$_.B};W=10},@{L='C';E={$_.C};W=10}

# Column width is only 4 - this does not work anywhere!
$x | Format-Table -Property @{L='A';E={$_.A};W=4},@{L='B';E={$_.B};W=4},@{L='C';E={$_.C};W=4}

This example...:

  • Does not work in VSCode - the VT100 sequence characters is included in the character count for table width
  • Works in "plain" PowerShell on Windows 10 (not the four wide example)
  • Does not work in ISE (but $host.UI.SupportsVirtualTerminal is $false - so VT100 doesn't work at all here)
@SydneyhSmith SydneyhSmith added Issue-Enhancement A feature request (enhancement). Area-General labels Jan 7, 2019
@SydneyhSmith
Copy link
Collaborator

@thordreier thanks for pointing this out, I am able to easily reproduce this result. I am calling this an enhancement because it is not available in the ISE, but it does seem like a reasonable ask.

@SydneyhSmith SydneyhSmith added Issue-Bug A bug to squash. and removed Issue-Enhancement A feature request (enhancement). labels Jan 8, 2019
@rjmholt
Copy link
Contributor

rjmholt commented Jan 9, 2019

See also: PowerShell/PowerShell#7744

@rjmholt
Copy link
Contributor

rjmholt commented Jan 9, 2019

@rkeithhill also had some good discussion in that issue

@SeeminglyScience
Copy link
Collaborator

This works in ConsoleHost because of a custom PSHostRawUserInterface.LengthInBufferCells implementation. The default call just returns string.Length, but it should call internalRawUI.LengthInBufferCells.

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

Successfully merging a pull request may close this issue.

5 participants