mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 03:43:19 +00:00
Use 16 colors by default to color users
This commit is contained in:
parent
ebb251cb4d
commit
10b2778309
4 changed files with 14 additions and 9 deletions
12
README.md
12
README.md
|
@ -143,10 +143,14 @@ MSG_FLAGS = {
|
|||
# use this app to open url when there are multiple
|
||||
URL_VIEW = 'urlview'
|
||||
|
||||
# Specifies range of colors to use for drawing different users
|
||||
# - 1, 8, 16, 256: range of colors to use
|
||||
# 233 is recommended and default, because it excludes gray
|
||||
USERS_COLORS = tuple(range(233))
|
||||
# Specifies range of colors to use for drawing users with
|
||||
# different colors
|
||||
# this one uses base 16 colors which should look good by default
|
||||
USERS_COLORS = tuple(range(2, 16))
|
||||
|
||||
# to use 256 colors, set range appropriately
|
||||
# though 233 looks better, because last colors are black and gray
|
||||
# USERS_COLORS = tuple(range(233))
|
||||
|
||||
# to make one color for all users
|
||||
# USERS_COLORS = (4,)
|
||||
|
|
|
@ -67,7 +67,8 @@ ICON_PATH = os.path.join(os.path.dirname(__file__), "resources", "tg.png")
|
|||
|
||||
URL_VIEW = "urlview"
|
||||
|
||||
USERS_COLORS = tuple(range(233))
|
||||
USERS_COLORS = tuple(range(2, 16))
|
||||
|
||||
|
||||
if os.path.isfile(CONFIG_FILE):
|
||||
config_params = runpy.run_path(CONFIG_FILE)
|
||||
|
|
|
@ -257,7 +257,7 @@ def pretty_ts(ts: int) -> str:
|
|||
|
||||
|
||||
@lru_cache(maxsize=256)
|
||||
def get_color_by_user(user: str) -> int:
|
||||
def get_color_by_str(user: str) -> int:
|
||||
index = int(hashlib.sha1(user.encode()).hexdigest(), 16) % len(
|
||||
config.USERS_COLORS
|
||||
)
|
||||
|
|
|
@ -18,7 +18,7 @@ from tg.colors import (
|
|||
from tg.models import Model
|
||||
from tg.msg import MsgProxy
|
||||
from tg.tdlib import ChatType
|
||||
from tg.utils import emoji_pattern, get_color_by_user, num, truncate_to_len
|
||||
from tg.utils import emoji_pattern, get_color_by_str, num, truncate_to_len
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -166,7 +166,7 @@ class ChatView:
|
|||
) -> Tuple[int, ...]:
|
||||
attrs = (
|
||||
get_color(cyan, -1),
|
||||
get_color(get_color_by_user(title), -1),
|
||||
get_color(get_color_by_str(title), -1),
|
||||
get_color(blue, -1),
|
||||
self._msg_color(is_selected),
|
||||
)
|
||||
|
@ -527,7 +527,7 @@ class MsgView:
|
|||
def _msg_attributes(self, is_selected: bool, user: str) -> Tuple[int, ...]:
|
||||
attrs = (
|
||||
get_color(cyan, -1),
|
||||
get_color(get_color_by_user(user), -1),
|
||||
get_color(get_color_by_str(user), -1),
|
||||
get_color(yellow, -1),
|
||||
get_color(white, -1),
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue