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.11k stars 140 forks source link

Colors are not interpreted anymore on Windows 10 cmd/PowerShell with the new 2.1.0 release #182

Closed AlexisJehan closed 3 years ago

AlexisJehan commented 3 years ago
package foo;

import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.AnsiConsole;

import java.io.PrintStream;

public class Foo {

    public static void main(final String[] args) {
        final PrintStream output = AnsiConsole.out();
        output.println(Ansi.ansi().fgBrightRed().a("Hello world").reset());
    }
}

Was working until 2.0.1: 2 0 1

Does not work anymore since 2.1.0: 2 1 0

Thanks in advance having a look.

gnodet commented 3 years ago

I've just tried both cmd and PowerShell on Windows 10 and it works for me. Do you have the latest windows 10 ? Could you run java -jar jansi-2.1.0.jar and paste the output please in both cmd and PowerShell ?

AlexisJehan commented 3 years ago

I confirm it works using java -jar jansi-2.1.0.jar.

This code was working until 2.0.1:

public static void main(final String[] args) {
    final PrintStream output = AnsiConsole.out();
    output.println(Ansi.ansi().fgBrightRed().a("Hello world").reset());
}

I've had another look, and this is working with 2.1.0, adding a single line:

public static void main(final String[] args) {
    AnsiConsole.systemInstall();
    final PrintStream output = AnsiConsole.out();
    output.println(Ansi.ansi().fgBrightRed().a("Hello world").reset());
}

So since 2.1.0, AnsiConsole.systemInstall(); appears to be required before using AnsiConsole.out(); to get colors in both PowerShell and cmd. That was not the case in previous versions.

gnodet commented 3 years ago

Ah, yes, that's right. If you want to restore the previous behavior, you can set the jansi.eager system property to true.