alphatwirl / atpbar

Progress bars for threading and multiprocessing tasks on terminal and Jupyter Notebook
https://alphatwirl.github.io/atpbar/
MIT License
93 stars 10 forks source link

Multiple Progress Bars keep printing new lines on Windows #16

Open pranjalchaubey opened 4 years ago

pranjalchaubey commented 4 years ago

Hi I am trying the simple two progress bars example, but my terminal is printing each bar on a newline.

   for i in atpbar(range(4), name='outer'):
        n = random.randint(500, 1000)
        for j in atpbar(range(n), name='inner {}'.format(i)):
            time.sleep(0.0001)

pbar How to fix this problem?

TaiSakuma commented 4 years ago

Thank you for letting me know about the issue.

Would you mind also letting me know the OS, Python version, and Terminal app that you are using, please?

pranjalchaubey commented 4 years ago

hi Tai OS - Windows 10 Python - 3.6 Terminal - CMD

The code gives a similar output on the terminal running inside VS Code as well.

SwapnilSoni1999 commented 4 years ago

even though after scrolling a new bar appears

TaiSakuma commented 4 years ago

Thank you for letting me know. I apologize for the delay. I don't have access to a windows machine at the moment and cannot test it. I will try when I can use Windows.

SwapnilSoni1999 commented 4 years ago

Also there is issue on linux too. When the threads exceed size of terminal window, and when I scroll it it duplicates printing of progress bars

TaiSakuma commented 4 years ago

@SwapnilSoni1999 I see. I think that that is a different issue. Would you mind creating a new issue?

SwapnilSoni1999 commented 4 years ago

Sure sir i ll upload screen record if possible

TaiSakuma commented 4 years ago

@SwapnilSoni1999 Sounds great. Thank you.

TaiSakuma commented 4 years ago

@pranjalchaubey, I released the version 1.1.2.

I updated the escape code for controlling the cursor on the terminal.

This version might work on Windows although I haven't had a chance to test it because I didn't have a Windows machine.

pranjalchaubey commented 4 years ago

Thanks @TaiSakuma, I will check it out!

TaiSakuma commented 4 years ago

@pranjalchaubey, that is great. Thank you.

udptcp commented 4 years ago

Hi Tai, for me it's not fixed on windows. I am trying to run:

n = random.randint(1000, 10000)
for i in atpbar(range(n)):  
    time.sleep(0.00001)

And this is my result on windows CMD:

grafik

TaiSakuma commented 4 years ago

@udptcp, thank you for letting me know.

Would you mind letting me the version of Windows that you used? You wrote that you used "windows CMD". That is Windows Console, I assume. I think that atpbar might work on Windows Terminal because it seems to support ANSI escape code.

udptcp commented 4 years ago

Thanks @TaiSakuma

I use Windows 10 LTSC version 1607 and tested with Windows Console. Windows Terminal needs at least version 1903 to work, so I can't check this out. But I have tried to connect via PuTTY to my machine and execute the script. This is the result:

grafik

TaiSakuma commented 4 years ago

@udptcp, thank you for letting me know about Windows Terminal. I wasn't aware that it only works with recent versions of Windows 10.

Thank you also for the screenshot on PuTTY. It might work there if the terminal is a bit wider. At the moment, atpbar doesn't work properly if the terminal width is less than 90 characters (I intend to fix it someday).

johnnymads-zz commented 4 years ago

On Windows, you have to call SetConsoleMode with ENABLE_VIRTUAL_TERMINAL_PROCESSING (see https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#cursor-positioning). Doing so in python is explained here: https://stackoverflow.com/questions/36760127/how-to-use-the-new-support-for-ansi-escape-sequences-in-the-windows-10-console

I put import ctypes

kernel32 = ctypes.windll.kernel32 kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7) at the top of my script and atpbar worked great in both cmd and powershell.

johnnymads-zz commented 4 years ago

A much more robust version of the code is here: https://bugs.python.org/issue30075