mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 13:08:31 +02:00
Properly colorize tags and print body
This commit is contained in:
parent
c3b18181d6
commit
68305350e4
2 changed files with 30 additions and 17 deletions
|
@ -95,15 +95,26 @@ class Entry:
|
||||||
self.body.rstrip(" \n"),
|
self.body.rstrip(" \n"),
|
||||||
self.journal.config['colors']['body'],
|
self.journal.config['colors']['body'],
|
||||||
bold=False)
|
bold=False)
|
||||||
body = "\n".join([
|
body_text = [colorize(
|
||||||
ansiwrap.fill(
|
ansiwrap.fill(
|
||||||
line,
|
line,
|
||||||
self.journal.config['linewrap'],
|
self.journal.config['linewrap'],
|
||||||
initial_indent=indent,
|
initial_indent=indent,
|
||||||
subsequent_indent=indent,
|
subsequent_indent=indent,
|
||||||
drop_whitespace=True) or indent
|
drop_whitespace=True),
|
||||||
for line in body.rstrip(" \n").splitlines()
|
self.journal.config['colors']['body']) or indent
|
||||||
])
|
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 nasty 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([colorize(indent, self.journal.config['colors']['body']) + line
|
||||||
|
if not ansiwrap.strip_color(line).startswith(indent)
|
||||||
|
else line
|
||||||
|
for line in body_text])
|
||||||
else:
|
else:
|
||||||
title = date_str + " " + highlight_tags_maintain_background_color(self,
|
title = date_str + " " + highlight_tags_maintain_background_color(self,
|
||||||
self.title.rstrip("\n"),
|
self.title.rstrip("\n"),
|
||||||
|
|
|
@ -233,17 +233,19 @@ def highlight_tags_maintain_background_color(entry, text, color, bold=False):
|
||||||
else:
|
else:
|
||||||
search_texts = re.split(entry.tag_regex(config['tagsymbols']), text)
|
search_texts = re.split(entry.tag_regex(config['tagsymbols']), text)
|
||||||
|
|
||||||
# TODO: Condense this all into a list comprehension once the broken regression test is fixed.
|
# TODO: Condense this all into a list comprehension
|
||||||
pretty_printed_entries = []
|
pretty_printed_entries = []
|
||||||
for text in search_texts:
|
for text in search_texts:
|
||||||
pretty_printed_entries.append(" ".join([colorize(part.strip(),
|
colorized_parts = [colorize(part.strip(),
|
||||||
color,
|
color,
|
||||||
bold)
|
bold)
|
||||||
if len(part) > 0 and part[0] not in config['tagsymbols']
|
if len(part) > 0 and part[0] not in config['tagsymbols']
|
||||||
else colorize(part.strip(),
|
else colorize(part.strip(),
|
||||||
config['colors']['tags'],
|
config['colors']['tags'],
|
||||||
not bold)
|
not bold)
|
||||||
for part in text.split()]))
|
for part in text.strip().split(" ")]
|
||||||
|
|
||||||
|
pretty_printed_entries.append(" ".join(colorized_parts))
|
||||||
return " ".join(pretty_printed_entries)
|
return " ".join(pretty_printed_entries)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue