PowerShell / PowerShell Public
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
Fix formatting truncation to handle strings with VT sequences #17251
Conversation
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? |
| /// <summary> | ||
| /// The default buffer cell calculation already works for the PowerShell console host and Visual studio code host. | ||
| /// </summary> | ||
| private static readonly HashSet<string> s_psHost = new(StringComparer.Ordinal) { "ConsoleHost", "Visual Studio Code Host" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SeeminglyScience Now that the default buffer cell calculation takes into account escape sequences and CJK characters, I think we can make ConsoleHost and VSCode host to use the default DisplayCells instead of calling into the host specific LengthInBufferCells method. Let me know if you have any concerns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SeeminglyScience Now that the default buffer cell calculation takes into account escape sequences and CJK characters, I think we can make
ConsoleHostand VSCode host to use the defaultDisplayCellsinstead of calling into the host specificLengthInBufferCellsmethod. Let me know if you have any concerns.
I agree! VSCode just redirects to ConsoleHost*'s implementation so shouldn't need any changes there.
Also does this mean that piping to line output writers that aren't host aware should work now too? Out-String and less.exe would calculate the wrong value width because they never call LengthInBufferCells)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.



PR Summary
Fix #16700
Fix formatting truncation to handle strings with VT sequences.
The main changes are in buffer cell length calculation, as well as adding
VtSubstringimplementations, which are used to get part of a string that may contain escape sequences.With the changes in this PR, the formatting works fine with the demo scripts from #16700 (comment) and #16700 (comment):
Using the repro provided in #16700 (comment), now the formatting truncation and alignment work as expected:
Out-Stringworks as well:PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.