changeset 3767:1861fa38a6a7

Move ellipsis code to util.ellipsis() and improve maxlength handling.
author Thomas Arendsen Hein <thomas@intevation.de>
date Sat, 02 Dec 2006 22:35:17 +0100
parents 581665242c07
children 6ae3685be45d
files mercurial/commands.py mercurial/util.py
diffstat 2 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sat Dec 02 22:16:00 2006 +0100
+++ b/mercurial/commands.py	Sat Dec 02 22:35:17 2006 +0100
@@ -3031,8 +3031,7 @@
         elif not inst[1]:
             u.warn(_(" empty string\n"))
         else:
-            u.warn("\n%r%s\n" %
-                    (inst[1][:400], len(inst[1]) > 400 and '...' or ''))
+            u.warn("\n%r\n" % util.ellipsis(inst[1]))
     except util.Abort, inst:
         u.warn(_("abort: %s\n") % inst)
     except TypeError, inst:
--- a/mercurial/util.py	Sat Dec 02 22:16:00 2006 +0100
+++ b/mercurial/util.py	Sat Dec 02 22:35:17 2006 +0100
@@ -1032,6 +1032,13 @@
         user = user[:f]
     return user
 
+def ellipsis(text, maxlength=400):
+    """Trim string to at most maxlength (default: 400) characters."""
+    if len(text) <= maxlength:
+        return text
+    else:
+        return "%s..." % (text[:maxlength-3])
+
 def walkrepos(path):
     '''yield every hg repository under path, recursively.'''
     def errhandler(err):