1

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. :-)

Brad Mace
  • 27,194
  • 17
  • 102
  • 148
rdmueller
  • 10,742
  • 10
  • 69
  • 126

3 Answers3

2

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

Brad Mace
  • 27,194
  • 17
  • 102
  • 148
2

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()
tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • hm. both `powershell` and `cmd.exe` seem not to support ANSI codes. But somehow it seems to be possible to clear the screen from your program - grails does it in interactive mode... – rdmueller Mar 28 '12 at 09:09
  • ok. got me. but grails does a lot of other "magic" like changing the font color and replacing the current line... – rdmueller Mar 28 '12 at 09:19
  • Ahhh... it's a [known bug of jLine](http://jline.sourceforge.net/#known_bugs) that _"Clearing the screen (CTRL-L) doesn't currently work on Windows."_ And if you want different coloured text, you can see my updated answer... – tim_yates Mar 28 '12 at 09:46
  • Unfortunately, it seems to be not only the "Clearing the screen" which does not work on windows. Your color example just produces `Some ←[31mRed←[0m text`. All control characters are ignored with only a few exceptions (`[\n\t\r\b]`) seem to be ignored. – rdmueller Mar 28 '12 at 10:00
  • It must not be ansi enabled then. Not done this on Windows for years, but it's a PITA... There [are](http://stackoverflow.com/questions/6532295/ansi-escape-sequences-not-working-in-windows-cmd-prompt) [some](http://stackoverflow.com/questions/7086034/colorizing-windows-command-line-output-from-php) questions here on SO about getting it working – tim_yates Mar 28 '12 at 10:10
1

found another trivial way to clear the screen :-)

print "\n"*80
rdmueller
  • 10,742
  • 10
  • 69
  • 126