From 82d3c65d828777cf6b07a53d5b766c2f6c298427 Mon Sep 17 00:00:00 2001 From: Aaron Lichtman Date: Thu, 7 Nov 2019 04:27:31 +0100 Subject: [PATCH] Reformatting and clean up --- jrnl/Entry.py | 38 +++++++++++++++++++------------------- jrnl/util.py | 9 ++++----- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/jrnl/Entry.py b/jrnl/Entry.py index 14b61378..b23086e2 100755 --- a/jrnl/Entry.py +++ b/jrnl/Entry.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import re import ansiwrap from datetime import datetime -from .util import split_title, colorize, highlight_tags_maintain_background_color +from .util import split_title, colorize, highlight_tags_with_background_color class Entry: @@ -86,15 +86,15 @@ class Entry: if not short and self.journal.config['linewrap']: # Color date / title and bold title title = ansiwrap.fill(date_str + " " + - highlight_tags_maintain_background_color(self, - self.title, - self.journal.config['colors']['title'], - bold=True), + highlight_tags_with_background_color(self, + self.title, + self.journal.config['colors']['title'], + bold=True), self.journal.config['linewrap']) - body = highlight_tags_maintain_background_color(self, - self.body.rstrip(" \n"), - self.journal.config['colors']['body'], - bold=False) + body = highlight_tags_with_background_color(self, + self.body.rstrip(" \n"), + self.journal.config['colors']['body'], + bold=False) body_text = [colorize( ansiwrap.fill( line, @@ -106,8 +106,8 @@ class Entry: 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 + # 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. @@ -116,14 +116,14 @@ class Entry: else line for line in body_text]) else: - title = date_str + " " + highlight_tags_maintain_background_color(self, - self.title.rstrip("\n"), - self.journal.config['colors']['title'], - bold=True) - body = highlight_tags_maintain_background_color(self, - self.body.rstrip("\n "), - self.journal.config['colors']['body'], - bold=False) + title = date_str + " " + highlight_tags_with_background_color(self, + self.title.rstrip("\n"), + self.journal.config['colors']['title'], + bold=True) + body = highlight_tags_with_background_color(self, + self.body.rstrip("\n "), + self.journal.config['colors']['body'], + bold=False) # Suppress bodies that are just blanks and new lines. has_body = len(self.body) > 20 or not all(char in (" ", "\n") for char in self.body) diff --git a/jrnl/util.py b/jrnl/util.py index c9559e59..14de8dfc 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -212,7 +212,7 @@ def colorize(string, color, bold=False): return colorama.Style.BRIGHT + color_escape + string + colorama.Style.RESET_ALL -def highlight_tags_maintain_background_color(entry, text, color, bold=False): +def highlight_tags_with_background_color(entry, text, color, bold=False): """ Takes a string and colorizes the tags in it based upon the config value for color.tags, while colorizing the rest of the text based on `color`. @@ -233,17 +233,16 @@ def highlight_tags_maintain_background_color(entry, text, color, bold=False): else: search_texts = re.split(entry.tag_regex(config['tagsymbols']), text) - # TODO: Condense this all into a list comprehension pretty_printed_entries = [] for text in search_texts: - colorized_parts = [colorize(part.strip(), + colorized_parts = (colorize(part.strip(), color, bold) - if len(part) > 0 and part[0] not in config['tagsymbols'] + if part and part[0] not in config['tagsymbols'] else colorize(part.strip(), config['colors']['tags'], not bold) - for part in text.strip().split(" ")] + for part in text.strip().split(" ")) pretty_printed_entries.append(" ".join(colorized_parts)) return " ".join(pretty_printed_entries)