From f9de5bcc0cd0df360d7ff7e13ce284a89fde02a9 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 15 Oct 2015 18:29:16 +0300 Subject: Add terminal size query to public interface --- ttystatus/tty.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'ttystatus/tty.py') diff --git a/ttystatus/tty.py b/ttystatus/tty.py index 31a9036..db0962a 100644 --- a/ttystatus/tty.py +++ b/ttystatus/tty.py @@ -62,27 +62,28 @@ class PhysicalTerminal(object): assert self._el is not None return self._cr + self._el - def get_width(self): - '''Return width of terminal in characters. + def get_size(self): + '''Return width, height of terminal in characters, rows. - If this fails, assume 80. + If this fails, assume 80 by 24. Borrowed and adapted from bzrlib. ''' width = 80 + height = 24 if self._terminal is not None: try: s = struct.pack('HHHH', 0, 0, 0, 0) x = fcntl.ioctl( self._terminal.fileno(), termios.TIOCGWINSZ, s) - width = struct.unpack('HHHH', x)[1] + height, width = struct.unpack('HHHH', x)[:2] except IOError: pass - return width + return width, height def write(self, raw_data): '''Write raw data to terminal. -- cgit v1.2.1