Closed hartmut27 closed 9 years ago
It has something to do with Jansi. If I skip the Jansi Test, everything works fine!
package testprog;
public class AnsiKonsoleTestJansi {
public static void main(String[] args) {
// Direct Test
System.out.println("Hello \u001b[1;31mred\u001b[0m world!");
}
}
Produces:
Hello red world!
where red is printed in red :+1:
Now it is perfect.
package testprog;
import static org.fusesource.jansi.Ansi.ansi;
import static org.fusesource.jansi.Ansi.Color.GREEN;
import static org.fusesource.jansi.Ansi.Color.RED;
public class AnsiKonsoleTestJansi {
public static void main(String[] args) {
// Test with Jansi
// In Eclipse: Remove:
// AnsiConsole.systemInstall();
// In Eclipse: Don't do eraseScreen().
System.out.println(ansi().isEnabled());
System.out.println(ansi().fg(RED).a("Hello").fg(GREEN).a(" World")
.reset());
System.out.println(ansi().render("@|red Hello|@ @|green World|@"));
// Direct Test
System.out.println("Hello \u001b[1;31mred\u001b[0m world!");
}
}
Do you use http://mvnrepository.com/artifact/org.fusesource.jansi/jansi/1.11 ?
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.11</version>
</dependency>
nice to know
@paulvi Yes, I like jansi; (in fact, I have even contributed some improvements :-)
I usually download jansi directly from http://jansi.fusesource.org/ And when I need it in maven (for instance in https://github.com/mihnita/java-color-loggers), then I add the dependency, and "just works" (probably comes from mvnrepository, but I have never checked)
@hartmut27
One of my comments at http://mihai-nita.net/java has another solution, jansi.passthrough:
One cause possible: many libraries detect if the standard output is redirected, and if that is the case, they don’s output ANSI escapes anymore.
In most cases there are ways to force them to do that, but the solution is library specific. One example is jansi, and the way to force it is by setting jansi.passthrough
This means you can pass it as a parameter at execution and you don't need to touch the code at all.
@paulvi, mihnita yes, I am using jansi Version 1.11. I can confirm: doing before anything else:
System.setProperty("jansi.passthrough", "true");
works perfect.
In Eclipse Luna Release (4.4.0) Build id: 20140612-0600 on Windows 7 I can only produce black on white output in the ANSI Console. I am very curious how I could solve this problem.
Eclpse setup: Windows -> Preferences -> Ansi Console -> Enabled, Use Windows color mapping, Color palette: Windows XP command prompt.
Gradle Dependency for this
Output black on white: