Add add_system_message function
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
parent
2630137019
commit
eeff80a85f
|
@ -146,7 +146,7 @@ class Squinnondation:
|
|||
curses.ungetch(c)
|
||||
continue
|
||||
elif len(key) > 1:
|
||||
squirrel.add_message(f"<system> *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"<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:
|
||||
"""
|
||||
|
@ -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"<system> *{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("<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:
|
||||
self.squirrel.add_message(pkt.body[0].data.decode('UTF-8'))
|
||||
self.squirrel.refresh_history()
|
||||
|
|
Loading…
Reference in New Issue