Jansi escape sequences ignored when running javaexec from gradle

(Mark Fisher) #1

When i run a class that outputs colour (using jansi) via a gradle JavaExec task, all of the escape sequences are lost. It works fine if I invoke the class directly from java.

For example

class AnsiConsoleTest {
 def static main(args) {
  System.out.println( ansi().render("@|red Hello|@ @|green World|@") )

Using the following task:

task runConsoleTest(type: JavaExec, dependsOn: "classes") {
 description = "Runs the Ansi Console Tester"
 main = 'AnsiConsoleTest'
 classpath configurations.compile, configurations.runtime, sourceSets.main.output

and invoking gives:

$ gradle runConsoleTest
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
Hello World
  Total time: 5.437 secs

where the UP-TO-DATE messages are coloured correctly, but my output is not.

Is there a way to get it to work via the gradle task invocation?

I did a search on forums, but the only thing I could find vaguely related to colour issues was this feature request: http://forums.gradle.org/gradle/topics/feature_request_force_color_option_color

but this doesn’t appear to be my problem, I am seeing colour in the build process, just not on execution of my class.

Thanks, Mark

(Luke Daley) #2

This is always the case with forked processes in Java. Pre Java 7, there’s no way to have a child process inherit the stdio handles.

What we will do, eventually, is add support for stdio handle inheritance (using JNA for pre Java 7). I’ve raised GRADLE-2530 for this.

Unfortunately right now, there’s no way to give this child process access to the console.

(Mark Fisher) #3

Thanks for the reply Luke.