Screen is resizable

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

View File

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