-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
"`e[m " is a valid ANSI escape sequence that resets current formatting, short for "`e[0m "
The StringDecorated currently doesn't recognize it, and retains it as part of the data when plain-text conversion is requested.
# If you output the string directly to the terminal, you'll see that the trailing "." is NOT green anymore,
# proving that "`e[m"` was effective in resetting the color.
([System.Management.Automation.Internal.StringDecorated]::new("`e[32mgreen`e[m.")).ToString('PlainText') | Format-HexNote:
-
Because terminals recognize
"`e[m "correctly, the problem is usually hidden when the class is used behind the scenes in conjunction with$PSStyle.OutputRendering = 'PlainText', e.g. with
$PSStyle.OutputRendering = 'PlainText'; wsl -e printf '\e[32mgreen\e[m.' | Out-Host. -
However, due to the - inappropriately closed - Streamed executable output prints Ansi Escaping in Write-* Commandlets #18771 - it currently does surface in
conhost.exewindows on Windows.
Expected behavior
Label: String (System.String) <7E780A95>
Offset Bytes Ascii
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
------ ----------------------------------------------- -----
0000000000000000 67 72 65 65 6E 2E green.Actual behavior
Label: String (System.String) <56784E4B>
Offset Bytes Ascii
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
------ ----------------------------------------------- -----
0000000000000000 67 72 65 65 6E 1B 5B 6D 2E green�[m.Note the extraneous �[m part in the Ascii column, showing that `e[m was unexpectedly retained.
Error details
No response
Environment data
PowerShell Core 7.4.0-preview.1Visuals
No response