mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Jakub Hrozek's patch to make textui.get_tty_width() actually work
This commit is contained in:
committed by
Jason Gerard DeRose
parent
e05fd7ab03
commit
67b688c7b2
@@ -28,6 +28,9 @@ import getpass
|
||||
import code
|
||||
import optparse
|
||||
import socket
|
||||
import fcntl
|
||||
import termios
|
||||
import struct
|
||||
|
||||
import frontend
|
||||
import backend
|
||||
@@ -67,8 +70,15 @@ class textui(backend.Backend):
|
||||
|
||||
If stdout is not a tty, this method will return ``None``.
|
||||
"""
|
||||
# /usr/include/asm/termios.h says that struct winsize has four
|
||||
# unsigned shorts, hence the HHHH
|
||||
if sys.stdout.isatty():
|
||||
return 80 # FIXME: we need to return the actual tty width
|
||||
try:
|
||||
winsize = fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ,
|
||||
struct.pack('HHHH', 0, 0, 0, 0))
|
||||
return struct.unpack('HHHH', winsize)[1]
|
||||
except IOError:
|
||||
return None
|
||||
|
||||
def max_col_width(self, rows, col=None):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user