I started to learn elixir and I successfully made the iex have ansi colors. The problem is that in the terminal in vscode the output looks like garbage:
$ iex
Interactive Elixir (1.8.1) - press Ctrl+C to exit (type h() ENTER for help)
?[G?[36miex>?[0m?[0m
When I run git-for-windows' bash from cmder it works well, the colors are good.
When I run the same bash as an integrated terminal in vscode the ansi codes are printed instead of having colors.
I've never had any problem with nodejs, or anything else, only elixir related things fall apart.
This is the same for both, I don't know if it still matters:
$ elixir -e "IO.inspect :io.columns"
{:error, :enotsup}
Does anyone have any idea what does vscode differently that makes the same thing work in a different way?
Thise ansi escape code are not supported in all Windows consoles, in particular an embedded CMD in VSCode (as detailed in Microsoft/WSL issue 1173).
Even in a git bash session done by VSCode, that bash session would still operate on top of a CMD, and not a hybrid terminal like cmder/ConEmu, able to interpret ANSI X3.64 / xterm 256 colors through hooking Windows API.
As shown here, there is an -elixir ansi_enabled false which would allow elixir to not output color escape codes.
Try an set it in the :elixir application, like doing the opposite of this example.
Application.put_env(:elixir, :ansi_enabled, false)
The other approach would be to use a VSCode console based on ConEmu/cmder, with for instance ipatalas.vscode-conemu

In that kind of console, ANSI colors escape code should be displayed just fine.
The OP indriq confirms in the comments:
ANSICON injects a DLL into a process, hooking its functions.
One of three methods is used to inject the DLL.
LoadLibraryviaCreateRemoteThreadfor a running process.LdrLoadDllviaCreateRemoteThreadfor a 64-bit .NET AnyCPU process.- Adding the DLL directly to the import table, otherwise.
You can see it setup with VSCode here:
{
...
"terminal.integrated.shell.windows": "C:\\Program Files\\ANSICON\\x64\\ansicon.exe",
"terminal.integrated.shellArgs.windows": [
"C:\\Program Files\\Git\\bin\\sh.exe",
"--login",
"-i"
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With