From 93c60fc277e37109a4ead36f69a6a50b7f72b229 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 10 Dec 2011 11:13:28 -0800 Subject: get_term_size: all values >= 0 for bug #394091 --- pym/portage/output.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pym/portage/output.py b/pym/portage/output.py index 6b10f7b6c..43d75036e 100644 --- a/pym/portage/output.py +++ b/pym/portage/output.py @@ -422,12 +422,14 @@ class StyleWriter(formatter.DumbWriter): def get_term_size(): """ Get the number of lines and columns of the tty that is connected to - stdout. Returns a tuple of (lines, columns) or (-1, -1) if an error + stdout. Returns a tuple of (lines, columns) or (0, 0) if an error occurs. The curses module is used if available, otherwise the output of - `stty size` is parsed. + `stty size` is parsed. The lines and columns values are guaranteed to be + greater than or equal to zero, since a negative COLUMNS variable is + known to prevent some commands from working (see bug #394091). """ if not sys.stdout.isatty(): - return -1, -1 + return (0, 0) try: import curses try: @@ -442,10 +444,13 @@ def get_term_size(): out = out.split() if len(out) == 2: try: - return int(out[0]), int(out[1]) + val = (int(out[0]), int(out[1])) except ValueError: pass - return -1, -1 + else: + if val[0] >= 0 and val[1] >= 0: + return val + return (0, 0) def set_term_size(lines, columns, fd): """ -- cgit v1.2.3-1-g7c22