Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle - multiple progress bars #122

Open
mfrechePgest opened this issue Jan 7, 2022 · 2 comments
Open

Gradle - multiple progress bars #122

mfrechePgest opened this issue Jan 7, 2022 · 2 comments

Comments

@mfrechePgest
Copy link

mfrechePgest commented Jan 7, 2022

Hey !
Don't know if it's the same problem as this issue : #20

Progress bar is working fine in my Gradle environment using single progress bars.

But i tried with the "new" multiple progress bars feature initiated by @vehovsky
And I can only see a single one.

Pretty simple test :

build.gradle

plugins {
    id 'java'
    id 'application'
}

group 'com.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation "me.tongfei:progressbar:0.9.2"
}

application {
    getMainClass().set("Main")
}

Main.java

import me.tongfei.progressbar.ProgressBar;

import java.util.concurrent.atomic.AtomicInteger;

public class Main {

    public static void main(String[] args) {
        try (ProgressBar pb1 = new ProgressBar("Job1", 10000);
             ProgressBar pb2 = new ProgressBar("Job2", 50000)) {

            AtomicInteger i1 = new AtomicInteger(0);
            AtomicInteger i2 = new AtomicInteger(0);
            new Thread(() -> {
                while (i1.getAndIncrement() < 10000) {
                    try {
                        Thread.sleep(1000);
                        pb1.step();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();


            while (i2.getAndIncrement() < 50000) {
                try {
                    Thread.sleep(1000);
                    pb2.step();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }


    }

}

./gradlew run only show a single progressbar

They seems to overwrite each other (i can briefly see that on first round)

Works smoothly without Gradle involved.

EDIT : Issue seems similar to this one : #103 involving IDEA
Or this one on Gradle side : gradle/gradle#17581 for another tool

@ctongfei
Copy link
Owner

Thanks @mfrechePgest . Yes I am aware of this and this is the same as #20. Sorry, but I have no idea how to fix this.

@Lc3586
Copy link

Lc3586 commented May 7, 2023

Hey ! Don't know if it's the same problem as this issue : #20

Progress bar is working fine in my Gradle environment using single progress bars.

But i tried with the "new" multiple progress bars feature initiated by @vehovsky And I can only see a single one.

Pretty simple test :

build.gradle

plugins {
    id 'java'
    id 'application'
}

group 'com.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation "me.tongfei:progressbar:0.9.2"
}

application {
    getMainClass().set("Main")
}

Main.java

import me.tongfei.progressbar.ProgressBar;

import java.util.concurrent.atomic.AtomicInteger;

public class Main {

    public static void main(String[] args) {
        try (ProgressBar pb1 = new ProgressBar("Job1", 10000);
             ProgressBar pb2 = new ProgressBar("Job2", 50000)) {

            AtomicInteger i1 = new AtomicInteger(0);
            AtomicInteger i2 = new AtomicInteger(0);
            new Thread(() -> {
                while (i1.getAndIncrement() < 10000) {
                    try {
                        Thread.sleep(1000);
                        pb1.step();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();


            while (i2.getAndIncrement() < 50000) {
                try {
                    Thread.sleep(1000);
                    pb2.step();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }


    }

}

./gradlew run only show a single progressbar

They seems to overwrite each other (i can briefly see that on first round)

Works smoothly without Gradle involved.

EDIT : Issue seems similar to this one : #103 involving IDEA Or this one on Gradle side : gradle/gradle#17581 for another tool

maybe you can try this

/**
     * 支持在控制台打印多行进度条
     *
     * @author LCTR
     * @date 2023-05-07
     */
    public class ConsoleMultiProgressBarConsumer
            extends ConsoleProgressBarConsumer {
        final int index;
        final PrintStream out;

        public ConsoleMultiProgressBarConsumer(PrintStream out,
                                               int index) {
            super(out);
            this.out = out;
            this.index = index;
        }

        public ConsoleMultiProgressBarConsumer(PrintStream out,
                                               int maxRenderedLength,
                                               int index) {
            super(out,
                  maxRenderedLength);
            this.out = out;
            this.index = index;
        }

        @Override
        public void accept(String str) {
            out.print(StringExtension.newString("\r\n",
                                                index));

            out.print(matcher.appendTail(sb));
            //super.accept(str);

            out.print(StringExtension.newString("\033[F",
                                                index));
        }
    }
new ProgressBarBuilder()
                                .setTaskName("#01"))
                                .setInitialMax(100)
                                .setConsumer(new ConsoleMultiProgressBarConsumer(new PrintStream(new FileOutputStream(FileDescriptor.out)),
                                                                                 1))
                                .hideEta()
                                .setUpdateIntervalMillis(100)
                                .build();
new ProgressBarBuilder()
                                .setTaskName("#02"))
                                .setInitialMax(100)
                                .setConsumer(new ConsoleMultiProgressBarConsumer(new PrintStream(new FileOutputStream(FileDescriptor.out)),
                                                                                 2))
                                .hideEta()
                                .setUpdateIntervalMillis(100)
                                .build();
new ProgressBarBuilder()
                                .setTaskName("#03"))
                                .setInitialMax(100)
                                .setConsumer(new ConsoleMultiProgressBarConsumer(new PrintStream(new FileOutputStream(FileDescriptor.out)),
                                                                                 3))
                                .hideEta()
                                .setUpdateIntervalMillis(100)
                                .build();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants