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

Using ProgressBar constructor and building it using ProgressBarBuilder yields different results #163

Open
nathanduchesne opened this issue May 28, 2024 · 1 comment

Comments

@nathanduchesne
Copy link

nathanduchesne commented May 28, 2024

I am experiencing different program behaviour when running this code
ProgressBar pb = new ProgressBar(name, 100);

or this code:

ProgressBar.builder().setTaskName(progressBarName).setInitialMax(progressBarMaxCapacity).setStyle(ProgressBarStyle.ASCII).build();

What I was expecting:
Everything works the same, except case 2 has a different display, since we no longer use Unicode.

What happens:
When using the builder, the default PrintStream is not System.err, but instead is

static ConsoleProgressBarConsumer createConsoleConsumer(int predefinedWidth) {
        PrintStream real = new PrintStream(new FileOutputStream(FileDescriptor.err));
        return createConsoleConsumer(real, predefinedWidth);  // System.err might be overridden by System.setErr
    }

(see Utils.java, line 20-23)

Why this may be a problem:
My code redirects certain streams (typically System.err) to other streams, and hence uses System.setErr() to redirect it. Because of this inconsistency, I can no longer do so.
Additionally, I am uncertain as to what benefits you gain from instantiating the PrintStream the way you do so in the above code, as opposed to using System.err directly.

What can easily be done :)

Would you be open to changing
PrintStream real = new PrintStream(new FileOutputStream(FileDescriptor.err));
with
PrintStream real = System.err;

This would make the whole code consistent. Let me know what you think and if you want me to make a pull request for this change!

Best,
Nathan

@ctongfei
Copy link
Owner

Thanks Nathan! I think this deliberate choice of instantiating from FileDescriptor.err is to force it to display it on the screen, if stderr is used for something else (which is likely when used within a build system). Maybe we could add a switch somewhere so that the stream can be customized?

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

2 participants