Hi, I have been experiencing some problems using on Windows regarding iex output coloring.
Since I’ve been using CMDER as my main console for some time, I only noticed this problem today trying to use iex through Visual Studio Code’s integrated terminal.
After searching a lot about this, I was unable to find the right cause or solutions to this problem, so I don’t know if this is a problem on the REPL by itself or at the OS level, so I was hoping someone could help me with that.
This is what I’m getting using this config on my
Application.put_env(:elixir, :ansi_enabled, true)
eval_result: [:cyan, :bright],
eval_info: [:blue, :bright],
eval_error: [:magenta, :bright],
doc_title: [:reverse, :yellow, :bright],
doc_headings: [:yellow, :bright],
doc_inline_code: [:magenta, :bright],
ls_directory: [:green, :bright],
stack_app: [:green, :bright],
stack_info: [:red, :bright]
Powershell, CMD and CMDER (Powershell)
Windows command line and Powershell simply are not capable of ANSI. They do understand another set of commands though, which is not implemented in elixir so far.
I found this PS function that can translate ANSI color escapes: https://pastebin.com/0i24B4ha.
Maybe some Powershell expert in the forum could help integrate this into iex as a workaround.
@Nobbz Actually windows commandline and powershell are capable of ANSI just fine (and I’ve used many times), however they are just ‘shells’, not the terminals, it is up to the terminal to display the colors. The standard terminal built in to Windows is, well, a huge piece of ****, Cmder on the other hand is far more capable. On Win10 at work I use ConEmu and both the Windows Command Prompt and Powershell display all colors just fine.
I.E. it’s not the shell’s fault, it’s the terminal you are using, use a better one.
I’ve searched a little bit more about this and found that Windows 10 had ANSI support. Now it’s disabled by default (because of inconsistent behavior).
So, the solution now is for vendors to enable it (like people made for Symphony).
Some explanations and references in this SO answer.
@josevalim Could you check if this something that is worth search into for iex?
If you know of a way of checking it programatically, we could do that. That’s what we do in the other operating systems:
I found a way to enable this flag using Powershell (in theory). Although it doesn’t seem to work for iex, can someone else try this too? The expected behavior should be that the output is colored after running:
(curl http://wttr.in/ -UserAgent "curl" ).Content. (Remember to check before cuz I forgot )
It doesn’t work in
iex because it is per-process, not per-terminal, so
iex itself (I.E. the BEAM) would have to make those calls. Someone could probably make a NIF do it though.
That makes sense @OvermindDL1.
I’d love to make any significant contribution but my knowledge of Windows specifics is too shallow .
Well getting a NIF built and then just googl’ing for the command needed to call into the winapi might be useful for those people, just prebuild it for them since they often don’t have a full C building environment set up and then it should ‘just work’ (might need to auto-select 32-bit or 64-bit depending?).