Don't add stars to mark a text as bold or italic if non-markdown mode

Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
Yohann D'ANELLO 2020-12-21 16:04:15 +01:00
parent 9f070f594b
commit e44998028d
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 6 additions and 3 deletions

View File

@ -257,7 +257,7 @@ class Squirrel(Hazelnut):
Add a new system log message. Add a new system log message.
TODO: Configure logging levels to ignore some messages. 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, 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: bold: bool = False, italic: bool = False, underline: bool = False, strike: bool = False) -> int:
@ -370,8 +370,9 @@ class Squirrel(Hazelnut):
match = re.match("<(.*)> (.*)", msg) match = re.match("<(.*)> (.*)", msg)
nickname = match.group(1) nickname = match.group(1)
msg = match.group(2) msg = match.group(2)
full_msg = f"<{nickname}> {msg}"
color_id = sum(ord(c) for c in nickname) % 6 + 1 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)) 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) y_offset += true_width // (curses.COLS - 1)
self.history_pad.refresh(0, 0, 0, 0, curses.LINES - 2, curses.COLS) self.history_pad.refresh(0, 0, 0, 0, curses.LINES - 2, curses.COLS)

View File

@ -303,7 +303,9 @@ class WarningTLV(TLV):
self.message.encode("UTF-8")[:self.length] self.message.encode("UTF-8")[:self.length]
def handle(self, squirrel: Any, sender: Any) -> None: 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 @staticmethod
def construct(message: str) -> "WarningTLV": def construct(message: str) -> "WarningTLV":