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

Multiple Progress Bars keep printing new lines on Windows #16

Open
pranjalchaubey opened this issue Mar 15, 2020 · 17 comments
Open

Multiple Progress Bars keep printing new lines on Windows #16

pranjalchaubey opened this issue Mar 15, 2020 · 17 comments

Comments

@pranjalchaubey
Copy link

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
Copy link
Member

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
Copy link
Author

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
Copy link

even though after scrolling a new bar appears

@TaiSakuma
Copy link
Member

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.

@TaiSakuma TaiSakuma changed the title Multiple Progress Bars keep printing new lines Multiple Progress Bars keep printing new lines on Windows Apr 26, 2020
@SwapnilSoni1999
Copy link

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
Copy link
Member

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

@SwapnilSoni1999
Copy link

Sure sir i ll upload screen record if possible

@TaiSakuma
Copy link
Member

@SwapnilSoni1999 Sounds great. Thank you.

@TaiSakuma
Copy link
Member

@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
Copy link
Author

Thanks @TaiSakuma, I will check it out!

@TaiSakuma
Copy link
Member

@pranjalchaubey, that is great. Thank you.

@udptcp
Copy link

udptcp commented May 21, 2020

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
Copy link
Member

@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
Copy link

udptcp commented May 22, 2020

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
Copy link
Member

@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
Copy link

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
Copy link

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

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

No branches or pull requests

5 participants