From 287b04e50a8a132f224def6ee1b36e8f4d0b105f Mon Sep 17 00:00:00 2001
From: Todd Gamblin <tgamblin@llnl.gov>
Date: Sun, 23 Nov 2014 17:53:21 -0600
Subject: Bugfix in terminal_size()

---
 lib/spack/llnl/util/tty/__init__.py | 23 +++++++++++++----------
 lib/spack/llnl/util/tty/colify.py   |  4 ++--
 2 files changed, 15 insertions(+), 12 deletions(-)

(limited to 'lib')

diff --git a/lib/spack/llnl/util/tty/__init__.py b/lib/spack/llnl/util/tty/__init__.py
index 652d1cc1a8..5eeab67d6f 100644
--- a/lib/spack/llnl/util/tty/__init__.py
+++ b/lib/spack/llnl/util/tty/__init__.py
@@ -25,6 +25,9 @@
 import sys
 import os
 import textwrap
+import fcntl
+import termios
+import struct
 from StringIO import StringIO
 
 from llnl.util.tty.color import *
@@ -155,7 +158,7 @@ def hline(label=None, **kwargs):
     color     = kwargs.get('color', '')
     max_width = kwargs.get('max_width', 64)
 
-    cols, rows = terminal_size()
+    rows, cols = terminal_size()
     if not cols:
         cols = max_width
     else:
@@ -178,22 +181,22 @@ def hline(label=None, **kwargs):
 
 
 def terminal_size():
-    """Gets the dimensions of the console: cols, rows."""
+    """Gets the dimensions of the console: (rows, cols)."""
     def ioctl_GWINSZ(fd):
         try:
-            cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
+            rc = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
         except:
             return
-        return cr
-    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
-    if not cr:
+        return rc
+    rc = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
+    if not rc:
         try:
             fd = os.open(os.ctermid(), os.O_RDONLY)
-            cr = ioctl_GWINSZ(fd)
+            rc = ioctl_GWINSZ(fd)
             os.close(fd)
         except:
             pass
-    if not cr:
-        cr = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80))
+    if not rc:
+        rc = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80))
 
-    return int(cr[1]), int(cr[0])
+    return int(rc[0]), int(rc[1])
diff --git a/lib/spack/llnl/util/tty/colify.py b/lib/spack/llnl/util/tty/colify.py
index ff06241937..0d068351a6 100644
--- a/lib/spack/llnl/util/tty/colify.py
+++ b/lib/spack/llnl/util/tty/colify.py
@@ -121,7 +121,7 @@ def colify(elts, **options):
 
     console_cols = options.get("cols", None)
     if not console_cols:
-        console_cols, console_rows = terminal_size()
+        console_rows, console_cols = terminal_size()
     elif type(console_cols) != int:
         raise ValueError("Number of columns must be an int")
     console_cols = max(1, console_cols - indent)
@@ -167,7 +167,7 @@ def colified(elts, **options):
 if __name__ == "__main__":
     import optparse
 
-    cols, rows = terminal_size()
+    rows, cols = terminal_size()
     parser = optparse.OptionParser()
     parser.add_option("-u", "--uniform", action="store_true", default=False,
                       help="Use uniformly sized columns instead of variable-size.")
-- 
cgit v1.2.3-70-g09d2