Mercurial > hg-stable
changeset 11010:18e81d42ee5c stable
util: fix default termwidth() under Windows
sys.stdout.write('-'*80 + '\n')
or
sys.stdout.write('-'*80 + '\r')
do not work on Windows as they do on unix. On a 80 columns Windows console, the
extra CR or LF are interpreted as if belonging to the next line, so the first
command displays 2 lines (only one on unix) and the second one leave the line
visible and move back to the following line. To avoid this, we sacrifice one
column under Windows.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Mon, 26 Apr 2010 22:30:40 +0200 |
parents | a0102da324ab |
children | 648130161e4d 409c0e4d79e9 |
files | mercurial/posix.py mercurial/util.py mercurial/windows.py |
diffstat | 3 files changed, 39 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/posix.py Tue Apr 27 00:44:06 2010 +0530 +++ b/mercurial/posix.py Mon Apr 26 22:30:40 2010 +0200 @@ -264,3 +264,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
--- a/mercurial/util.py Tue Apr 27 00:44:06 2010 +0530 +++ b/mercurial/util.py Mon Apr 26 22:30:40 2010 +0200 @@ -1245,35 +1245,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 @@ -1357,3 +1328,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_()
--- a/mercurial/windows.py Tue Apr 27 00:44:06 2010 +0530 +++ b/mercurial/windows.py Mon Apr 26 22:30:40 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 *