The nickname of the current user is colored
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
parent
dfd2d319a8
commit
a1b93e851e
|
@ -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"<system> 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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue