| 1 | Gracefully deal with 'stty size' failures. |
| 2 | Submitted upstream. |
| 3 | |
| 4 | |
| 5 | |
| 6 | def get_cols(): |
| 7 | stty = which('stty') |
| 8 | if stty: |
| 9 | row_cols = commands.getoutput("%s size" % stty) |
| 10 | - rows, cols = map(int, row_cols.split()) |
| 11 | + try: |
| 12 | + rows, cols = map(int, row_cols.split()) |
| 13 | + except: |
| 14 | + # In some cases 'stty size' will just fail with |
| 15 | + # "Inappropriate ioctl for device". |
| 16 | + cols = DEFAULT_NUM_COLS |
| 17 | return cols |
| 18 | else: |
| 19 | return DEFAULT_NUM_COLS |