rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.45k stars 205 forks source link

Run incorrectly in cmder in windows #193

Closed flt6 closed 1 year ago

flt6 commented 1 year ago

In windows, it runs like this. image

rsalmei commented 1 year ago

I've explained in other issues that windows do not support ANSI Escape Codes, which are necessary to read the number of columns available and to control the cursor.

But I think windows users can do something to counter those, like installing colorama and/or using another terminal, but I'm not sure as I've never used windows for python programming. Please search for closed issues regarding windows here.

flt6 commented 1 year ago

I have checked that ANSI Escape Codes is available in console cmder.

I have checked with the following ways:

print "\033" directly in cmder:

print("\033[1;31mColorful text.\033[0m")

image

run colorama.init before using alive_progress

from alive_progress import alive_bar
from colorama import init
from time import sleep

init()
with alive_bar(10) as bar:
    bar.text = "111111111111111111111111111111111111111111111111111111111111111111"
    for i in range(5):
        sleep(2)
        bar()

image

Check in cmder setting

image image

TheTechRobo commented 1 year ago

Please provide your code or else we cant help you.

flt6 commented 1 year ago

Please provide your code or else we cant help you.

I have referenced at last commit.

from alive_progress import alive_bar
from colorama import init
from time import sleep

init()
with alive_bar(10) as bar:
    bar.text = "111111111111111111111111111111111111111111111111111111111111111111"
    for i in range(5):
        sleep(2)
        bar()
rsalmei commented 1 year ago

That's excellent! Thanks for the additional info. I'm glad it does support ANSI Escape Codes. Which terminal is this? I suppose it is not the default one.

It seems it is not retrieving the terminal size, that's why alive-progress does not know where to clip the row. A few months ago, to support some unusual environments, I started using the shutil version, which does not fail ever and just returns 80 columns in these cases... Please test this:

In [2]: import os

In [3]: os.get_terminal_size()
Out[3]: os.terminal_size(columns=120, lines=40)
TheTechRobo commented 1 year ago

They said cmder, so from a quick google looks like https://cmder.app/

flt6 commented 1 year ago

I have run your test code.

>>> os.get_terminal_size()
os.terminal_size(columns=149, lines=41)

>>> os.terminal_size(columns=120, lines=40)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: structseq() missing required argument 'sequence' (pos 1)
>>> os.terminal_size((120,40))      # maybe it should be like this
os.terminal_size(columns=120, lines=40)