break line on spaces if possible. Fixed #1541

parent cf88579e
...@@ -210,11 +210,21 @@ class TextWin(Win): ...@@ -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): ...@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment