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

Windows terminal size #12

Open
GoogleCodeExporter opened this issue Nov 16, 2015 · 2 comments
Open

Windows terminal size #12

GoogleCodeExporter opened this issue Nov 16, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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

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

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

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

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

1 participant