Reformatting and clean up

This commit is contained in:
Aaron Lichtman 2019-11-07 04:27:31 +01:00
parent 68305350e4
commit 82d3c65d82
No known key found for this signature in database
GPG key ID: 22368077DE9F9903
2 changed files with 23 additions and 24 deletions

View file

@ -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,12 +86,12 @@ 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,
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,
body = highlight_tags_with_background_color(self,
self.body.rstrip(" \n"),
self.journal.config['colors']['body'],
bold=False)
@ -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,11 +116,11 @@ class Entry:
else line
for line in body_text])
else:
title = date_str + " " + highlight_tags_maintain_background_color(self,
title = date_str + " " + highlight_tags_with_background_color(self,
self.title.rstrip("\n"),
self.journal.config['colors']['title'],
bold=True)
body = highlight_tags_maintain_background_color(self,
body = highlight_tags_with_background_color(self,
self.body.rstrip("\n "),
self.journal.config['colors']['body'],
bold=False)

View file

@ -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)