mirror of
https://github.com/markqvist/NomadNet.git
synced 2026-10-26 19:01:44 -04:00
Added custom nick color theme option
This commit is contained in:
parent
503ea58b85
commit
f6158ba4df
2 changed files with 26 additions and 4 deletions
|
|
@ -157,6 +157,7 @@ class NomadNetworkApp:
|
|||
self.rrc_filter_loaded_history = True
|
||||
self.rrc_ephemeral_notices = 600
|
||||
self.rrc_nick_colors = True
|
||||
self.rrc_nick_colors_theme = None
|
||||
self.rrc_ui_justify_msgs = True
|
||||
self.rrc_ui_space_msgs = False
|
||||
self.rrc_ui_render_markdown = True
|
||||
|
|
@ -950,6 +951,20 @@ class NomadNetworkApp:
|
|||
except Exception: value = True
|
||||
self.rrc_nick_colors = value
|
||||
|
||||
if option == "nick_colors_theme":
|
||||
try:
|
||||
colors = self.config["rrc"].as_list(option)
|
||||
nick_colors_theme = []
|
||||
for c in colors:
|
||||
if len(c) == 6:
|
||||
try: bytes.fromhex(c)
|
||||
except: continue
|
||||
nick_colors_theme.append(c)
|
||||
self.rrc_nick_colors_theme = nick_colors_theme
|
||||
except Exception as e:
|
||||
RNS.log(f"Could not load custom nick colors theme: {e}", RNS.LOG_WARNING)
|
||||
self.rrc_nick_colors_theme = None
|
||||
|
||||
if option == "render_markdown":
|
||||
try: value = self.config["rrc"].as_bool(option)
|
||||
except Exception: value = True
|
||||
|
|
@ -1306,6 +1321,11 @@ nick_colors = yes
|
|||
justify_msgs = yes
|
||||
space_msgs = no
|
||||
|
||||
# You can configure your own color theme
|
||||
# for nick color assignment
|
||||
# nick_colors_theme = f68787, 00c394, d59e00, ...
|
||||
|
||||
|
||||
[node]
|
||||
|
||||
# Whether to enable node hosting
|
||||
|
|
|
|||
|
|
@ -909,12 +909,14 @@ class _ChatLinkDelegate:
|
|||
except Exception as e:
|
||||
RNS.log("Could not open page link: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
def get_nick_color(sender_hash, theme, shift=15):
|
||||
def get_nick_color(sender_hash, theme, app, shift=15):
|
||||
if app.rrc_nick_colors_theme: nick_colors = app.rrc_nick_colors_theme
|
||||
else: nick_colors = theme["nick_colors"]
|
||||
if type(sender_hash) == str:
|
||||
try: sender_hash = sender_hash.encode("utf-8")
|
||||
except: pass
|
||||
if not type(sender_hash) == bytes: return theme["nick_peer"]
|
||||
return theme["nick_colors"][(int.from_bytes(sender_hash)+shift)%len(theme["nick_colors"])]
|
||||
return nick_colors[(int.from_bytes(sender_hash)+shift)%len(nick_colors)]
|
||||
|
||||
room_nick_src_cache = {}
|
||||
mdc = MarkdownToMicron(max_width=80, syntax_highlighter=SyntaxHighlighter(), url_scope=None)
|
||||
|
|
@ -978,7 +980,7 @@ def _message_widget(app, hub, m, link_delegate=None):
|
|||
if ms.startswith("irc_mention"):
|
||||
if not app.rrc_nick_colors: message_body += f"`!`F{t['mention']}{mb}`f`!"
|
||||
else:
|
||||
try: message_body += f"`!`FT{get_nick_color(room_nick_src_cache[m.nick], t)}{mb}`f`!"
|
||||
try: message_body += f"`!`FT{get_nick_color(room_nick_src_cache[m.nick], t, app)}{mb}`f`!"
|
||||
except: message_body += f"`!`F{t['mention']}{mb}`f`!"
|
||||
|
||||
elif ms.startswith("link_"):
|
||||
|
|
@ -998,7 +1000,7 @@ def _message_widget(app, hub, m, link_delegate=None):
|
|||
mbo = mdc.format_block(strip_escaped_micron(mb)) if app.rrc_ui_render_markdown else strip_escaped_micron(mb)
|
||||
message_body += strip_non_formatting_tags(mbo)
|
||||
|
||||
if app.rrc_nick_colors: nick_attr = f"`FT{get_nick_color(m.src, t)}"
|
||||
if app.rrc_nick_colors: nick_attr = f"`FT{get_nick_color(m.src, t, app)}"
|
||||
else: nick_attr = f"`F{t['nick_self']}" if own else f"`F{t['nick_peer']}"
|
||||
irc_ts = f"`F{t['ts']}"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue