danielixir
Better check for ANSI-enabled terminal on Windows
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_PROFILE_ID and 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?
Most Liked
garazdawi
Erlang/OTP 26 (to be released in May 2023) has a completely rewritten shell implementation that solves the problem for windows. So if you wait a while the problem will go away on its own.
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










