powershellvisual-studio-codeoh-my-posh

Unexpected ANSI escape codes on VS Code integrated terminal


My visual studio code integrated terminal is showing some escaped ANSI codes on every command line:

\x1b7\x1b[38\x3b2\x3b122\x3b122\x3b122m ❮ \x1b[0m\x1b[38\x3b2\x3b159\x3b211\x3b86m

enter image description here

Those are the current settings related to the terminal:

"terminal.integrated.fontSize": 12,
"terminal.integrated.cursorStyle": "line",
"terminal.integrated.defaultProfile.windows": "PowerShell",
"terminal.integrated.enableImages": true,
"terminal.integrated.persistentSessionReviveProcess": "never"

I also have Oh My Posh 19.24.2 configured through PowerShell user profile:

oh-my-posh init pwsh --config "C:\Users\sergi\AppData\Local\Programs\oh-my-posh\themes\slimfat.omp.json" | Invoke-Expression

How to fix?


Solution

  • As BDENsys said in their answer, using oh-my-posh init pwsh | Invoke-Expression works. But it is a temporary solution. The ANSI escape overflows still occur in a new instance of VSCode

    Adding oh-my-posh init pwsh | Invoke-Expression on $PROFILE wasn't working for me. I resolved it by going to my VS Code settings terminal.integrated.profiles.windows and updating PowerShell settings like this.

    "PowerShell": {
                "source": "PowerShell",
                "icon": "terminal-powershell",
                "args": [
                    "-NoExit",
                    "-Command",
                    "oh-my-posh init pwsh | Invoke-Expression"
                ]
            }
    

    Apparently the "args" allows you to run a command whenever Pwsh instance is created.