From dfd2d319a8e2388e5fae9158ca3856d3997255de Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 21 Dec 2020 16:04:01 +0100 Subject: [PATCH] Add text colors Signed-off-by: Yohann D'ANELLO --- squinnondation/squinnondation.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/squinnondation/squinnondation.py b/squinnondation/squinnondation.py index 387fa6f..0f8bf9c 100644 --- a/squinnondation/squinnondation.py +++ b/squinnondation/squinnondation.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later import curses +import re import socket from argparse import ArgumentParser from enum import Enum @@ -428,7 +429,17 @@ class Squirrel(Hazelnut): """ self.history_pad.erase() for i, msg in enumerate(self.history[max(0, len(self.history) - curses.LINES + 2):]): - self.history_pad.addstr(i, 0, msg) + if not re.match("<.*> .*", msg): + msg = " " + msg + 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, 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) self.history_pad.refresh(0, 0, 0, 0, curses.LINES - 2, curses.COLS) def refresh_input(self) -> None: