home · contact · privacy
Speed up Terminal.write_yx by avoiding unnecessary blessed.Terminal.length calls.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 1 Jun 2025 13:47:00 +0000 (15:47 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 1 Jun 2025 13:47:00 +0000 (15:47 +0200)
ircplom.py

index e49a68492de736b45841620cc1e23fd7774da893..fc20c1bbb4cddb3c39d05c50c0873ca74d79fa0f 100755 (executable)
@@ -101,7 +101,9 @@ class Terminal:
     def write_yx(self, offset: YX, msg: str) -> None:
         'Starting at offset, write line with msg, padded at end with spaces.'
         print(self._blessed.move_yx(offset.y, offset.x), end='')
-        len_with_offset = offset.x + self._blessed.length(msg)
+        # ._blessed.length can slow down things notably, only use where needed
+        len_with_offset = offset.x + (len(msg) if msg.isascii()
+                                      else self._blessed.length(msg))
         if len_with_offset > self.size.x:
             print(self._blessed.truncate(msg, self.size.x - offset.x), end='')
         else:
@@ -211,7 +213,7 @@ class IrcMessage:
         self.tags: dict[str, str] = tags or {}
 
     def __str__(self) -> str:
-        return f'[{self.tags}[{self.source}[{self.verb}]]][{self.parameters}]'
+        return f'[{self.tags}[{self.source}][{self.verb}]]][{self.parameters}]'
 
     @classmethod
     def from_raw(cls, raw_msg: str) -> Self: