[PATCH 1 of 2] termwidth: move to ui.ui from util

Augie Fackler durin42 at gmail.com
Sun Oct 10 10:23:50 CDT 2010


# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1286723196 18000
# Node ID 6380f00fa4e6a3ef2522594a1a843900f3e52ec0
# Parent  d664547ef54014b1a12cb8070bed0522b547b653
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 @@
     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 @@
                 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 @@
         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 @@
         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 @@
     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 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 @@
 
         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 @@
                 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 @@
     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 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


More information about the Mercurial-devel mailing list