summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2008-12-16 19:00:39 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-12-16 19:00:39 -0700
commit67b688c7b26845dedeca378d4ba8df88e6b44c0c (patch)
tree4411552b3c9bd8231468d4977d392d652336a8e1 /ipalib
parente05fd7ab03eb05c26e880ae04fbf095198b58027 (diff)
downloadfreeipa-67b688c7b26845dedeca378d4ba8df88e6b44c0c.tar.gz
freeipa-67b688c7b26845dedeca378d4ba8df88e6b44c0c.tar.xz
freeipa-67b688c7b26845dedeca378d4ba8df88e6b44c0c.zip
Jakub Hrozek's patch to make textui.get_tty_width() actually work
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/cli.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 37fdad445..a0fe63db2 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -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):
"""