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

Seems to be a bug with early closing the terminal #137

Open
bepopov opened this issue Jun 23, 2022 · 1 comment
Open

Seems to be a bug with early closing the terminal #137

bepopov opened this issue Jun 23, 2022 · 1 comment
Labels

Comments

@bepopov
Copy link

bepopov commented Jun 23, 2022

Hello.

Thank you for your efforts in creating this great lib! It saved a lot of time for me.

Unfortunately, I think I found a bug. I tried to create several progress bars in my Spring Shell application sequentially but I faced with issue in cmd and PowerShell on Windows: after closing the first progress bar the width of each newly created one reduced, moreover, I wasn't able to print messages in terminal. While investigation I dived into progress bar's source code and found that library is closing the terminal when progress is finished.

class ProgressUpdateAction implements Runnable {
    //...
    public void run() {
        if (first) {
            forceRefresh();
            first = false;
        }
        else {
            if (!progress.paused) refresh();
            if (!progress.alive) {
                forceRefresh();
                consumer.close();
                TerminalUtils.closeTerminal();
            }
        }
    }
    //...
}

When it is closed each new creation of progress bar will also create dumb terminal using TerminalUtils.getTerminal(). Therefore the width is changing. And as initial terminal is closed output stream is also becoming to be closed (I assume it closes the System.out too so that is why I couldn't print anything even to there).

I downloaded the source code and removed TerminalUtils.closeTerminal(); line, built library locally and everything worked fine. Not closing the terminal also allows user to use terminal's output stream so user can change color of he's text and print messages to one output stream instead of printing via System.err. I would suggest to remove this line in the library too. Also maybe it would be good to mention in docs that user has to close Terminal by his own

@ctongfei
Copy link
Owner

Hi @bepopov, thanks for the issue and investigation!

However, I'm not sure why it behaves like you described. TerminalUtils.closeTerminal() does not close the System.out stream: see the source code at

synchronized static void closeTerminal() {

Creating progress bars sequentially might be a problem if the prior one is not yet closed and another Terminal is created. Can you try adding synchronized to TerminalUtils.getTerminal() method to see if it resolves your problem?

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

No branches or pull requests

2 participants