Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Garbage output instead of colors in vscode with gitbash and elixir

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
  • windows 10 pro
  • vscode 1.36.1
  • cmder (conemu 161206)
  • elixir 1.8.1

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?

like image 309
indriq Avatar asked Nov 18 '25 23:11

indriq


1 Answers

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

https://raw.githubusercontent.com/ipatalas/vscode-conemu/master/images/titlebar.png

In that kind of console, ANSI colors escape code should be displayed just fine.


The OP indriq confirms in the comments:

  • not wanting to disable colors
  • using ansicon, again an injection program:

ANSICON injects a DLL into a process, hooking its functions.
One of three methods is used to inject the DLL.

  • LoadLibrary via CreateRemoteThread for a running process.
  • LdrLoadDll via CreateRemoteThread for 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"
    ]
}
like image 83
VonC Avatar answered Nov 20 '25 13:11

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!