Grails console enhancements

  • Authors : Antony Jones
2 votes
Dependency :
compile ":console-enhancements:1.0"
Custom repositories :
mavenRepo "http://snapshots.repository.codehaus.org/"
mavenRepo "http://repository.codehaus.org/"

Documentation

Summary

Enhances the grails console output for better visibility

Installation

grails install-plugin console-enhancements

Description

Enhances the grails console output for better visibility.

Features

  • System.out.println colouring.
    • Colours printlns separately from other console output for better visibility.
  • Console test-runner output colouring and enhanced display.
    • Test case name is printed to console
    • A failing test will show up in red.
    • A passing test will show up in green.
    • A failing test will turn all further tests red in case it scrolls off the screen.
Rationale

This plugin was born as a result of seeing too many of my colleagues typing:

println ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ${myValue}"

Usage

Usage is designed to be as simple and as unintrusive as possible. Essentially this plugin takes the bold step of overriding the 'println' method on the Object class'. What this means is that any time you type:

println "my text"

Your println will come up in the console in bold, colour, flashing, or whatever custom values you have put into the configuration (see below)

If you want to use a custom set of colours for a particular println, you can use up to three:

println ANSICode.ITALIC_ON, ANSICode.FOREGROUND_RED, ANSICode.BACKGROUND_YELLOW, "my text"

If you want any more control, see 'advanced usage below'.

Configuration

Configuration is automatic, if you like your printlns in bold aqua coloured text. If not, it's simple to override:

console {
    colours {
        normal = [ANSICode.FOREGROUND_RED, ANSICode.BOLD_ON]
    }
}

Where the list assigned to the 'normal' attribute can by any number of values from the provided ANSICode enum. The ANSI escape sequence is automatically reset after each println.

Limitations

This plugin requires that you have an ANSI capable terminal. As with most things that are great about computing, this means that this plugin will not work on windows, and will likely print a number of ugly ANSI escape sequences around your printlns!

Advanced Usage

You can format any text using ANSI by manually invoking the ANSISequence class' .format method. This is probably most useful in Grails event scripts:

new ANSISequence(ANSICode.FOREGROUND_YELLOW, ANSICode.BACKGROUND_MAGENTA).format('test message')