I want to get the size of the terminal. I am using this functionality:
import sys, struct, fcntl, termios
s = struct.pack('HHHH', 0, 0, 0, 0)
t = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, s)
print(struct.unpack('HHHH', t))
But what on earth is termios.TIOCGWINSZ
?
It is a magic constant determined by the system you are running on resp. by the terminal driver.
In combination with ioctl()
, it serves to tell exectly what you want, in your case call IOCtl to Get the Window Size. Thus the name TIOCGWINSZ
, IOC
tl to G
et the WIN
dow S
iZ
e.
This bit of documentation might help you clear things up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With