Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 382
Sergio Jr Avatar asked Nov 25 '25 11:11

Sergio Jr


2 Answers

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.

like image 143
Gabe Wasabi Avatar answered Nov 28 '25 04:11

Gabe Wasabi


You need to disable shell integrations in vscode. If you want to enable shell integrations, you can do from your oh-my-posh config using "shell_integration": true.

like image 41
Jan De Dobbeleer Avatar answered Nov 28 '25 04:11

Jan De Dobbeleer