How to make console output colorful

Jansi is a small ASl 2.0 licensed Java library that allows you to use ANSI escape sequences to format your console output which works even on windows.

Using jansi is easy. Before you start sending ANSI escape sequences to System.out make sure you run:

AnsiConsole.systemInstall();

If you would rather not mess with the System.out settings, you can use the AnsiConsole.out PrintStream instead. For example:

AnsiConsole.out.println("Hello World");

Here is an example which will print colorful output :

AnsiConsole.systemInstall();

    System.out.println(ansi().fg(RED).a("Hello World").reset());
    System.out.println( ansi().eraseScreen().fg(RED).a("Hello").fg(GREEN).a(" World").reset() );
    AnsiConsole.systemUninstall();

Library can be downloaded from here : http://fusesource.github.io/jansi/

Leave a Reply

Your email address will not be published. Required fields are marked *