Does Java support controlling the cursor when outputting to a console? For example, I'd like to set the character position, and possibly color, before doing a System.out.print(). Think of the way an application like top writes to the console. Thanks!
3 Answers
You usually do not use system.out to do these things. most applications in *nix use NCURSES (http://en.wikipedia.org/wiki/Ncurses) for this. You can try http://sourceforge.net/projects/javacurses/ if you need something this smart.
However, you can always sysout backspace (\b) characters if you want to delete what you wanted, and hope for the best
Ha. You can still do it in Linux. Reference this man page for the codes themselves http://man7.org/linux/man-pages/man4/console_codes.4.html
public class quickTest{
public static void main( String[] args ){
//This will undo the current line by erasing it
//and then putting the curser back at column 1
System.out.println( "Hello.\u001b[1K\u001b[1GHi." );
}
}