Skip to content

Instantly share code, notes, and snippets.

@sbz
Last active September 27, 2017 21:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbz/bca2d1327910e0d8cadff1835625cbf2 to your computer and use it in GitHub Desktop.
Save sbz/bca2d1327910e0d8cadff1835625cbf2 to your computer and use it in GitHub Desktop.
get terminal size using ioctl get win size (TIOCGWINSZ) in Python
import termios
import fcntl
import os
import struct
with open(os.ctermid(), 'r') as fd:
packed = fcntl.ioctl(fd, termios.TIOCGWINSZ, struct.pack('HHHH', 0, 0, 0, 0))
rows, cols, h_pixels, v_pixels = struct.unpack('HHHH', packed)
print rows, cols, h_pixels, v_pixels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment