summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-12-21 06:28:35 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-12-21 06:28:35 +0000
commitdc7910570c28a69902ef7e439cecabf8c80cef38 (patch)
tree0e9cd1ee9c39c4d7cb4243256240708f29ae37cb
parentac3e0f7099352254cba53d14d896dc05c9c55e6f (diff)
downloadpoezio-dc7910570c28a69902ef7e439cecabf8c80cef38.tar.gz
poezio-dc7910570c28a69902ef7e439cecabf8c80cef38.tar.bz2
poezio-dc7910570c28a69902ef7e439cecabf8c80cef38.tar.xz
poezio-dc7910570c28a69902ef7e439cecabf8c80cef38.zip
improve performances a little more. And avoid a very rare crash, too
-rw-r--r--src/windows.py36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/windows.py b/src/windows.py
index 9d38cd84..a2c7e72e 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -405,10 +405,11 @@ class TextWin(Win):
# on resize, we rebuild all the messages
def scroll_up(self, dist=14):
- # The pos can grow a lot over the top of the number of
- # available lines, it will be fixed on the next refresh of the
- # screen anyway
self.pos += dist
+ if self.pos + self.height > len(self.built_lines):
+ self.pos = len(self.built_lines) - self.height
+ if self.pos < 0:
+ self.pos = 0
def scroll_down(self, dist=14):
self.pos -= dist
@@ -502,31 +503,24 @@ class TextWin(Win):
"""
if self.height <= 0:
return
+ if self.pos != 0:
+ lines = self.built_lines[-self.height-self.pos:-self.pos]
+ else:
+ lines = self.built_lines[-self.height:]
+ self._win.move(0, 0)
with g_lock:
self._win.erase()
- # lines = self.build_lines_from_messages(room.messages)
- lines = self.built_lines
- if self.pos + self.height > len(lines):
- self.pos = len(lines) - self.height
- if self.pos < 0:
- self.pos = 0
- if self.pos != 0:
- lines = lines[-self.height-self.pos:-self.pos]
- else:
- lines = lines[-self.height:]
- y = 0
- for line in lines:
- self._win.move(y, 0)
- if line == None:
+ for y, line in enumerate(lines):
+ if line is None:
self.write_line_separator()
- y += 1
continue
- if line.time is not None:
+ if line.time:
self.write_time(line.time)
- if line.nickname is not None:
+ if line.nickname:
self.write_nickname(line.nickname, line.nickname_color)
self.write_text(y, line.text_offset, line.text, line.text_color, line.colorized)
- y += 1
+ if y != self.height - 1:
+ self.addstr('\n')
self._refresh()
def write_line_separator(self):