From e44998028d6f8ffd798d1b467f8d2610e41ce44a Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 21 Dec 2020 16:04:15 +0100 Subject: [PATCH] Don't add stars to mark a text as bold or italic if non-markdown mode Signed-off-by: Yohann D'ANELLO --- squinnondation/hazel.py | 5 +++-- squinnondation/messages.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/squinnondation/hazel.py b/squinnondation/hazel.py index a8c07f4..2c830cf 100644 --- a/squinnondation/hazel.py +++ b/squinnondation/hazel.py @@ -257,7 +257,7 @@ class Squirrel(Hazelnut): Add a new system log message. TODO: Configure logging levels to ignore some messages. """ - return self.add_message(f"system: *{msg}*") + return self.add_message(f"system: *{msg}*" if not self.squinnondation.no_markdown else f"system: {msg}") def print_markdown(self, pad: Any, y: int, x: int, msg: str, bold: bool = False, italic: bool = False, underline: bool = False, strike: bool = False) -> int: @@ -370,8 +370,9 @@ class Squirrel(Hazelnut): match = re.match("<(.*)> (.*)", msg) nickname = match.group(1) msg = match.group(2) + full_msg = f"<{nickname}> {msg}" color_id = sum(ord(c) for c in nickname) % 6 + 1 - true_width = self.print_markdown(self.history_pad, i + y_offset, 0, f"<**{nickname}**> {msg}") + true_width = self.print_markdown(self.history_pad, i + y_offset, 0, full_msg) self.history_pad.addstr(i + y_offset, 1, nickname, curses.A_BOLD | curses.color_pair(color_id + 1)) y_offset += true_width // (curses.COLS - 1) self.history_pad.refresh(0, 0, 0, 0, curses.LINES - 2, curses.COLS) diff --git a/squinnondation/messages.py b/squinnondation/messages.py index fd9d672..8e49f85 100644 --- a/squinnondation/messages.py +++ b/squinnondation/messages.py @@ -303,7 +303,9 @@ class WarningTLV(TLV): self.message.encode("UTF-8")[:self.length] def handle(self, squirrel: Any, sender: Any) -> None: - squirrel.add_message(f"warning: *A client warned you: {self.message}*") + squirrel.add_message(f"warning: *A client warned you: {self.message}*" + if not squirrel.squinnondation.no_markdown else + f"warning: A client warned you: {self.message}") @staticmethod def construct(message: str) -> "WarningTLV":