From e6446b84db52d9c5b6adf6c8869ab3d12e6f2ce4 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sun, 7 Jun 2020 23:57:15 +0200 Subject: 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 --- _pytest/conftest.py | 5 +++++ _pytest/test_unwrap_attachments.py | 20 ++++++++++++++++++++ docs/Commands.md | 2 +- docs/Options.md | 6 ++++++ wee_slack.py | 18 +++++++++++++++++- 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 +/label |-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 -- cgit