4

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 3

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

I agree with @Nir Levy. Consider however that this looks very aged for anything but perhaps some quick one-time installation interface.. Then again, I don't know what your constraints are. If at all possible, consider awt, swing or swt
1

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." ); 
    }
}

Comments

0

Not directly. In the old days ANSI escape sequences was supported, but not anymore.

I would suggest you look into a good Java Curses library supporting Windows. I cannot recommend any :(

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.