Add text colors

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

View File

@ -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 = "<unknown> " + 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: