Skip to content

Commit

Permalink
Patch to add emoji support and fix username alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
iiPythonx committed Jan 24, 2024
1 parent d28a659 commit d8329b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion nightwatch/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.0"
__version__ = "0.5.1"
11 changes: 8 additions & 3 deletions nightwatch/client/extra/ui.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Copyright (c) 2024 iiPython

# Modules
import os
import shlex
from typing import Tuple
from datetime import datetime
from types import FunctionType

import urwid
from emoji import emojize

from .commands import commands
from .wswrap import ORJSONWebSocket
Expand Down Expand Up @@ -45,6 +47,9 @@ def __init__(self, websocket: ORJSONWebSocket) -> None:
command = command(self, self.add_message)
self.commands[command.name] = command

def len(self, text: str) -> int:
return int(len(text.encode(encoding = "utf_16_le")) / 2)

def send_message(self, text: str) -> None:
if text[0] == "/":
splices = shlex.split(text)
Expand All @@ -58,15 +63,15 @@ def send_message(self, text: str) -> None:
self.websocket.send({"type": "message", "text": text})

def construct_message(self, author: str, content: str, user_color: str = "gray") -> None:
visible_author = author if author != self.last_author else " " * len(author)
visible_author = author if author != self.last_author else " " * self.len(author)
now, time_string = datetime.now(), ""
if (author != self.last_author) or ((now - self.last_time).total_seconds() > 300):
time_string = now.strftime("%I:%M %p") + " " # Right padding for the scrollbar
time_string = now.strftime("%I:%M %p") + " "

self.pile.contents.append((urwid.Columns([
(len(visible_author), urwid.Text((user_color, visible_author))),
(3, urwid.Text(("sep", " | "))),
("weight", 4, urwid.Text(content)),
(os.get_terminal_size()[0] - len(time_string) - self.len(visible_author) - 8, urwid.Text(emojize(content, language = "alias"))),
(len(time_string) + 2, urwid.Text(("time", time_string), align = "right")) # +2 adds left padding
]), self.pile.options()))
self.last_author, self.last_time = author, now
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ dependencies = [
"websockets",
"orjson",
"urwid",
"nanoid"
"nanoid",
"emoji"
]

[project.optional-dependencies]
Expand Down

0 comments on commit d8329b7

Please sign in to comment.