Last active
March 28, 2025 06:58
-
-
Save sbz/bca2d1327910e0d8cadff1835625cbf2 to your computer and use it in GitHub Desktop.
get terminal size using ioctl get win size (TIOCGWINSZ) in Python
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
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