From dc39cdab50f8fc2df9683bb26a3eafc3a3675f56 Mon Sep 17 00:00:00 2001 From: "louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13" Date: Wed, 30 Jun 2010 10:21:16 +0000 Subject: break line on spaces if possible. Fixed #1541 --- src/window.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/window.py b/src/window.py index c62dd869..87014cfd 100644 --- a/src/window.py +++ b/src/window.py @@ -210,11 +210,21 @@ class TextWin(Win): if nick: offset += len(nick) + 2 # + nick + spaces length first = True + this_line_was_broken_by_space = False while txt != '': if txt[:self.width-offset].find('\n') != -1: limit = txt[:self.width-offset].find('\n') 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 if not first: nick = None @@ -223,7 +233,10 @@ class TextWin(Win): txt[:limit], message.color, offset) 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'): txt = txt[1:] first = False -- cgit v1.2.3