Skip to content

Use colorama to get console width on Win32 #198

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ Grig Gheorghiu
Bob Ippolito
Christian Tismer
Wim Glenn
Stephen Rauch
11 changes: 8 additions & 3 deletions py/_io/terminalwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@


def _getdimensions():
import termios,fcntl,struct
call = fcntl.ioctl(1,termios.TIOCGWINSZ,"\000"*8)
height,width = struct.unpack( "hhhh", call ) [:2]
if colorama is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this platform check is incorrect, as colorama might be installed on non-windows environments

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just noted that the same code is down below
so this is basically bad code duplication (see the win32 object handling)

Copy link
Author

@stephenrauch stephenrauch Aug 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up near the top of the file is:

colorama = None
if sys.platform == "win32":
    try:
        import colorama

colorama will be None in non-windows environments since the import will not be attempted.

import termios,fcntl,struct
call = fcntl.ioctl(1,termios.TIOCGWINSZ,"\000"*8)
height,width = struct.unpack( "hhhh", call ) [:2]
else:
win = colorama.win32.GetConsoleScreenBufferInfo(colorama.win32.STDOUT).dwSize
height, width = win.Y, win.X

return height, width


Expand Down