break line on spaces if possible. Fixed #1541

This commit is contained in:
louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 2010-06-30 10:21:16 +00:00
parent cf88579ec7
commit dc39cdab50

View file

@ -210,11 +210,21 @@ class TextWin(Win):
if nick: if nick:
offset += len(nick) + 2 # + nick + spaces length offset += len(nick) + 2 # + nick + spaces length
first = True first = True
this_line_was_broken_by_space = False
while txt != '': while txt != '':
if txt[:self.width-offset].find('\n') != -1: if txt[:self.width-offset].find('\n') != -1:
limit = txt[:self.width-offset].find('\n') limit = txt[:self.width-offset].find('\n')
else: else:
limit = self.width-offset-1 # break between words if possible
if len(txt) >= self.width:
limit = txt[:self.width-offset-1].rfind(' ')
this_line_was_broken_by_space = True
if limit <= 0:
limit = self.width-offset-1
this_line_was_broken_by_space = False
else:
limit = self.width-offset-1
this_line_was_broken_by_space = False
color = message.user.color if message.user else None color = message.user.color if message.user else None
if not first: if not first:
nick = None nick = None
@ -223,7 +233,10 @@ class TextWin(Win):
txt[:limit], message.color, txt[:limit], message.color,
offset) offset)
lines.append(l) lines.append(l)
txt = txt[limit:] if this_line_was_broken_by_space:
txt = txt[limit+1:] # jump the space at the start of the line
else:
txt = txt[limit:]
if txt.startswith('\n'): if txt.startswith('\n'):
txt = txt[1:] txt = txt[1:]
first = False first = False