diff --git a/squinnondation/squinnondation.py b/squinnondation/squinnondation.py index 0f8bf9c..f468f6c 100644 --- a/squinnondation/squinnondation.py +++ b/squinnondation/squinnondation.py @@ -383,6 +383,9 @@ class Squirrel(Hazelnut): self.history = [] self.history_pad = curses.newpad(curses.LINES - 2, curses.COLS) self.input_pad = curses.newpad(1, curses.COLS) + curses.init_color(curses.COLOR_WHITE, 1000, 1000, 1000) + for i in range(curses.COLOR_BLACK + 1, curses.COLOR_WHITE): + curses.init_pair(i + 1, i, curses.COLOR_BLACK) self.hazelnuts = dict() self.history.append(f" Listening on {self.address}:{self.port}") @@ -434,12 +437,14 @@ class Squirrel(Hazelnut): match = re.match("<(.*)> (.*)", msg) nickname = match.group(1) msg = match.group(2) - self.history_pad.addstr(i, 0, "<") color_id = sum(ord(c) for c in nickname) % 6 + 1 - curses.init_pair(color_id + 1, color_id, curses.COLOR_BLACK) + 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), "> ") - self.history_pad.addstr(i, 3 + len(nickname), msg) + attrs = curses.color_pair(0) + if nickname == "system": + attrs |= curses.A_ITALIC + self.history_pad.addstr(i, 3 + len(nickname), msg, attrs) self.history_pad.refresh(0, 0, 0, 0, curses.LINES - 2, curses.COLS) def refresh_input(self) -> None: @@ -447,7 +452,10 @@ class Squirrel(Hazelnut): Redraw input line. Must not be called while the message is not sent. """ self.input_pad.erase() - self.input_pad.addstr(0, 0, f"<{self.nickname}> ") + color_id = sum(ord(c) for c in self.nickname) % 6 + 1 + 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), "> ") self.input_pad.refresh(0, 0, curses.LINES - 1, 0, curses.LINES - 1, curses.COLS - 1)