如何在 MSYS/Git Bash 中查看颜色 Ant 输出? [英] How to see color Ant output in MSYS/Git Bash?
问题描述
我想使用 AnsiColorLogger 从 蚂蚁.我在 Windows 上使用 Git Bash.
I'd like to use AnsiColorLogger to get color ouput from Ant. I'm using Git Bash on Windows.
我试过了:
$ ant -logger org.apache.tools.ant.listener.AnsiColorLogger
但我的输出看起来像:
Buildfile: c:\foo\build.xml
←[2;36m [junit] Testsuite: org.foo.BarTest←[m
←[2;36m [junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.188 sec←[m
←[2;36m [junit] ←[m
←[2;36m [junit] Testcase: testInherits took 0.175 sec←[m
←[2;36m [junit] FAILED←[m
←[2;36m [junit] subdir not child←[m
←[2;36m [junit] junit.framework.AssertionFailedError: subdir not child←[m
←[2;36m [junit] at org.foo.BarTest.testInherits(BarTest.java:61)←[m
←[2;36m [junit] ←[m
←[2;31m [junit] Test org.foo.BarTest FAILED←[m
我知道 ANSI 颜色在 Git Bash 中至少部分起作用,因为像 ls -ACF --color=auto
这样的命令会产生漂亮的彩色输出.
I know ANSI colors work, at least partially, in Git Bash because commands like ls -ACF --color=auto
produce nicely colored output.
Ant 的诀窍是什么?
What's the trick for Ant?
推荐答案
经过大量的谷歌搜索和实验,我将几个变体组合成一个解决方案,该解决方案适用于 Git Bash、Ant 和 Windows 的特定组合.
After much Googling and experimentation, I combined several variations into a solution that works well for the particular combination of Git Bash, Ant and Windows.
在您的 .bashrc
文件中添加以下几行后重新启动 Git Bash:
Relaunch Git Bash after adding the following lines to your .bashrc
file:
alias ant='cant'
function cant {
"ant" -logger org.apache.tools.ant.listener.AnsiColorLogger "$@" \
2>&1 | perl -pe 's/(?<=\e\[)2;//g'
}
Git Bash Noob 提示: .bashrc
文件(如果存在)位于您的主目录中.创建/编辑它的方法如下:
Git Bash Noob Tip: .bashrc
file, if it exists, lives in your home directory. Here's how to create/edit it:
$ cd
$ notepad .bashrc &
这篇关于如何在 MSYS/Git Bash 中查看颜色 Ant 输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!