Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java cli running indicator

I want some ascii characters periodically changing to indicate my CLI program is running, like -|\/-|/.... The old character is replaced by the new, which looks like an animation. Is there any library approaching that?

Kejia

like image 368
象嘉道 Avatar asked Dec 09 '25 23:12

象嘉道


1 Answers

You might want to use the carriage return(CR) character ('\r' in java) to do this. I would do it this way (assuming you are doing the animation at the beginning of the row):

My solution (Test.java):

public class Test
{
    public static void main(String[] args)
    {
        try
        {
            System.out.print("\\");
            Thread.sleep(1000);
            System.out.print("\r|");
            Thread.sleep(1000);
            System.out.print("\r/");
        }catch(Exception e)
        {
        }
    }
}
like image 99
INS Avatar answered Dec 11 '25 14:12

INS