~parthm/bzr/164450-push-pull-tags

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

terminal_width can now returns None.

* bzrlib/win32utils.py:
(get_console_size): Fix typo in comment.

* bzrlib/ui/text.py:
(TextProgressView._show_line): Handle the no terminal present case.

* bzrlib/tests/test_osutils.py:
(TestTerminalWidth): Update tests.

* bzrlib/tests/blackbox/test_too_much.py:
Fix some imports.
(OldTests.test_bzr): Handle the no terminal present case.

* bzrlib/tests/__init__.py:
(VerboseTestResult.report_test_start): Handle the no terminal
present case.

* bzrlib/status.py:
(show_pending_merges): Handle the no terminal present case.
(show_pending_merges.show_log_message): Factor out some
code. Handle the no terminal present case.

* bzrlib/osutils.py:
(terminal_width): Return None if no precise value can be found.

* bzrlib/log.py:
(LineLogFormatter.__init__): Handle the no terminal present case.
(LineLogFormatter.truncate): Accept None as max_len meaning no
truncation.
(LineLogFormatter.log_string): 

* bzrlib/help.py:
(_help_commands_to_text): Handle the no terminal present case.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1294
1294
    normalized_filename = _inaccessible_normalized_filename
1295
1295
 
1296
1296
 
1297
 
default_tty_width = 80
1298
 
"""The default terminal width for ttys."""
1299
 
default_non_tty_width = 256
1300
 
"""The default terminal width for non-ttys."""
 
1297
default_terminal_width = 80
 
1298
"""The default terminal width for ttys.
 
1299
 
 
1300
This is defined so that higher levels can share a common fallback value when
 
1301
terminal_width() returns None.
 
1302
"""
 
1303
 
 
1304
 
1301
1305
def terminal_width():
1302
 
    """Return estimated terminal width."""
 
1306
    """Return terminal width.
 
1307
 
 
1308
    None is returned if the width can't established precisely.
 
1309
    """
1303
1310
 
1304
1311
    # If the env var is set, take it, user is always right
1305
1312
    try:
1309
1316
 
1310
1317
    isatty = getattr(sys.stdout, 'isatty', None)
1311
1318
    if  isatty is None or not isatty():
1312
 
        # If it's not a tty, there is no way to acquire a value
1313
 
        # automatically. Yet, bzrlib expect a reasonable value here since it's
1314
 
        # used for both truncating lines or filling them. As such we need to
1315
 
        # use a reasonable default.  When the output is redirected, the pagers
1316
 
        # can then handle that themselves (or set COLUMNS if needed). A cleaner
1317
 
        # implementation would be to fix the callers to not try to format at
1318
 
        # all in these circumstances, but not formmatting when filling lines
1319
 
        # does not always make sense.
1320
 
        return default_non_tty_width
 
1319
        # Don't guess, setting COLUMNS is the recommended way to override.
 
1320
        return None
1321
1321
 
1322
1322
    if sys.platform == 'win32':
1323
 
        return win32utils.get_console_size(default_tty_width)[0]
 
1323
        return win32utils.get_console_size(defaultx=None)[0]
1324
1324
 
1325
1325
    try:
1326
1326
        import struct, fcntl, termios
1328
1328
        x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
1329
1329
        width = struct.unpack('HHHH', x)[1]
1330
1330
    except (IOError, AttributeError):
1331
 
        width = -1
 
1331
        return None
1332
1332
 
1333
1333
    if width <= 0:
1334
 
        width = default_tty_width
 
1334
        return None
1335
1335
 
1336
1336
    return width
1337
1337