fusesource / jansi

Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.
http://fusesource.github.io/jansi/
Apache License 2.0
1.1k stars 139 forks source link

Jansi does not work when running application with `gradle run` #283

Open tauinger-de opened 4 months ago

tauinger-de commented 4 months ago

I wrote a tiny Java application and run it through Gradle 8.5 but there is no colored output.

it works when running in Intellij with flag -Djansi.passthrough=true.

Adding the same flag to Gradle doesn't make a difference (gradle -Djansi.passthrough=true clean run)

tauinger-de commented 4 months ago

I could get it to work by adding (thanks to chatgpt)

application {
    applicationDefaultJvmArgs = ["-Djansi.passthrough=true"]
}
tkslaw commented 2 months ago

I could get it to work by adding (thanks to chatgpt)

application {
    applicationDefaultJvmArgs = ["-Djansi.passthrough=true"]
}

Thank you for that solution. And if you want a narrower scope, you can instead just configure the run task:

tasks {
    named<JavaExec>("run") {
        systemProperty("jansi.passthrough", "true")
    }
}

- Kotlin DSL

Though note JANSI_PASSTHROUGH is deprecated in favor of JANSI_MODE. So, it would probably be better to use:

applicationDefaultJvmArgs = listOf("-Djansi.mode=force")

- Kotlin DSL

Or:

systemProperty("jansi.mode", "force")

- Kotlin DSL