Skip to content

Instantly share code, notes, and snippets.

View gvanrossum's full-sized avatar

Guido van Rossum gvanrossum

View GitHub Profile
@sbz
sbz / tty-size.py
Last active September 27, 2017 21:39
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