From b4a3aabad9afa41976985602f9e27242ea45ce5b Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 29 May 2020 11:26:53 +0200 Subject: [PATCH] Add quote_wrap option --- matrix/colors.py | 29 +++++++++++++++++++---------- matrix/config.py | 10 ++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/matrix/colors.py b/matrix/colors.py index 89e7654..f049ecb 100644 --- a/matrix/colors.py +++ b/matrix/colors.py @@ -62,14 +62,11 @@ class Formatted(object): # type: (List[FormattedString]) -> None self.substrings = substrings - @property - def textwrapper(self): - quote_pair = color_pair(G.CONFIG.color.quote_fg, - G.CONFIG.color.quote_bg) + def textwrapper(self, width, colors): return textwrap.TextWrapper( - width=67, - initial_indent="{}> ".format(W.color(quote_pair)), - subsequent_indent="{}> ".format(W.color(quote_pair)), + width=width, + initial_indent="{}> ".format(W.color(colors)), + subsequent_indent="{}> ".format(W.color(colors)), ) def is_formatted(self): @@ -356,9 +353,21 @@ class Formatted(object): elif name == "strikethrough": return string_strikethrough(string) elif name == "quote": - return self.textwrapper.fill( - W.string_remove_color(string.replace("\n", ""), "") - ) + quote_pair = color_pair(G.CONFIG.color.quote_fg, + G.CONFIG.color.quote_bg) + + if G.CONFIG.look.quote_wrap >= 0: + wrapper = self.textwrapper(G.CONFIG.look.quote_wrap, quote_pair) + return wrapper.fill( + W.string_remove_color(string.replace("\n", ""), "") + ) + else: + # Don't wrap, just add quote markers to all lines + return "{color_on}{text}{color_off}".format( + color_on=W.color(quote_pair), + text="> " + W.string_remove_color(string.replace("\n", "\n> "), ""), + color_off=W.color("resetcolor") + ) elif name == "code": code_color_pair = color_pair( G.CONFIG.color.untagged_code_fg, diff --git a/matrix/config.py b/matrix/config.py index f8dbc90..d4d4ed8 100644 --- a/matrix/config.py +++ b/matrix/config.py @@ -540,6 +540,16 @@ class MatrixConfig(WeechatConfig): ("Number of spaces to add as a margin around around a code " "block"), ), + Option( + "quote_wrap", + "integer", + "", + -1, + 1000, + "67", + ("After how many characters to soft-wrap lines in a quote " + "block (reply message). Set to -1 to disable soft-wrapping."), + ), Option( "human_buffer_names", "boolean",