# HG changeset patch # User Augie Fackler # Date 2010-10-10 15:06:36 # Node ID c52c629ce19ea8206245885ee74ccd4153569e11 # Parent 8c034a825cfef3a6a9966c76967f4c9c0722116e termwidth: move to ui.ui from util diff --git a/hgext/churn.py b/hgext/churn.py --- a/hgext/churn.py +++ b/hgext/churn.py @@ -149,7 +149,7 @@ def churn(ui, repo, *pats, **opts): maxcount = float(max(sum(v) for k, v in rate)) or 1.0 maxname = max(len(k) for k, v in rate) - ttywidth = util.termwidth() + ttywidth = ui.termwidth() ui.debug("assuming %i character terminal\n" % ttywidth) width = ttywidth - maxname - 2 - 2 - 2 diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -1437,7 +1437,7 @@ class queue(object): ph = patchheader(self.join(patchname), self.plainmode) msg = ph.message and ph.message[0] or '' if self.ui.formatted(): - width = util.termwidth() - len(pfx) - len(patchname) - 2 + width = self.ui.termwidth() - len(pfx) - len(patchname) - 2 if width > 0: msg = util.ellipsis(msg, width) else: diff --git a/hgext/progress.py b/hgext/progress.py --- a/hgext/progress.py +++ b/hgext/progress.py @@ -156,7 +156,7 @@ class progbar(object): sys.stderr.flush() def width(self): - tw = util.termwidth() + tw = self.ui.termwidth() return min(int(self.ui.config('progress', 'width', default=tw)), tw) def progress(self, topic, pos, item='', unit='', total=None): diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -706,7 +706,7 @@ def diffordiffstat(ui, repo, diffopts, n diffopts = diffopts.copy(context=0) width = 80 if not ui.plain(): - width = util.termwidth() + width = ui.termwidth() chunks = patch.diff(repo, node1, node2, match, changes, diffopts, prefix=prefix) for chunk, label in patch.diffstatui(util.iterlines(chunks), diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1834,7 +1834,7 @@ def help_(ui, name=None, with_version=Fa Returns 0 if successful. """ option_lists = [] - textwidth = util.termwidth() - 2 + textwidth = ui.termwidth() - 2 def addglobalopts(aliases): if ui.verbose: diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -272,7 +272,7 @@ def spawndetached(args): def gethgcmd(): return sys.argv[:1] -def termwidth_(): +def termwidth(): try: import termios, array, fcntl for dev in (sys.stderr, sys.stdout, sys.stdin): diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -402,6 +402,16 @@ class ui(object): return i + def termwidth(self): + '''how wide is the terminal in columns? + ''' + if 'COLUMNS' in os.environ: + try: + return int(os.environ['COLUMNS']) + except ValueError: + pass + return util.termwidth() + def formatted(self): '''should formatted output be used? diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1393,14 +1393,6 @@ except NameError: return False return True -def termwidth(): - if 'COLUMNS' in os.environ: - try: - return int(os.environ['COLUMNS']) - except ValueError: - pass - return termwidth_() - def interpolate(prefix, mapping, s, fn=None): """Return the result of interpolating items in the mapping into string s. diff --git a/mercurial/win32.py b/mercurial/win32.py --- a/mercurial/win32.py +++ b/mercurial/win32.py @@ -181,7 +181,7 @@ def hidewindow(): pid = win32process.GetCurrentProcessId() win32gui.EnumWindows(callback, pid) -def termwidth_(): +def termwidth(): try: # Query stderr to avoid problems with redirections screenbuf = win32console.GetStdHandle(win32console.STD_ERROR_HANDLE) diff --git a/mercurial/windows.py b/mercurial/windows.py --- a/mercurial/windows.py +++ b/mercurial/windows.py @@ -356,7 +356,7 @@ def spawndetached(args): def gethgcmd(): return [sys.executable] + sys.argv[:1] -def termwidth_(): +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