From 39016f69800327a6f56c39605725d9cb095d218d Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 21 Dec 2020 16:04:04 +0100 Subject: [PATCH] Screen is resizable Signed-off-by: Yohann D'ANELLO --- squinnondation/squinnondation.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/squinnondation/squinnondation.py b/squinnondation/squinnondation.py index 11abf8a..c46acff 100644 --- a/squinnondation/squinnondation.py +++ b/squinnondation/squinnondation.py @@ -21,6 +21,7 @@ class Squinnondation: bind_port: int no_emoji: bool no_markdown: bool + screen: Any def parse_arguments(self) -> None: parser = ArgumentParser(description="MIRC client.") @@ -53,6 +54,7 @@ class Squinnondation: with TermManager() as term_manager: screen = term_manager.screen + instance.screen = screen screen.addstr(0, 0, "Enter your nickname: ") nickname = screen.getstr().decode("UTF-8") @@ -470,7 +472,7 @@ class Squirrel(Hazelnut): bold_italic_match = re.match("(.*)\\*\\*\\*(.*)\\*\\*\\*(.*)", msg) if bold_italic_match: before, text, after = bold_italic_match.group(1), bold_italic_match.group(2),\ - bold_italic_match.group(3) + bold_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, not bold, not italic, underline, strike) len_after = self.print_markdown(pad, y, x + len_before + len_mid, after, bold, italic, underline, strike) @@ -515,6 +517,12 @@ class Squirrel(Hazelnut): """ Rewrite the history of the messages. """ + y, x = self.squinnondation.screen.getmaxyx() + if curses.is_term_resized(curses.LINES, curses.COLS): + curses.resizeterm(y, x) + self.history_pad.resize(curses.LINES - 2, curses.COLS - 1) + self.input_pad.resize(1, curses.COLS - 1) + self.history_pad.erase() for i, msg in enumerate(self.history[max(0, len(self.history) - curses.LINES + 2):]): if not re.match("<.*> .*", msg): @@ -526,7 +534,6 @@ class Squirrel(Hazelnut): self.history_pad.addstr(i, 0, "<") self.history_pad.addstr(i, 1, nickname, curses.A_BOLD | curses.color_pair(color_id + 1)) self.history_pad.addstr(i, 1 + len(nickname), "> ") - attrs = curses.color_pair(0) self.print_markdown(self.history_pad, i, 3 + len(nickname), msg) self.history_pad.refresh(0, 0, 0, 0, curses.LINES - 2, curses.COLS)