mihnita / ansi-econsole

Eclipse plugin that understands ANSI escape sequences to color the Eclipse console output.
http://www.mihai-nita.net/java/
Other
91 stars 25 forks source link

Only black on white output #11

Closed hartmut27 closed 9 years ago

hartmut27 commented 9 years ago

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.

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;

import org.fusesource.jansi.AnsiConsole;

public class AnsiKonsoleTestJansi {

    public static void main(String[] args) {

        // Test with Jansi
        AnsiConsole.systemInstall();
        System.out.println(ansi().isEnabled());
        System.out.println(ansi().eraseScreen().fg(RED).a("Hello").fg(GREEN).a(" World")
                .reset());
        System.out.println(ansi().eraseScreen().render("@|red Hello|@ @|green World|@"));

        // Direct Test
        System.out.println("Hello \u001b[1;31mred\u001b[0m world!");

    }
}

Gradle Dependency for this

org.fusesource.jansi:jansi:1.11

Output black on white:

true
Hello World
Hello World
Hello red world!
hartmut27 commented 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:

hartmut27 commented 9 years ago

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!");

    }
}
paulvi commented 9 years ago

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

mihnita commented 9 years ago

@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)

mihnita commented 9 years ago

@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.

hartmut27 commented 9 years ago

@paulvi, mihnita yes, I am using jansi Version 1.11. I can confirm: doing before anything else:

System.setProperty("jansi.passthrough", "true");

works perfect.