1

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. 
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
  • Have you tried [`Ansi#eraseScreen(Ansi.Erase)`](http://fusesource.github.io/jansi/documentation/api/org/fusesource/jansi/Ansi.html#eraseScreen-org.fusesource.jansi.Ansi.Erase-) and using one of the other erase methods? It might not be possible and might be limitation of the API – MadProgrammer Apr 05 '17 at 22:18
  • @MadProgrammer Just tried it; it has the same problem. – sdgfsdh Apr 06 '17 at 07:24
  • Your examplecode worked correctly when running in a console under Windows 10. – Jan Feb 20 '20 at 13:23

1 Answers1

0

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"));
vizen10
  • 3
  • 3