diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-10-15 18:29:16 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-10-15 18:30:25 +0300 |
commit | f9de5bcc0cd0df360d7ff7e13ce284a89fde02a9 (patch) | |
tree | b7b4f3fe13d0ba5f7affc484350f0d85865277c3 /ttystatus/tty.py | |
parent | 9fd6ba3d79e2e3f5a1a022cf334528deeb43f793 (diff) | |
download | python-ttystatus-f9de5bcc0cd0df360d7ff7e13ce284a89fde02a9.tar.gz |
Add terminal size query to public interface
Diffstat (limited to 'ttystatus/tty.py')
-rw-r--r-- | ttystatus/tty.py | 11 |
1 files changed, 6 insertions, 5 deletions
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. |