Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with Ant's AnsiColorLogger in Snow Leopard

I have Ant configured to use the AnsiColorLogger. In Mac OS 10.5, everything was fine. Since upgrading to Snow Leopard, the AnsiColorLoggger no longer works. I see the Ant output (uncolorized) for a second then it just disappears. Has anyone else gotten this working in Snow Leopard? Other ANSI colors are working fine in Terminal.app (colored ls output, colors in my prompt).

Also, would this be a better question on SuperUser?

like image 366
Nate Avatar asked Jan 22 '23 22:01

Nate


2 Answers

UPDATE: I have sorted out the issue. It has to do with ANT giving escape sequences that while appropriate for a linux xterm, are NOT correctly interpreted by Mac OS X. It is possible to filter the ANT output to convert these sequences and restore colorized output.

The moral of the story is that this wrapper script will achieve colorized output:

# cat /workspace/SDK/bin/ant-wrapper.sh
/usr/bin/ant -logger org.apache.tools.ant.listener.AnsiColorLogger "$@" | perl -pe 's/(?&lt=\e\[)2;//g'

# alias ant='/workspace/SDK/bin/ant-wrapper.sh' 

# ant publish 
(output has lots of pretty colors;  well, maybe not so pretty, more like an easter egg)

Original Post (and debugging steps):

I'm having similar issues with regard to AnsiColorLogger not displaying colors at all. I'm not sure what the author means by "[output appears] for a second then it just disappears". That seems like a strange problem to occur on the Terminal.

My Box:

# uname -a
Darwin Dave-Dopsons-MacBook-Pro.local 10.7.0 Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386 i386

This is the ANT Logger we are using: http://ant.apache.org/manual/listeners.html#AnsiColorLogger

Here's a related forum post (tried the advice given, to no avail): http://ant.1045680.n5.nabble.com/Macosx-and-AnsiColorLogger-td1355310.html

I did "ant | less", and I DO see escape sequences, but still no colors:

Buildfile: /workspace/Words/words_blackberry/build.xml
ESC[2;32m
publish:ESC[m

Still blocked on this, and would love advice if anyone has gotten it to work on OSX

GOT IT!

So here's the output of colorized ls:

# CLICOLOR_FORCE=exfxcxdxbxegedabagacad ls -lGF | less
total 112
-rw-r--r--  1 ddopson  admin  6511 May 29 12:41 build.xml
drwxr-xr-x  6 ddopson  admin   204 May 28 23:59 ESC[34meclipse-binESC[mESC[m/
lrwxr-xr-x  1 ddopson  admin    35 May 23 21:24 ESC[35mfilesESC[mESC[m@ -> ../artwork/output/blackberry/files/
lrwxr-xr-x  1 ddopson  admin    36 May 23 21:20 ESC[35mimagesESC[mESC[m@ -> ../artwork/output/blackberry/images/

Notice how the escape sequences are subtly different; they don't have the '2;' like ANT did...

So to test this theory: ant -logger org.apache.tools.ant.listener.AnsiColorLogger publish | sed 's/2;//g'

... and the output is COLORIZED! Victory!

like image 73
Dave Dopson Avatar answered Jan 25 '23 12:01

Dave Dopson


I've take ddopson's knowledge and crammed it into a single line:

ant () { command ant  -logger org.apache.tools.ant.listener.AnsiColorLogger "$@" | sed 's/2;//g' ; }

This works by using a Bash Function. Place this in your ~/.profile file and it will do the same thing as ddopson's ant-wrapper.sh, but without needing a second file to make it work. Slightly more elegant and less fragile.

like image 38
Stu Thompson Avatar answered Jan 25 '23 11:01

Stu Thompson