termwidth: move to ui.ui from util
authorAugie Fackler <durin42@gmail.com>
Sun, 10 Oct 2010 10:06:36 -0500
changeset 12689 c52c629ce19e
parent 12688 8c034a825cfe
child 12690 94e7bd38d9a3
termwidth: move to ui.ui from util
hgext/churn.py
hgext/mq.py
hgext/progress.py
mercurial/cmdutil.py
mercurial/commands.py
mercurial/posix.py
mercurial/ui.py
mercurial/util.py
mercurial/win32.py
mercurial/windows.py
--- a/hgext/churn.py	Thu Oct 07 23:34:21 2010 -0500
+++ b/hgext/churn.py	Sun Oct 10 10:06:36 2010 -0500
@@ -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
 
--- a/hgext/mq.py	Thu Oct 07 23:34:21 2010 -0500
+++ b/hgext/mq.py	Sun Oct 10 10:06:36 2010 -0500
@@ -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:
--- a/hgext/progress.py	Thu Oct 07 23:34:21 2010 -0500
+++ b/hgext/progress.py	Sun Oct 10 10:06:36 2010 -0500
@@ -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):
--- a/mercurial/cmdutil.py	Thu Oct 07 23:34:21 2010 -0500
+++ b/mercurial/cmdutil.py	Sun Oct 10 10:06:36 2010 -0500
@@ -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),
--- a/mercurial/commands.py	Thu Oct 07 23:34:21 2010 -0500
+++ b/mercurial/commands.py	Sun Oct 10 10:06:36 2010 -0500
@@ -1834,7 +1834,7 @@
     Returns 0 if successful.
     """
     option_lists = []
-    textwidth = util.termwidth() - 2
+    textwidth = ui.termwidth() - 2
 
     def addglobalopts(aliases):
         if ui.verbose:
--- a/mercurial/posix.py	Thu Oct 07 23:34:21 2010 -0500
+++ b/mercurial/posix.py	Sun Oct 10 10:06:36 2010 -0500
@@ -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):
--- a/mercurial/ui.py	Thu Oct 07 23:34:21 2010 -0500
+++ b/mercurial/ui.py	Sun Oct 10 10:06:36 2010 -0500
@@ -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?
 
--- a/mercurial/util.py	Thu Oct 07 23:34:21 2010 -0500
+++ b/mercurial/util.py	Sun Oct 10 10:06:36 2010 -0500
@@ -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.
 
--- a/mercurial/win32.py	Thu Oct 07 23:34:21 2010 -0500
+++ b/mercurial/win32.py	Sun Oct 10 10:06:36 2010 -0500
@@ -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)
--- a/mercurial/windows.py	Thu Oct 07 23:34:21 2010 -0500
+++ b/mercurial/windows.py	Sun Oct 10 10:06:36 2010 -0500
@@ -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