Using Java, how do I create a console application that manipulates text in system.out?

For example, instead of printing /
- Page \
/

on a new line to make it stay on the same line and be an animation?

+4
source share
3 answers

Yes, type \b (backspace) to remove the last character. In a nutshell:

 System.out.print('/'); System.out.print('\b'); System.out.print('-'); System.out.print('\b'); System.out.print('\\'); System.out.print('\b'); 

Please note that this one does not work in the Eclipse console due to an error. However, in the command console, it should work fine.

+7
source

If you need to position the text cursor, the solution should be through JNI. You will need C cursor positioning software that will not be portable. Curses was a popular application about 15-20 years ago.
The question is, do you really need this trip to the past?

+1
source

Perhaps you should implement a command line interface in your application. Then you can completely control the command line behavior. Libraries like Clamshell-Cli can do the hard work for you.

0
source

Source: https://habr.com/ru/post/1336052/


All Articles