使用 gitbash 和 elixir 在 vscode 中输出垃圾而不是颜色 [英] Garbage output instead of colors in vscode with gitbash and elixir
问题描述
我开始学习elixir,我成功地让iex有了ansi颜色.问题是在 vscode 的终端中,输出看起来像垃圾:
$ iexInteractive Elixir (1.8.1) - 按 Ctrl+C 退出(输入 h() ENTER 寻求帮助)?[G?[36miex>?[0m?[0m
- Windows 10 专业版
- vscode 1.36.1
- cmder (conemu 161206)
- 长生不老药 1.8.1
当我从 cmder 运行 git-for-windows 的 bash 时,它运行良好,颜色很好.
当我在 vscode 中运行与集成终端相同的 bash 时,会打印 ansi 代码而不是颜色.
我在使用 nodejs 或其他任何东西时从来没有遇到过任何问题,只有与 elixir 相关的东西会崩溃.
这两个都一样,我不知道它是否仍然重要:
$ elixir -e "IO.inspect :io.columns"{:错误,:enotsup}
有没有人知道 vscode 有什么不同使同样的事情以不同的方式工作?
Thise
在那种控制台中,ANSI 颜色转义码应该可以正常显示.
<小时>OP indriq 在评论中确认:
- 不想想要禁用颜色
- 使用 ansicon,同样是一个注入程序:
ANSICON 将一个 DLL 注入一个进程,钩住它的函数.
三种方法之一用于注入DLL.
LoadLibrary
通过CreateRemoteThread
用于正在运行的进程.LdrLoadDll
通过CreateRemoteThread
用于 64 位 .NET AnyCPU 进程.- 将 DLL 直接添加到导入表中,否则.
<代码>{..."terminal.integrated.shell.windows": "C:\\Program Files\\ANSICON\\x64\\ansicon.exe",terminal.integrated.shellArgs.windows":["C:\\Program Files\\Git\\bin\\sh.exe","- 登录",-一世"]}
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?
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:
- 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
viaCreateRemoteThread
for a running process.LdrLoadDll
viaCreateRemoteThread
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"
]
}
这篇关于使用 gitbash 和 elixir 在 vscode 中输出垃圾而不是颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!