diff --git a/squinnondation/squinnondation.py b/squinnondation/squinnondation.py index b1548a4..1360b49 100644 --- a/squinnondation/squinnondation.py +++ b/squinnondation/squinnondation.py @@ -427,62 +427,74 @@ class Squirrel(Hazelnut): return self.socket.recvfrom(1024) def print_markdown(self, pad: Any, y: int, x: int, msg: str, - bold: bool = False, italic: bool = False, underline: bool = False) -> int: + bold: bool = False, italic: bool = False, underline: bool = False, strike: bool = False) -> int: """ - Parse a markdown-formatted text and format the text as bold, italic or underlined text. + Parse a markdown-formatted text and format the text as bold, italic or text text. ***text***: bold, italic **text**: bold *text*: italic __text__: underline _text_: italic + ~~text~~: strikethrough """ underline_match = re.match("(.*)__(.*)__(.*)", msg) if underline_match: - before, underlined, after = underline_match.group(1), underline_match.group(2), underline_match.group(3) + before, text, after = underline_match.group(1), underline_match.group(2), underline_match.group(3) len_before = self.print_markdown(pad, y, x, before, bold, italic, underline) - len_mid = self.print_markdown(pad, y, x + len_before, underlined, bold, italic, not underline) + len_mid = self.print_markdown(pad, y, x + len_before, text, bold, italic, not underline) len_after = self.print_markdown(pad, y, x + len_before + len_mid, after, bold, italic, underline) return len_before + len_mid + len_after italic_match = re.match("(.*)_(.*)_(.*)", msg) if italic_match: - before, underlined, after = italic_match.group(1), italic_match.group(2), italic_match.group(3) + before, text, after = italic_match.group(1), italic_match.group(2), italic_match.group(3) len_before = self.print_markdown(pad, y, x, before, bold, italic, underline) - len_mid = self.print_markdown(pad, y, x + len_before, underlined, bold, not italic, underline) + len_mid = self.print_markdown(pad, y, x + len_before, text, bold, not italic, underline) len_after = self.print_markdown(pad, y, x + len_before + len_mid, after, bold, italic, underline) return len_before + len_mid + len_after bold_italic_match = re.match("(.*)\\*\\*\\*(.*)\\*\\*\\*(.*)", msg) if bold_italic_match: - before, underlined, after = bold_italic_match.group(1), bold_italic_match.group(2),\ + before, text, after = bold_italic_match.group(1), bold_italic_match.group(2),\ bold_italic_match.group(3) - len_before = self.print_markdown(pad, y, x, before, bold, italic, underline) - len_mid = self.print_markdown(pad, y, x + len_before, underlined, not bold, not italic, underline) - len_after = self.print_markdown(pad, y, x + len_before + len_mid, after, bold, italic, underline) + len_before = self.print_markdown(pad, y, x, before, bold, italic, underline, strike) + len_mid = self.print_markdown(pad, y, x + len_before, text, not bold, not italic, underline, strike) + len_after = self.print_markdown(pad, y, x + len_before + len_mid, after, bold, italic, underline, strike) return len_before + len_mid + len_after bold_match = re.match("(.*)\\*\\*(.*)\\*\\*(.*)", msg) if bold_match: - before, underlined, after = bold_match.group(1), bold_match.group(2), bold_match.group(3) - len_before = self.print_markdown(pad, y, x, before, bold, italic, underline) - len_mid = self.print_markdown(pad, y, x + len_before, underlined, not bold, italic, underline) - len_after = self.print_markdown(pad, y, x + len_before + len_mid, after, bold, italic, underline) + before, text, after = bold_match.group(1), bold_match.group(2), bold_match.group(3) + len_before = self.print_markdown(pad, y, x, before, bold, italic, underline, strike) + len_mid = self.print_markdown(pad, y, x + len_before, text, not bold, italic, underline, strike) + len_after = self.print_markdown(pad, y, x + len_before + len_mid, after, bold, italic, underline, strike) return len_before + len_mid + len_after italic_match = re.match("(.*)\\*(.*)\\*(.*)", msg) if italic_match: - before, underlined, after = italic_match.group(1), italic_match.group(2), italic_match.group(3) - len_before = self.print_markdown(pad, y, x, before, bold, italic, underline) - len_mid = self.print_markdown(pad, y, x + len_before, underlined, bold, not italic, underline) - len_after = self.print_markdown(pad, y, x + len_before + len_mid, after, bold, italic, underline) + before, text, after = italic_match.group(1), italic_match.group(2), italic_match.group(3) + len_before = self.print_markdown(pad, y, x, before, bold, italic, underline, strike) + len_mid = self.print_markdown(pad, y, x + len_before, text, bold, not italic, underline, strike) + len_after = self.print_markdown(pad, y, x + len_before + len_mid, after, bold, italic, underline, strike) + return len_before + len_mid + len_after + + strike_match = re.match("(.*)~~(.*)~~(.*)", msg) + if strike_match: + before, text, after = strike_match.group(1), strike_match.group(2), strike_match.group(3) + len_before = self.print_markdown(pad, y, x, before, bold, italic, underline, strike) + len_mid = self.print_markdown(pad, y, x + len_before, text, bold, italic, underline, not strike) + len_after = self.print_markdown(pad, y, x + len_before + len_mid, after, bold, italic, underline, strike) return len_before + len_mid + len_after attrs = 0 attrs |= curses.A_BOLD if bold else 0 attrs |= curses.A_ITALIC if italic else 0 attrs |= curses.A_UNDERLINE if underline else 0 + size = len(msg) + if strike: + msg = "".join(c + "\u0336" for c in msg) pad.addstr(y, x, msg, attrs) - return len(msg) + return size def refresh_history(self) -> None: """