Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is termios.TIOCGWINSZ

Tags:

python

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?

like image 711
William Avatar asked Apr 26 '13 13:04

William


1 Answers

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, IOCtl to Get the WINdow SiZe.

This bit of documentation might help you clear things up.

like image 138
glglgl Avatar answered Sep 25 '22 00:09

glglgl