How to use jcurses from groovy

1.1k views Asked by At

I just tried to use JCurses from within Groovy, but I always get the following exception:

Caused by: java.lang.NullPointerException at    
    jcurses.system.Toolkit.getLibraryPath(Toolkit.java:97) at 
    jcurses.system.Toolkit.<clinit>(Toolkit.java:37)

Toolkit.java:37 :

    String url = ClassLoader.getSystemClassLoader()\
            .getResource("jcurses/system/Toolkit.class").toString();

Google told me that it could have to do with spaces within the classpath (windows), but moving the library and even using the classes instead of the .jar file was not successful.

It seems to be possible - pleac for groovy references JCurses: http://pleac.sourceforge.net/pleac_groovy/userinterfaces.html

Another way to clear the screen from within a Groovy shell script would also solve my problem. :-)

3

There are 3 answers

5
tim_yates On BEST ANSWER

As jline is bundled with Groovy, can't you use the class jline.ANSIBuffer.ANSICodes (as is shows in the page you linked to)

print jline.ANSIBuffer.ANSICodes.clrscr()

You might also need to do:

print jline.ANSIBuffer.ANSICodes.gotoxy( 1, 1 )

If you want the cursor to go back to the top of the screen

To draw coloured text, you can do:

println new jline.ANSIBuffer().append( 'Some ' )
                              .red( 'Red' )
                              .append( ' text' )
                              .toString()
1
rdmueller On

found another trivial way to clear the screen :-)

print "\n"*80
0
Brad Mace On

The root problem is most likely that jcurses.jar was not being found on your classpath, causing ClassLoader.getSystemClassLoader().getResource("jcurses/system/Toolkit.class") to return null.

There's a related problem you can run into if it can't find the C library containing the native code (libjcurses.so or libjcurses64.so on linux). It expects the C libary to be in the same folder where it found jcurses.jar. If it's not there, you'll get:

java.lang.RuntimeException: couldn't find jcurses library