1330
1330
normalized_filename = _inaccessible_normalized_filename
1333
default_terminal_width = 80
1334
"""The default terminal width for ttys.
1336
This is defined so that higher levels can share a common fallback value when
1337
terminal_width() returns None.
1333
1341
def terminal_width():
1334
"""Return estimated terminal width."""
1342
"""Return terminal width.
1344
None is returned if the width can't established precisely.
1347
# If BZR_COLUMNS is set, take it, user is always right
1349
return int(os.environ['BZR_COLUMNS'])
1350
except (KeyError, ValueError):
1353
isatty = getattr(sys.stdout, 'isatty', None)
1354
if isatty is None or not isatty():
1355
# Don't guess, setting BZR_COLUMNS is the recommended way to override.
1335
1358
if sys.platform == 'win32':
1336
return win32utils.get_console_size()[0]
1359
return win32utils.get_console_size(defaultx=None)[0]
1339
1362
import struct, fcntl, termios
1340
1363
s = struct.pack('HHHH', 0, 0, 0, 0)
1341
1364
x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
1342
1365
width = struct.unpack('HHHH', x)[1]
1366
except (IOError, AttributeError):
1367
# If COLUMNS is set, take it
1347
width = int(os.environ['COLUMNS'])
1369
return int(os.environ['COLUMNS'])
1370
except (KeyError, ValueError):
1374
# Consider invalid values as meaning no width