mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
Reformatting and clean up
This commit is contained in:
parent
68305350e4
commit
82d3c65d82
2 changed files with 23 additions and 24 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue