Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Rewriting Multiple Lines in the Console

Tags:

java

console

I am running Windows, however the program I am writing needs to be cross compatible with Linux.

I am aware that you can rewrite (or replace a already written line in the console with another) single lines in the console in both Windows/Linux just by using \r

System.out.print("Initial line");
System.out.print("\r");
System.out.print("Updated line");

but I would like to rewrite multiple lines like:

System.out.print("Line 1");
System.out.print("Line 2");
// magic code
System.out.print("Updated line 1");
System.out.print("Updated line 2");

I would guess that you use something along the lines of \b, etc but I am at a loss. Anyone know how this is done? (NO 3RD PARTY LIBRARIES)

like image 640
ahoward Avatar asked Jul 04 '26 04:07

ahoward


1 Answers

I am afraid that is not possible. Windows documentation shows it cannot be done. I know you said no third party libraries, but would you mind trying curses. That is the only hope I see AFAIK.

like image 200
abhiroxx Avatar answered Jul 06 '26 16:07

abhiroxx