diff --git a/jrnl/journals/Entry.py b/jrnl/journals/Entry.py index 907adb90..4b68529f 100644 --- a/jrnl/journals/Entry.py +++ b/jrnl/journals/Entry.py @@ -144,28 +144,17 @@ class Entry: body = highlight_tags_with_background_color( self, self.body.rstrip(" \n"), self.journal.config["colors"]["body"] ) - body_text = [ - colorize( - wrap_with_ansi_colors(line, columns, indent_text=indent), - self.journal.config["colors"]["body"], - ) - for line in body.rstrip(" \n").splitlines() - ] - # ansiwrap doesn't handle lines with only the "\n" character and some - # ANSI escapes properly, so we have this hack here to make sure the - # beginning of each line has the indent character and it's colored - # properly. textwrap doesn't have this issue, however, it doesn't wrap - # the strings properly as it counts ANSI escapes as literal characters. - # TL;DR: I'm sorry. - body = "\n".join( - [ + body = wrap_with_ansi_colors(body, columns - len(indent)) + if indent: + # Without explicitly colorizing the indent character, it will lose its + # color after a tag appears. + body = "\n".join( colorize(indent, self.journal.config["colors"]["body"]) + line - if not ansiwrap.strip_color(line).startswith(indent) - else line - for line in body_text - ] - ) + for line in body.splitlines() + ) + + body = colorize(body, self.journal.config["colors"]["body"]) else: title = ( date_str diff --git a/jrnl/output.py b/jrnl/output.py index 800b3e42..68ea4916 100644 --- a/jrnl/output.py +++ b/jrnl/output.py @@ -130,15 +130,10 @@ def format_msg_text(msg: Message) -> Text: return Text(text) -def wrap_with_ansi_colors( - text: str, width: int, indent_text: str = "", drop_whitespace: bool = True -) -> str: +def wrap_with_ansi_colors(text: str, width: int) -> str: richtext = Text.from_ansi(text, no_wrap=False, tab_size=None) - pre_indent_width = width - len(indent_text) - console = Console(width=pre_indent_width) + console = Console(width=width) with console.capture() as capture: console.print(richtext) - wrapped_text = capture.get() - - return "\n".join([indent_text + line for line in wrapped_text.splitlines()]) + return capture.get()