diff options
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r-- | ipalib/cli.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index ca3364ae..518b7129 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): """ @@ -433,11 +443,11 @@ class show_api(frontend.Application): else: for name in namespaces: if name not in self.api: - exit_error('api has no such namespace: %s' % name) + raise errors.NoSuchNamespaceError(name) names = namespaces lines = self.__traverse(names) ml = max(len(l[1]) for l in lines) - self.print_name() + self.Backend.textui.print_name('run') first = True for line in lines: if line[0] == 0 and not first: @@ -453,7 +463,7 @@ class show_api(frontend.Application): s = '1 attribute shown.' else: s = '%d attributes show.' % len(lines) - self.print_dashed(s) + self.Backend.textui.print_dashed(s) def __traverse(self, names): |