aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorbemoody <bemoody@users.noreply.github.com>2021-11-16 13:08:33 -0500
committerGitHub <noreply@github.com>2021-11-16 19:08:33 +0100
commit16ccb4fe4df80061abba94efeda761bc6b3a665b (patch)
tree62c3723f2c00cbac414eca569224d1e479ff1837 /wee_slack.py
parent3dce003dbceccbc1fb0bd54ea687d786fe724f63 (diff)
downloadwee-slack-16ccb4fe4df80061abba94efeda761bc6b3a665b.tar.gz
Fix alignment of multiline messages with non-ASCII prefix. (#854)
On Python 2, weechat.string_remove_color doesn't work for Unicode strings containing non-ASCII characters. The string must be converted to bytes using encode_to_utf8. Furthermore, the length of a non-ASCII string (either in bytes or codepoints) isn't the same as the width of the string on screen. To accurately calculate the width, when the string might contain combining or double-width characters, use weechat.strlen_screen. Co-authored-by: Benjamin Moody <benjaminmoody@gmail.com>
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 13eac0a..8eea38e 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -263,7 +263,8 @@ class WeechatWrapper(object):
# number of spaces, so it aligns correctly.
def prnt_date_tags(self, buffer, date, tags, message):
prefix, _, _ = message.partition("\t")
- prefix_spaces = " " * len(weechat.string_remove_color(prefix, ""))
+ prefix = weechat.string_remove_color(encode_to_utf8(prefix), "")
+ prefix_spaces = " " * weechat.strlen_screen(prefix)
message = message.replace("\n", "\n{}\t".format(prefix_spaces))
return self.wrap_for_utf8(self.wrapped_class.prnt_date_tags)(
buffer, date, tags, message