How do I clear the screen using Jansi?

534 Views Asked by At

I am trying to clear the console in Java using Jansi. I am using macOS, but Jansi should be portable.

Here is the code that I have tried:

AnsiConsole.systemInstall();

System.out.println("Hello... ");
System.out.println(Ansi.ansi().eraseScreen());
System.out.println("... world.");

However, this does not clear the screen. It inserts many new lines and then prints the next line, like this:

Hello...






 ... world. 

How do I clear the screen properly, so that my final output is just the below?

... world. 
1

There are 1 best solutions below

0
On

Maybe you can try by overwriting the world "Hello..." with "...world".

It should be something like this:

System.out.print("Hello... ");
System.out.print(ansi().cursorLeft("Hello... ".lenght()).a("...world"));