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

How to show an option to stop the progress after the progress has started #132

Open
shirishpandharikar opened this issue Apr 16, 2022 · 3 comments

Comments

@shirishpandharikar
Copy link

We have a requirement where we monitor the progress of background tasks via events. The progress bar works just fine. We have a requirement where in we also need to show the user an option to stop the background task. For this we want to show the user a prompt on the console E.g. Press X to exit: after the progress is displayed. How can this be achieved? The progress bar seems to take over and the user is not able to input anything. Below is how we expect it

0% [>                                  ]    243/100000  (0:00:12 / 1:23:51)
Press X to exit: 

If the user inputs X and presses enter the program will stop the background task and exit. Any help here would be really appreciated.

@ctongfei
Copy link
Owner

You can do something like the following, which I think should work (let me know if it does not work):

progressBar.pause();
boolean exit = /* prompt the user response */;
if (exit) progressBar.close() else progressBar.resume();

@shirishpandharikar
Copy link
Author

You can do something like the following, which I think should work (let me know if it does not work):

progressBar.pause();
boolean exit = /* prompt the user response */;
if (exit) progressBar.close() else progressBar.resume();

Thanks for the quick reply. I think I did not explain the requirement correctly. The progressbar should show the progress as long as the task is running. While the progressbar is being updated continuously at some interval the user should also be shown an option to stop the background task via a prompt. Here is what I understand from your solution:

  1. Pause the progressbar before showing the prompt to the user
  2. Accept the input from the user
  3. If the input matches the stop/cancel command close the progressbar
  4. If the input does not match resume the progress

If the task is running and the user does not give any input the above solution will not show any progress and just wait. We want the progress bar to continue as long the user does not input anything.

@ctongfei
Copy link
Owner

ctongfei commented May 6, 2022

Thanks. I now understand your request. This is unfortunately not possible right now: the constant printing of the progress bar will interfere with normal output stream. To fix this one need to track the coordinate location of the progress bar on the screen while normal text is printing -- which is difficult. It may be supported in a future version.

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