What is termios.TIOCGWINSZ

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 exactly is termios.TIOCGWINSZ ?

+8
python
source share
1 answer

This is a magic constant determined by the system on which you work. terminal driver.

In combination with ioctl() it serves to say exactly what you want, in your case call IOCtl to get the window size. So the name is TIOCGWINSZ , IOC tl to G et WIN dow S i Z e.

This bit of documentation can help you figure it out.

+15
source share

All Articles