From 4a79fcaabeaf090fe6d4e1a8c8dcd418dfc57558 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 9 Jan 2021 20:38:13 +0100 Subject: [PATCH] Prevent curses errors --- squinnondation/peers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/squinnondation/peers.py b/squinnondation/peers.py index cea8ff1..ed4fdee 100644 --- a/squinnondation/peers.py +++ b/squinnondation/peers.py @@ -715,13 +715,19 @@ class User(Peer): _text_: italic ~~text~~: strikethrough """ + msg = msg.replace("\0", "") + # Replace :emoji_name: by the good emoji if not self.squinnondation.no_emoji: import emoji msg = emoji.emojize(msg, use_aliases=True) if self.squinnondation.no_markdown: - pad.addstr(y, x, msg) + try: + pad.addstr(y, x, msg) + except curses.error: + # Should not happen + pass return len(msg) underline_match = re.match("(.*)__(.*)__(.*)", msg) @@ -788,7 +794,11 @@ class User(Peer): space_left_on_line = (curses.COLS - 2) - (x % (curses.COLS - 1)) msg = msg[:space_left_on_line + max(0, (curses.COLS - 1) * (remaining_lines - 1))] if msg: - pad.addstr(y + x // (curses.COLS - 1), x % (curses.COLS - 1), msg, attrs) + try: + pad.addstr(y + x // (curses.COLS - 1), x % (curses.COLS - 1), msg, attrs) + except curses.error: + # Should not happen + pass return size def refresh_history(self) -> None: