Search code examples
powershellvisual-studio-codeoh-my-posh

VS Code 1.90 PowerShell is escaping ANSI escape codes like "\x1b[0m"


VS Code terminal

I'm talking about these characters: \x1b[0m \x1b7\x1b[1000C\x1b[32D\x1b[38\x3b2\x3b0\x3b119\x3b194m\x1b[0m\x1b[48\x3b2\x3b0\x3b119\x3b194m\x1b[38\x3b2\x3b255\x3b255\x3b255m  pwsh \x1b[0m\x1b[38\x3b2\x3b0\x3b119\x3b194\x3b49m\x1b[7m\x1b[0m\x1b[38\x3b2\x3b76\x3b175\x3b80m\x1b[0m\x1b[48\x3b2\x3b76\x3b175\x3b80m\x1b[38\x3b2\x3b255\x3b255\x3b255m  100 \x1b[0m\x1b[38\x3b2\x3b76\x3b175\x3b80\x3b49m\x1b[7m\x1b[0m\x1b[38\x3b2\x3b46\x3b149\x3b153m\x1b[0m\x1b[48\x3b2\x3b46\x3b149\x3b153m\x1b[38\x3b2\x3b17\x3b17\x3b17m 08:55:45 \x1b[0m\x1b[38\x3b2\x3b46\x3b149\x3b153m\x1b[0m\x1b8

I've tried this accepted solution. Set VS Code "terminal.integrated.shellIntegration.enabled": false and enabled "shell_integration": true in oh-my-posh configuration file. That didn't work for me.


Solution

  • This is probably a case of the bug described in issue ticket Terminal in VSCode Insiders not able to display special characters #211922.

    The fix has been made in Encode all chars 0x00-0x1f #215452 and is in the 1.90.2 release.

    Some people say they were able to work around the issue by replacing the PowerShell shell integration script for 1.90 with an older version like this one. The path to the file to replace is in ~\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\contrib\terminal\browser\media\shellIntegration.ps1.

    Another user said that as a workaround, they could start a subshell (run pwsh.exe / powershell.exe) and the subshell wouldn't have this issue.