From eeff80a85f919cce770e821873de3aadaa963d9a Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 21 Dec 2020 16:04:08 +0100 Subject: [PATCH] Add add_system_message function Signed-off-by: Yohann D'ANELLO --- squinnondation/squinnondation.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/squinnondation/squinnondation.py b/squinnondation/squinnondation.py index 7a0ce5e..1eb5d65 100644 --- a/squinnondation/squinnondation.py +++ b/squinnondation/squinnondation.py @@ -146,7 +146,7 @@ class Squinnondation: curses.ungetch(c) continue elif len(key) > 1: - squirrel.add_message(f" *unmanaged key press: {key}*") + squirrel.add_system_message(f"unmanaged key press: {key}") continue elif key != "\n": squirrel.input_buffer = squirrel.input_buffer[:squirrel.input_index] + key \ @@ -492,7 +492,7 @@ class Squirrel(Hazelnut): curses.init_pair(i + 1, i, curses.COLOR_BLACK) self.hazelnuts = dict() - self.add_message(f" *Listening on {self.address}:{self.port}*") + self.add_system_message(f"Listening on {self.address}:{self.port}") def find_hazelnut(self, address: str, port: int) -> Hazelnut: """ @@ -538,6 +538,13 @@ class Squirrel(Hazelnut): if self.last_line == len(self.history) - 2: self.last_line += 1 + def add_system_message(self, msg: str) -> None: + """ + Add a new system log message. + TODO: Configure logging levels to ignore some messages. + """ + return self.add_message(f" *{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: """ @@ -650,6 +657,9 @@ class Squirrel(Hazelnut): self.input_pad.addstr(0, 0, "<") self.input_pad.addstr(0, 1, self.nickname, curses.A_BOLD | curses.color_pair(color_id + 1)) self.input_pad.addstr(0, 1 + len(self.nickname), "> ") + msg = self.input_buffer + if len(msg) + len(self.nickname) + 3 >= curses.COLS: + msg = "" self.input_pad.addstr(0, 3 + len(self.nickname), self.input_buffer) if not self.squinnondation.no_emoji: self.input_pad.addstr(0, self.input_pad.getmaxyx()[1] - 3, "😀") @@ -705,7 +715,7 @@ class Worm(Thread): try: pkt, hazelnut = self.squirrel.receive_packet() except ValueError as error: - self.squirrel.add_message(" *An error occured while receiving a packet: {}*".format(error)) + self.squirrel.add_system_message("An error occurred while receiving a packet: {}".format(error)) else: self.squirrel.add_message(pkt.body[0].data.decode('UTF-8')) self.squirrel.refresh_history()