Add add_system_message function

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

View File

@ -146,7 +146,7 @@ class Squinnondation:
curses.ungetch(c) curses.ungetch(c)
continue continue
elif len(key) > 1: elif len(key) > 1:
squirrel.add_message(f"<system> *unmanaged key press: {key}*") squirrel.add_system_message(f"unmanaged key press: {key}")
continue continue
elif key != "\n": elif key != "\n":
squirrel.input_buffer = squirrel.input_buffer[:squirrel.input_index] + key \ 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) curses.init_pair(i + 1, i, curses.COLOR_BLACK)
self.hazelnuts = dict() self.hazelnuts = dict()
self.add_message(f"<system> *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: def find_hazelnut(self, address: str, port: int) -> Hazelnut:
""" """
@ -538,6 +538,13 @@ class Squirrel(Hazelnut):
if self.last_line == len(self.history) - 2: if self.last_line == len(self.history) - 2:
self.last_line += 1 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"<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:
""" """
@ -650,6 +657,9 @@ class Squirrel(Hazelnut):
self.input_pad.addstr(0, 0, "<") 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, self.nickname, curses.A_BOLD | curses.color_pair(color_id + 1))
self.input_pad.addstr(0, 1 + len(self.nickname), "> ") 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) self.input_pad.addstr(0, 3 + len(self.nickname), self.input_buffer)
if not self.squinnondation.no_emoji: if not self.squinnondation.no_emoji:
self.input_pad.addstr(0, self.input_pad.getmaxyx()[1] - 3, "😀") self.input_pad.addstr(0, self.input_pad.getmaxyx()[1] - 3, "😀")
@ -705,7 +715,7 @@ class Worm(Thread):
try: try:
pkt, hazelnut = self.squirrel.receive_packet() pkt, hazelnut = self.squirrel.receive_packet()
except ValueError as error: except ValueError as error:
self.squirrel.add_message("<system> *An error occured while receiving a packet: {}*".format(error)) self.squirrel.add_system_message("An error occurred while receiving a packet: {}".format(error))
else: else:
self.squirrel.add_message(pkt.body[0].data.decode('UTF-8')) self.squirrel.add_message(pkt.body[0].data.decode('UTF-8'))
self.squirrel.refresh_history() self.squirrel.refresh_history()