fix terminal dimension detection to work with stdout

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-07-26 13:13:10 +02:00
parent 71cb42d263
commit ed8e24312c
5 changed files with 21 additions and 3 deletions

View File

@ -1,3 +1,9 @@
Changes between 1.3.2 and 1.3.3a1
==================================================
- fix weirdness: make terminal width detection work on stdout instead of stdin
(thanks Armin Ronacher for reporting)
Changes between 1.3.1 and 1.3.2
==================================================

View File

@ -8,7 +8,7 @@ dictionary or an import path.
(c) Holger Krekel and others, 2004-2010
"""
__version__ = version = "1.3.2"
__version__ = version = "1.3.3a1"
import py.apipkg

View File

@ -18,7 +18,7 @@ if sys.platform == "win32":
def _getdimensions():
import termios,fcntl,struct
call = fcntl.ioctl(0,termios.TIOCGWINSZ,"\000"*8)
call = fcntl.ioctl(1,termios.TIOCGWINSZ,"\000"*8)
height,width = struct.unpack( "hhhh", call ) [:2]
return height, width

View File

@ -26,7 +26,7 @@ def main():
name='py',
description='py.test and pylib: rapid testing and development utils.',
long_description = long_description,
version= '1.3.2',
version= '1.3.3a1',
url='http://pylib.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

View File

@ -6,6 +6,18 @@ def test_get_terminal_width():
x = py.io.get_terminal_width
assert x == terminalwriter.get_terminal_width
def test_getdimensions(monkeypatch):
fcntl = py.test.importorskip("fcntl")
import struct
l = []
monkeypatch.setattr(fcntl, 'ioctl', lambda *args: l.append(args))
try:
terminalwriter._getdimensions()
except struct.error:
pass
assert len(l) == 1
assert l[0][0] == 1
def test_terminal_width_COLUMNS(monkeypatch):
""" Dummy test for get_terminal_width
"""