Rev 4764: terminal_width is now very large for non-tty in http://bazaar.launchpad.net/~vila/bzr/integration

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Oct 22 09:49:58 BST 2009


At http://bazaar.launchpad.net/~vila/bzr/integration

------------------------------------------------------------
revno: 4764 [merge]
revision-id: v.ladeuil+lp at free.fr-20091022084942-r6c1s2io9x8xjs8m
parent: pqm at pqm.ubuntu.com-20091022074533-1ll6d040i4ofk77b
parent: v.ladeuil+lp at free.fr-20091022084035-swi9xvao11z2w7ke
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: integration
timestamp: Thu 2009-10-22 10:49:42 +0200
message:
  terminal_width is now very large for non-tty
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2009-10-22 01:07:25 +0000
+++ b/NEWS	2009-10-22 08:49:42 +0000
@@ -25,6 +25,10 @@
 * ``bzr+http`` servers no longer give spurious jail break errors when
   serving branches inside a shared repository.  (Andrew Bennetts, #348308)
 
+* ``osutils.terminal_width()`` will now return a very large value
+  to avoid truuncated lines when using pagers (for example).
+  (Joke de Buhr, Vincent Ladeuil, #353370)
+
 * TreeTransform.adjust_path updates the limbo paths of descendants of adjusted
   files.  (Aaron Bentley)
 

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2009-10-15 04:01:26 +0000
+++ b/bzrlib/osutils.py	2009-10-22 08:40:35 +0000
@@ -1296,6 +1296,14 @@
 
 def terminal_width():
     """Return estimated terminal width."""
+    if getattr(sys.stdout, 'isatty', None) is None:
+        # If it's not a tty, the width makes no sense. We just use a value bug
+        # enough to avoid truncations. When the output is redirected, the
+        # pagers can then handle that themselves. A cleaner implementation
+        # would be to fix the callers to not try to format at all in these
+        # circumstances.
+        return 65536
+
     if sys.platform == 'win32':
         return win32utils.get_console_size()[0]
     width = 0



More information about the bazaar-commits mailing list