Prevent curses errors

This commit is contained in:
Yohann D'ANELLO 2021-01-09 20:38:13 +01:00
parent 2797b9ddc5
commit 4a79fcaabe
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 12 additions and 2 deletions

View File

@ -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: