Rev 4758: Re-fix the priority order since there is a known valid case. in file:///home/vila/src/bzr/bugs/353370-notty-no-term-width/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri Dec 4 11:27:57 GMT 2009
At file:///home/vila/src/bzr/bugs/353370-notty-no-term-width/
------------------------------------------------------------
revno: 4758
revision-id: v.ladeuil+lp at free.fr-20091204112757-2dz18xsbug1322q7
parent: v.ladeuil+lp at free.fr-20091204112038-8dzq6ugle9xb83od
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 353370-notty-no-term-width
timestamp: Fri 2009-12-04 12:27:57 +0100
message:
Re-fix the priority order since there is a known valid case.
* bzrlib/tests/test_osutils.py:
(TestTerminalWidth.test_falls_back_to_COLUMNS): Ensures COLUMNS is
taken into account if BZR_COLUMNS is not set.
* bzrlib/osutils.py:
(terminal_width): COLUMNS takes priority on termios.TIOCGWINSZ as
shown by tests under emacs (on no counter examples are known).
-------------- next part --------------
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2009-12-04 11:20:38 +0000
+++ b/bzrlib/osutils.py 2009-12-04 11:27:57 +0000
@@ -1358,17 +1358,21 @@
if sys.platform == 'win32':
return win32utils.get_console_size(defaultx=None)[0]
+ # If COLUMNS is set, take it, the terminal knows better (at least under
+ # emacs, COLUMNS gives an accurate answer while the fcntl.ioctl call below
+ # doesn't) -- vila 20091204
+ try:
+ return int(os.environ['COLUMNS'])
+ except (KeyError, ValueError):
+ pass
+
try:
import struct, fcntl, termios
s = struct.pack('HHHH', 0, 0, 0, 0)
x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
width = struct.unpack('HHHH', x)[1]
except (IOError, AttributeError):
- # If COLUMNS is set, take it
- try:
- return int(os.environ['COLUMNS'])
- except (KeyError, ValueError):
- return None
+ return None
if width <= 0:
# Consider invalid values as meaning no width
=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py 2009-12-04 10:09:11 +0000
+++ b/bzrlib/tests/test_osutils.py 2009-12-04 11:27:57 +0000
@@ -1936,6 +1936,11 @@
os.environ['BZR_COLUMNS'] = '12'
self.assertEquals(12, osutils.terminal_width())
+ def test_falls_back_to_COLUMNS(self):
+ del os.environ['BZR_COLUMNS']
+ os.environ['COLUMNS'] = '42'
+ self.assertEquals(42, osutils.terminal_width())
+
def test_tty_default_without_columns(self):
del os.environ['BZR_COLUMNS']
del os.environ['COLUMNS']
More information about the bazaar-commits
mailing list