Module: deluge
Branch: master
Commit: b11468c19bc1f2ce21e076d5be945efbdc84878f

Author: Nick Lanham <[email protected]>
Date:   Tue Feb 22 17:17:55 2011 +0100

handle double-wide unicode characters

---

 deluge/ui/console/modes/format_utils.py |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/deluge/ui/console/modes/format_utils.py 
b/deluge/ui/console/modes/format_utils.py
index 3b73edb..81906d4 100644
--- a/deluge/ui/console/modes/format_utils.py
+++ b/deluge/ui/console/modes/format_utils.py
@@ -33,6 +33,11 @@
 #
 
 import deluge.common
+try:
+    import unicodedata
+    haveud = True
+except:
+    haveud = False
 
 def format_speed(speed):
     if (speed > 0):
@@ -61,7 +66,14 @@ def trim_string(string, w):
         return "%s... "%(string[0:w-4])
 
 def format_column(col, lim):
-    size = len(col)
+    dbls = 0
+    if haveud and isinstance(col,unicode):
+        # might have some double width chars
+        for c in col:
+            if unicodedata.east_asian_width(c) in ['W','F']:
+                # found a wide/full char
+                dbls += 1
+    size = len(col)+dbls
     if (size >= lim - 1):
         return trim_string(col,lim)
     else:

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to