I just started to learning Elixir. I’m a very visual guy, so I like my terminal colors very much. I noticed on YouTube, that the mix command does actually produce colored output, which led me down a rabbit hole.
Somewhere in the middle of it, I found the following code part in
C:\Program Files (x86)\Elixir\bin\elixir.bat
reg query HKCU\Console /v VirtualTerminalLevel 2>nul | findstr /e "0x1" >nul 2>nul if %errorlevel% == 0 ( set beforeExtra=-elixir ansi_enabled true !beforeExtra! )
Windows Terminal does support ANSI/VT100 escape sequences, regardless of whether this key exists or not. I don’t know when support was added, but I believe it was in 2021, if not 2022. Changing the above code part to
set beforeExtra=-elixir ansi_enabled true !beforeExtra!
successfully enabled colors on commands like
mix phx.new hello when in a Windows Terminal session.
Unfortunately, I don’t know how to reliably check if the current console host is Windows Terminal. But I can observe that Windows Terminal adds two environment variables
WT_SESSION. Maybe this could be leveraged to improve
elixir.bat to not rely solely on the existence of a registry key that the majority of people don’t know or care about (no offense).
What do you think?