Created
November 1, 2013 17:22
-
-
Save marsam/7268750 to your computer and use it in GitHub Desktop.
terminal size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import sys | |
| def terminal_size(): | |
| width, height = None, None | |
| if sys.platform == 'win32': | |
| import win32utils | |
| width, height = win32utils.get_console_size(defaultx=width, defaulty=height) | |
| else: | |
| try: | |
| import struct, fcntl, termios | |
| s = struct.pack('HHHH', 0, 0, 0, 0) | |
| x = fcntl.ioctl(1, termios.TIOCGWINSZ, s) | |
| height, width = struct.unpack('HHHH', x)[0:2] | |
| except (IOError, AttributeError): | |
| pass | |
| return width, height |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment