Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 7547:4949729ee9ee
python implementation of diffstat
Implemented as two functions: diffstat, which yields lines of text,
formatted as a usual diffstat output, and diffstatdata, which is called
inside diffstat to do real performing and yield file names with
appropriate data (numbers of added and removed lines).
author | Alexander Solovyov <piranha@piranha.org.ua> |
---|---|
date | Thu, 25 Dec 2008 10:48:24 +0200 |
parents | 9e186bda013d |
children | 016a7319e76b |
line wrap: on
line diff
--- a/mercurial/util.py Sun Dec 28 19:59:42 2008 +0100 +++ b/mercurial/util.py Thu Dec 25 10:48:24 2008 +0200 @@ -1985,3 +1985,24 @@ def uirepr(s): # 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.stdout, sys.stdin): + try: + fd = dev.fileno() + if not os.isatty(fd): + continue + arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8) + return array.array('h', arri)[1] + except ValueError: + pass + except ImportError: + pass + return 80