Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixed bug when calculating width of terminal

  • Loading branch information...
commit 173bdb80ec265dded73d3e8531bf24c659aa921a 1 parent 29c4499
Giles Lavelle authored

Showing 1 changed file with 9 additions and 5 deletions. Show diff stats Hide diff stats

  1. 14  gridformat.py
14  gridformat.py
... ...
@@ -1,3 +1,6 @@
  1
+from settings import DEBUG
  2
+
  3
+
1 4
 def format_grid(grid, divider_positions=[], truncatable_column=None):
2 5
     """
3 6
     Create a string that displays a 2D array of values in a formatted and aligned table
@@ -21,20 +24,21 @@ def format_grid(grid, divider_positions=[], truncatable_column=None):
21 24
     separator_width = 3
22 25
     # Total number of characters used by all column separators in one row of the grid
23 26
     separators_width = num_columns * separator_width
  27
+    # Default width for a lot of systems
  28
+    terminal_width = 80
24 29
 
25 30
     # Try to determine the width of the user's terminal window in characters
26 31
     # so the rows can be truncated if they are too long
27 32
     try:
28 33
         import subprocess
29  
-        terminal_width = int(subprocess.check_output('stty size').split()[1])
  34
+        terminal_width = int(subprocess.check_output(['stty', 'size']).split()[1])
30 35
 
31  
-    except:
  36
+    except Exception as error:
  37
+        if DEBUG:
  38
+            print error
32 39
         print 'The size of your terminal window could not be determined so ' \
33 40
             'the layout of the grid below may be broken due to text wrapping.'
34 41
 
35  
-        # Default width for a lot of systems
36  
-        terminal_width = 80
37  
-
38 42
     # If the grid is wider than the terminal window work out the difference between them -
39 43
     # this is the number of characters by which the table should be truncated
40 44
     terminal_diff = None

0 notes on commit 173bdb8

Please sign in to comment.
Something went wrong with that request. Please try again.