summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-09-13 01:55:52 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-09-13 01:55:52 +0200
commitc8d80807c7580c4f723983d27408823bcee1b578 (patch)
treee6d30debf1d7e05e4ac59ecb7e8f90f194bd488e
parentd1bf1dfa53c995008d1f0e0e6dcf9db7fb36747f (diff)
downloadpoezio-c8d80807c7580c4f723983d27408823bcee1b578.tar.gz
poezio-c8d80807c7580c4f723983d27408823bcee1b578.tar.bz2
poezio-c8d80807c7580c4f723983d27408823bcee1b578.tar.xz
poezio-c8d80807c7580c4f723983d27408823bcee1b578.zip
fix issues with too long nicknames
-rw-r--r--src/windows.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/windows.py b/src/windows.py
index e942407f..e4ec29cf 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -51,6 +51,12 @@ g_lock = Lock()
LINES_NB_LIMIT = 4096
+def truncate_nick(nick, size=25):
+ if nick and len(nick) >= size:
+ return nick[:size]+'…'
+ return nick
+
+
class Win(object):
_win_core = None
def __init__(self):
@@ -474,9 +480,7 @@ class MucInfoWin(InfoWin):
nick = room.own_nick
if not nick:
return
- if len(nick) > 13:
- nick = nick[:13]+'…'
- self.addstr(nick, common.curses_color_pair(theme.COLOR_INFORMATION_BAR))
+ self.addstr(truncate_nick(nick, 13), common.curses_color_pair(theme.COLOR_INFORMATION_BAR))
def write_role(self, room):
"""
@@ -549,15 +553,12 @@ class TextWin(Win):
message.
"""
if message is None: # line separator
- log.debug('je build NON, cool non ? +++++++++++++++++++++++++++')
self.built_lines.append(None)
return 0
txt = message.txt
if not txt:
return 0
- nick = message.nickname
- if nick and len(nick) >= 25:
- nick = nick[:25]+'…'
+ nick = truncate_nick(message.nickname)
offset = 1 + len(message.str_time)
if nick:
offset += wcwidth.wcswidth(nick) + 2 # + nick + spaces length
@@ -565,7 +566,7 @@ class TextWin(Win):
offset += 1
if theme.CHAR_TIME_RIGHT:
offset += 1
- lines = cut_text(txt, self.width-offset-1)
+ lines = cut_text(txt, self.width-offset)
first = True
for line in lines:
self.built_lines.append(Line(msg=message,
@@ -591,7 +592,6 @@ class TextWin(Win):
self._win.erase()
for y, line in enumerate(lines):
if line is None:
- log.debug('COUCOU JE SUIS NONE\n\n-----------------')
self.write_line_separator()
else:
msg = line.msg
@@ -610,7 +610,7 @@ class TextWin(Win):
for y, line in enumerate(lines):
if not line:
continue
- self.write_text(y, (3 if line.msg.nickname else 1) + len(line.msg.str_time)+len(line.msg.nickname or ''), line.msg.txt[line.start_pos:line.end_pos])
+ self.write_text(y, (3 if line.msg.nickname else 1) + len(line.msg.str_time)+len(truncate_nick(line.msg.nickname) or ''), line.msg.txt[line.start_pos:line.end_pos])
if y != self.height-1:
self.addstr('\n')
self._win.attrset(0)
@@ -634,7 +634,7 @@ class TextWin(Win):
return
if color:
self._win.attron(common.curses_color_pair(color))
- self.addstr(nickname)
+ self.addstr(truncate_nick(nickname))
if color:
self._win.attroff(common.curses_color_pair(color))
self.addstr("> ")