ctongfei / progressbar

Terminal-based progress bar for Java / JVM
http://tongfei.me/progressbar/
MIT License
1.07k stars 102 forks source link

Multi thread progress bars overwriting each other #128

Closed NikR-IV closed 2 years ago

NikR-IV commented 2 years ago

I'm trying to create two progressbars for tasks in two different threads, but only one progressbar shows properly in windows cmd or powershell. here's my code:

        new Thread(){
            @Override
            public void run() {
                ProgressBar pb = new ProgressBar("task 1",100);
                for(int i = 0 ; i < 100 ; ++i){
                    pb.step();
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                ProgressBar pb = new ProgressBar("task 2",200);
                for(int i = 0 ; i < 100 ; ++i){
                    pb.step();
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();

Please correct me if any usage is wrong, thanks.

ctongfei commented 2 years ago

See #100 and #109 : Progressbar is known to be broken on Cygwin / cmd / Powershell when using multiple bars. Multiple bars are only working under Linux/Mac/WSL. Sorry, but as of now there is no fix to this.