-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Related: #7744
Virtual Terminal escape sequences allow, among other things, formatting of console (terminal) output, notably to produce colored output.
An escape sequence that changes the output color - e.g., "`e[32m" to switch to green - stays in effect until the color is reset - e.g., with "`e[m"
Example:
"before `e[32mgreen`e[m after" # prints only the word "green" in green.Therefore, if PowerShell truncates strings for output formatting, a string may get cut off so that the reset sequence is not output, which means that the color unexpectedly stays in effect.
#7744 shows the problem in the context of using an OSC escape sequence to construct a hyperlink (which only some terminals support; others render just the link label).
This is a nontrivial problem to solve, because PowerShell would have to be aware of all potential escape sequences and know how to reset their effects so that the appropriate escape sequence can be appended to the truncated string.
Steps to reproduce
[pscustomobject] @{ test1="before `e[32mgreen`e[m after"; test2='next col' } | Format-Table @{ e='test1'; width=17 }, test2Expected behavior
test1 test2
----- -----
before gr... next col
gr... should render green, but next col should render with the default color.
Actual behavior
test1 test2
----- -----
before gr... next col
That is, next col too is printed in green, and green output stays in effect (the prompt rendered after the command will be green too).
Additionally, note that the column alignment is off.
Environment data
PowerShell Core v6.1.0-rc.1 on macOS 10.13.6
PowerShell Core v6.1.0-rc.1 on Ubuntu 16.04.4 LTS
PowerShell Core v6.1.0-rc.1 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.165)