Mercurial > hg-stable
changeset 30322:4b1af1c867fa
scmutil: move util.termwidth()
I'm going to get rid of sys.stderr|out|in references from posix.termwidth().
In order to do that, termwidth() needs to take a ui, but functions in util.py
shouldn't depend on a ui object. So moves termwidth() to scmutil.py.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 20 Oct 2016 21:38:44 +0900 |
parents | d500ddae7494 |
children | 5c379b1f56c7 |
files | mercurial/posix.py mercurial/scmposix.py mercurial/scmutil.py mercurial/scmwindows.py mercurial/ui.py mercurial/util.py mercurial/windows.py |
diffstat | 7 files changed, 38 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/posix.py Sun Nov 06 00:37:50 2016 -0700 +++ b/mercurial/posix.py Thu Oct 20 21:38:44 2016 +0900 @@ -463,36 +463,6 @@ def gethgcmd(): return sys.argv[:1] -def termwidth(): - try: - import array - import termios - for dev in (sys.stderr, sys.stdout, sys.stdin): - try: - try: - fd = dev.fileno() - except AttributeError: - continue - if not os.isatty(fd): - continue - try: - arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8) - width = array.array('h', arri)[1] - if width > 0: - return width - except AttributeError: - pass - except ValueError: - pass - except IOError as e: - if e[0] == errno.EINVAL: - pass - else: - raise - except ImportError: - pass - return 80 - def makedir(path, notindexed): os.mkdir(path)
--- a/mercurial/scmposix.py Sun Nov 06 00:37:50 2016 -0700 +++ b/mercurial/scmposix.py Thu Oct 20 21:38:44 2016 +0900 @@ -1,5 +1,7 @@ from __future__ import absolute_import +import errno +import fcntl import os import sys @@ -38,3 +40,33 @@ return [encoding.environ['home'] + '/lib/hgrc'] else: return [os.path.expanduser('~/.hgrc')] + +def termwidth(): + try: + import array + import termios + for dev in (sys.stderr, sys.stdout, sys.stdin): + try: + try: + fd = dev.fileno() + except AttributeError: + continue + if not os.isatty(fd): + continue + try: + arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8) + width = array.array('h', arri)[1] + if width > 0: + return width + except AttributeError: + pass + except ValueError: + pass + except IOError as e: + if e[0] == errno.EINVAL: + pass + else: + raise + except ImportError: + pass + return 80
--- a/mercurial/scmutil.py Sun Nov 06 00:37:50 2016 -0700 +++ b/mercurial/scmutil.py Thu Oct 20 21:38:44 2016 +0900 @@ -40,6 +40,7 @@ systemrcpath = scmplatform.systemrcpath userrcpath = scmplatform.userrcpath +termwidth = scmplatform.termwidth class status(tuple): '''Named tuple with a list of files per status. The 'deleted', 'unknown'
--- a/mercurial/scmwindows.py Sun Nov 06 00:37:50 2016 -0700 +++ b/mercurial/scmwindows.py Thu Oct 20 21:38:44 2016 +0900 @@ -5,6 +5,7 @@ from . import ( osutil, util, + win32, ) try: @@ -51,3 +52,6 @@ path.append(os.path.join(userprofile, 'mercurial.ini')) path.append(os.path.join(userprofile, '.hgrc')) return path + +def termwidth(): + return win32.termwidth()
--- a/mercurial/ui.py Sun Nov 06 00:37:50 2016 -0700 +++ b/mercurial/ui.py Thu Oct 20 21:38:44 2016 +0900 @@ -822,7 +822,7 @@ return int(encoding.environ['COLUMNS']) except ValueError: pass - return util.termwidth() + return scmutil.termwidth() def formatted(self): '''should formatted output be used?
--- a/mercurial/util.py Sun Nov 06 00:37:50 2016 -0700 +++ b/mercurial/util.py Thu Oct 20 21:38:44 2016 +0900 @@ -122,7 +122,6 @@ statfiles = getattr(osutil, 'statfiles', platform.statfiles) statisexec = platform.statisexec statislink = platform.statislink -termwidth = platform.termwidth testpid = platform.testpid umask = platform.umask unlink = platform.unlink
--- a/mercurial/windows.py Sun Nov 06 00:37:50 2016 -0700 +++ b/mercurial/windows.py Thu Oct 20 21:38:44 2016 +0900 @@ -38,7 +38,6 @@ setsignalhandler = win32.setsignalhandler spawndetached = win32.spawndetached split = os.path.split -termwidth = win32.termwidth testpid = win32.testpid unlink = win32.unlink