zvyn / python-progressbar

Automatically exported from code.google.com/p/python-progressbar
Other
0 stars 0 forks source link

Windows terminal size #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

The library uses the wrong terminal width on windows so here is some code for 
finding it:

def get_windows_term_width():
    from ctypes import windll, create_string_buffer
    h = windll.kernel32.GetStdHandle(-12)
    csbi = create_string_buffer(22)
    res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
    if res:
        import struct
        (bufx, bufy, curx, cury, wattr,
         left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
        sizex = right - left + 1
    else:
        sizex = 80
    return sizex

Your library really rocks btw!

Original issue reported on code.google.com by bjou...@gmail.com on 30 May 2011 at 9:02

GoogleCodeExporter commented 9 years ago
Cool. I didn't even know that windows terminals could be resized horizontally. 
Does that work for all windows versions?

Original comment by nilton.v...@gmail.com on 30 May 2011 at 10:05

GoogleCodeExporter commented 9 years ago
Both of you are cool. FYI get_windows_term_width's working report is following.
Every test runs on Windows XP SP3 x86.

Regards!

* Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
    -> Works well with no fix.

* IronPython 2.7 (2.7.0.40) on .NET 4.0.30319.225
    -> Works well with some fix.

IronPython doesn't allow such syntax of new line.
----
[BEFORE]
(bufx, bufy, curx, cury, wattr,
         left, top, right, bottom, maxx, maxy)
[AFTER]
(bufx, bufy, curx, cury, wattr,left, top, right, bottom, maxx, maxy)
----

* Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)[GCC 4.3.4 20090804 (release) 
1] on cygwin
    -> Doesn't work, but cygwin's os.name returns 'posix'. So no problem.

----
ImportError: cannot import name windll
----

Original comment by sakurai....@gmail.com on 10 Jun 2011 at 6:59