diff mercurial/util.py @ 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 98f2507c5551
children 96095d9ff1f8
line wrap: on
line diff
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1032,6 +1032,13 @@ def shortuser(user):
         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):