(Jan-16-2017, 08:25 AM)wavic Wrote: [ -> ]Hm! I don't know what you are doing with it. How about that way:
>>> import blessings
>>> t = blessings.Terminal()
>>> print '{}x{}'.format(t.height, t.width)
24x80
>>>
The good thing here... If you change the virtual terminal window size, t.height and t.width are changed accordingly.
that module cannot be found. i am distributing a script that needs to know. here is the solution i came up with:
def get_terminal_geometry(fd=0):
import fcntl,struct,termios
return struct.unpack('4H',fcntl.ioctl(fd,termios.TIOCGWINSZ,struct.pack('4H',0,0,0,0)))[1::-1]
Output:
lt1/forums /home/forums 12> py2
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def get_terminal_geometry(fd=0):
... import fcntl,struct,termios
... return struct.unpack('4H',fcntl.ioctl(fd,termios.TIOCGWINSZ,struct.pack('4H',0,0,0,0)))[1::-1]
...
>>> t=get_terminal_geometry()
>>> print '{}x{}'.format(t[1],t[0])
46x166
>>>
lt1/forums /home/forums 13> py3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def get_terminal_geometry(fd=0):
... import fcntl,struct,termios
... return struct.unpack('4H',fcntl.ioctl(fd,termios.TIOCGWINSZ,struct.pack('4H',0,0,0,0)))[1::-1]
...
>>> t=get_terminal_geometry()
>>> print('{}x{}'.format(t[1], t[0]))
46x166
>>>
lt1/forums /home/forums 14>