aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2020-06-07 23:57:15 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2020-06-16 23:03:01 +0200
commite6446b84db52d9c5b6adf6c8869ab3d12e6f2ce4 (patch)
treef44f371c7c7fb5def5b6cf0cb528e8aa73c10e9f
parent7a4a95baafc78682288acaa1b4622d87eed1db3e (diff)
downloadwee-slack-e6446b84db52d9c5b6adf6c8869ab3d12e6f2ce4.tar.gz
Support colorizing attachment prefix or line
Thanks to @Informatic for the initial implementation of this in PR #426. I have seen that most attachment colors are without the leading #, but a few does include it, so we have to handle it. Fixes #424, closes #426
-rw-r--r--_pytest/conftest.py5
-rw-r--r--_pytest/test_unwrap_attachments.py20
-rw-r--r--docs/Commands.md2
-rw-r--r--docs/Options.md6
-rw-r--r--wee_slack.py18
5 files changed, 49 insertions, 2 deletions
diff --git a/_pytest/conftest.py b/_pytest/conftest.py
index ad0949e..1ad2310 100644
--- a/_pytest/conftest.py
+++ b/_pytest/conftest.py
@@ -117,6 +117,11 @@ class FakeWeechat():
return ""
def color(self, name):
return "<[color {}]>".format(name)
+ def info_get(self, info_name, arguments):
+ if info_name == "color_rgb2term":
+ return arguments
+ else:
+ return ""
def __getattr__(self, name):
def method(*args):
pass
diff --git a/_pytest/test_unwrap_attachments.py b/_pytest/test_unwrap_attachments.py
index ea3a35d..054c0af 100644
--- a/_pytest/test_unwrap_attachments.py
+++ b/_pytest/test_unwrap_attachments.py
@@ -267,6 +267,26 @@ import pytest
"| Second attachment text",
]),
},
+ {
+ 'input_message': {'attachments': [{
+ 'title': 'Title',
+ 'color': 'ff0000',
+ }]},
+ 'input_text_before': "",
+ 'output': "\n".join([
+ "<[color 16711680]>|<[color reset]> Title",
+ ]),
+ },
+ {
+ 'input_message': {'attachments': [{
+ 'title': 'Title',
+ 'color': '#ff0000',
+ }]},
+ 'input_text_before': "",
+ 'output': "\n".join([
+ "<[color 16711680]>|<[color reset]> Title",
+ ]),
+ },
))
def test_unwrap_attachments(case):
result = wee_slack.unwrap_attachments(
diff --git a/docs/Commands.md b/docs/Commands.md
index 34b2a1f..7088b97 100644
--- a/docs/Commands.md
+++ b/docs/Commands.md
@@ -61,7 +61,7 @@ Hide the current channel if it is marked as distracting.
### label
```
-/label <name>
+/label <name>|-unset
```
Rename a channel or thread buffer. Note that this only changes the short
diff --git a/docs/Options.md b/docs/Options.md
index 39ea4f5..112a4e1 100644
--- a/docs/Options.md
+++ b/docs/Options.md
@@ -76,6 +76,12 @@ slack` after changing it to take effect.
**Description:** Color to use for the typing notice.
+### colorize_attachments
+
+**Default:** `prefix`
+
+**Description:** Whether to colorize attachment lines. Values: "prefix": Only colorize the prefix, "all": Colorize the whole line, "none": Don't colorize.
+
### colorize_private_chats
**Default:** `false`
diff --git a/wee_slack.py b/wee_slack.py
index 8c9d358..1dc2bc9 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -3812,7 +3812,18 @@ def unwrap_attachments(message_json, text_before):
t.append(fallback)
if t:
lines = [line for part in t for line in part.strip().split("\n") if part]
- attachment_texts.extend("| {}".format(line) for line in lines)
+ prefix = '|'
+ line_color = None
+ color = attachment.get('color')
+ if color and config.colorize_attachments != "none":
+ weechat_color = w.info_get("color_rgb2term", str(int(color.lstrip("#"), 16)))
+ if config.colorize_attachments == "prefix":
+ prefix = colorize_string(weechat_color, prefix)
+ elif config.colorize_attachments == "all":
+ line_color = weechat_color
+ attachment_texts.extend(
+ colorize_string(line_color, "{} {}".format(prefix, line))
+ for line in lines)
return "\n".join(attachment_texts)
@@ -5230,6 +5241,10 @@ class PluginConfig(object):
'color_typing_notice': Setting(
default='yellow',
desc='Color to use for the typing notice.'),
+ 'colorize_attachments': Setting(
+ default='prefix',
+ desc='Whether to colorize attachment lines. Values: "prefix": Only colorize'
+ ' the prefix, "all": Colorize the whole line, "none": Don\'t colorize.'),
'colorize_private_chats': Setting(
default='false',
desc='Whether to use nick-colors in DM windows.'),
@@ -5435,6 +5450,7 @@ class PluginConfig(object):
get_color_reaction_suffix_added_by_you = get_string
get_color_thread_suffix = get_string
get_color_typing_notice = get_string
+ get_colorize_attachments = get_string
get_debug_level = get_int
get_external_user_suffix = get_string
get_files_download_location = get_string