Patch Groovy to Allow Overriding of Font Size + Height/width of Console

| Comments

I’ve just opened JIRA issue with a patch to enhance the groovy and grails consoles so that the default font size and the dimensions of the input and output areas can be overridden.

The initial patch I submitted used a custom GroovyConfig file, but at the suggestion of Guillame, I’ve modified the patch to use the preferences API. In my initial poke through the code, I didn’t see the preferences API being used (and couldn’t remember any settings that were saved by the console). After a closer look, it was being used in a couple of places.

The updated patch has been accepted and scheduled for inclusion in Groovy 1.6.1.

If you’re interested in making sure this change gets in, please vote for the JIRA.

I know that I open a groovy or grails console probably 10 times on an average day of programming, and the first thing that I do every time is to hit cmd-shift-L 3 times to bump the font size up to 18 points (yes, my eyes aren’t that great and I’m running my monitor at 1920x1200). The next thing that I do is drag it from the postage stamp size that it defaults to to cover at least half my screen.

This patch will probably save me more frustration than time, but I’m hoping it’ll save a lot of both for others out there.

This change won’t get in till 1.6.1, so if you want to tweak your current groovy install, it’s actually pretty easy to do.

How to apply the patch to an older version of Groovy

Just download the groovy source archive that matches the binary distribution that you’re using and unzip/untar it.

The file that you want to modify is located at src/main/groovy/ui/view/BasicContentPane.groovy. The easiest way to do it is to just download the patch file and apply it (from the root of the unzipped archive directory):

patch -p0 < console_font_size_config.patch

If it can’t apply cleanly, it should abort and you can make the changes manually (it adds/modifies about 20 lines of code to 3 different files in the groovy.ui package). Alternatively, you can just set the hard coded size in those files to your preferred sizes.

Then you’ll want to recompile groovy, this should be as simple as executing

ant install

This will take a few minutes to recompile and run all of the tests, when it’s done, you can then copy the newly compiled jar file from target/dist into your $GROOVY_HOME/lib and $GRAILS_HOME/lib directories.

Potential Issues

One problem that I ran into when first doing this on OSX Leopard is that I did have Ant 1.7 installed by default, but it doesn’t have the required and jar files that have the antlr tasks needed to build groovy.

The easiest way to fix this is to just install the latest version of ant (currently 1.7.1). Just download ant and unzip it somewhere. Then make sure that the bin directory is in your path ahead of any other ant installs.

Another issue I hit is that the current stable release of Groovy, 1.6-RC2, has a bug in a test case that is checking the length of a ~2 month period and using the current time. It started failing on Jan 8th and will continue to fail till March 1st because of an arithmetic error caused by the shortness of February.

The easiest thing to do to get around this is to simply comment out the testDurationArithmetic test in src/test/groovy/time/DurationTest.groovy.

Comments