Make nick prefix (&, @, +) colour configurable.

This commit is contained in:
Denis Kasak 2020-06-07 15:05:50 +02:00
parent 72b0cd959b
commit 71b7f79317
2 changed files with 50 additions and 11 deletions

View file

@ -468,7 +468,6 @@ class WeechatChannelBuffer(object):
own_lines = W.hdata_pointer(self._hdata, self._ptr, "own_lines")
return W.hdata_integer(W.hdata_get("lines"), own_lines, "lines_count")
@property
def lines(self):
own_lines = W.hdata_pointer(self._hdata, self._ptr, "own_lines")
@ -675,17 +674,8 @@ class WeechatChannelBuffer(object):
@staticmethod
def _get_prefix_color(prefix):
# type: (str) -> str
# TODO make this configurable
color = ""
if prefix == "&":
color = "lightgreen"
elif prefix == "@":
color = "lightgreen"
elif prefix == "+":
color = "yellow"
return color
return G.CONFIG.color.nick_prefixes.get(prefix, "")
def _add_user_to_nicklist(self, user):
# type: (WeechatUser) -> None

View file

@ -233,6 +233,40 @@ def logbook_category(value):
return "all"
def parse_nick_prefix_colors(value):
"""Parses the nick prefix color setting string
("admin=COLOR1;mod=COLOR2;power=COLOR3") into a prefix -> color dict."""
def key_to_prefix(key):
if key == "admin":
return "&"
elif key == "mod":
return "@"
elif key == "power":
return "+"
else:
return ""
prefix_colors = {
"&": "lightgreen",
"@": "lightgreen",
"+": "yellow",
}
for setting in value.split(";"):
# skip malformed settings
if "=" not in setting:
continue
key, color = setting.split("=")
prefix = key_to_prefix(key)
if prefix:
prefix_colors[prefix] = color
return prefix_colors
def eval_cast(string):
"""A function that passes a string to weechat which evaluates it using its
expression evaluation syntax.
@ -818,6 +852,21 @@ class MatrixConfig(WeechatConfig):
"default",
"Background counterpart of untagged_code_fg",
),
Option(
"nick_prefixes",
"string",
"",
0,
0,
"admin=lightgreen;mod=lightgreen;power=yellow",
('Colors for nick prefixes indicating power level. '
'Format is "admin:color1;mod:color2;power:color3", '
'where "admin" stands for admins (power level = 100), '
'"mod" stands for moderators (power level >= 50) and '
'"power" for any other power user (power level > 0). '
'Requires restart to apply changes.'),
parse_nick_prefix_colors,
),
]
sections = [