Rev 4749: Tweaked as hinted in reviews. in file:///home/vila/src/bzr/bugs/353370-notty-no-term-width/

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


At file:///home/vila/src/bzr/bugs/353370-notty-no-term-width/

------------------------------------------------------------
revno: 4749
revision-id: v.ladeuil+lp at free.fr-20091022084035-swi9xvao11z2w7ke
parent: joke.de.buhr at seiken.de-20091015103147-go9anvw5el0f0zd7
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 353370-notty-no-term-width
timestamp: Thu 2009-10-22 10:40:35 +0200
message:
  Tweaked as hinted in reviews.
  
  * bzrlib/osutils.py:
  (terminal_width): Still returns an insanely high value, but
  explaining why and making sure we work in more cases.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2009-10-15 04:06:32 +0000
+++ b/NEWS	2009-10-22 08:40:35 +0000
@@ -22,6 +22,10 @@
 Bug Fixes
 *********
 
+* ``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)
+
 Improvements
 ************
 

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2009-10-15 10:31:47 +0000
+++ b/bzrlib/osutils.py	2009-10-22 08:40:35 +0000
@@ -1296,8 +1296,13 @@
 
 def terminal_width():
     """Return estimated terminal width."""
-    if not sys.stdout.isatty():
-        return 10000
+    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]



More information about the bazaar-commits mailing list