# HG changeset patch # User Patrick Mezard # Date 1272314566 -7200 # Node ID 648130161e4da3c07cd0585a7e97a0df3ceedabb # Parent 4d3288197717d8b0cdb4d910910c8e4c8d685027# Parent 18e81d42ee5c141484e023fcc57e6b56feed3cef Merge with crew-stable diff -r 4d3288197717 -r 648130161e4d mercurial/posix.py --- a/mercurial/posix.py Mon Apr 26 21:35:09 2010 +0200 +++ b/mercurial/posix.py Mon Apr 26 22:42:46 2010 +0200 @@ -265,3 +265,27 @@ def gethgcmd(): return sys.argv[:1] + +def termwidth_(): + try: + import termios, array, fcntl + for dev in (sys.stderr, sys.stdout, sys.stdin): + try: + try: + fd = dev.fileno() + except AttributeError: + continue + if not os.isatty(fd): + continue + arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8) + return array.array('h', arri)[1] + except ValueError: + pass + except IOError, e: + if e[0] == errno.EINVAL: + pass + else: + raise + except ImportError: + pass + return 80 diff -r 4d3288197717 -r 648130161e4d mercurial/util.py --- a/mercurial/util.py Mon Apr 26 21:35:09 2010 +0200 +++ b/mercurial/util.py Mon Apr 26 22:42:46 2010 +0200 @@ -1252,35 +1252,6 @@ # Avoid double backslash in Windows path repr() return repr(s).replace('\\\\', '\\') -def termwidth(): - if 'COLUMNS' in os.environ: - try: - return int(os.environ['COLUMNS']) - except ValueError: - pass - try: - import termios, array, fcntl - for dev in (sys.stderr, sys.stdout, sys.stdin): - try: - try: - fd = dev.fileno() - except AttributeError: - continue - if not os.isatty(fd): - continue - arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8) - return array.array('h', arri)[1] - except ValueError: - pass - except IOError, e: - if e[0] == errno.EINVAL: - pass - else: - raise - except ImportError: - pass - return 80 - def wrap(line, hangindent, width=None): if width is None: width = termwidth() - 2 @@ -1364,3 +1335,11 @@ if not i: return False return True + +def termwidth(): + if 'COLUMNS' in os.environ: + try: + return int(os.environ['COLUMNS']) + except ValueError: + pass + return termwidth_() diff -r 4d3288197717 -r 648130161e4d mercurial/windows.py --- a/mercurial/windows.py Mon Apr 26 21:35:09 2010 +0200 +++ b/mercurial/windows.py Mon Apr 26 22:42:46 2010 +0200 @@ -356,6 +356,13 @@ def gethgcmd(): return [sys.executable] + sys.argv[:1] +def termwidth_(): + # cmd.exe does not handle CR like a unix console, the CR is + # counted in the line length. On 80 columns consoles, if 80 + # characters are written, the following CR won't apply on the + # current line but on the new one. Keep room for it. + return 79 + try: # override functions with win32 versions if possible from win32 import *