(default_width=80)
| 41 | |
| 42 | |
| 43 | def determine_terminal_width(default_width=80): |
| 44 | # If we can't detect the terminal width, the default_width is returned. |
| 45 | try: |
| 46 | from fcntl import ioctl |
| 47 | from termios import TIOCGWINSZ |
| 48 | except ImportError: |
| 49 | return default_width |
| 50 | try: |
| 51 | height, width = struct.unpack( |
| 52 | 'hhhh', ioctl(sys.stdout, TIOCGWINSZ, '\000' * 8) |
| 53 | )[0:2] |
| 54 | except Exception: |
| 55 | return default_width |
| 56 | else: |
| 57 | return width |
| 58 | |
| 59 | |
| 60 | def center_text( |