mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 21:18: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 re
|
||||||
import ansiwrap
|
import ansiwrap
|
||||||
from datetime import datetime
|
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:
|
class Entry:
|
||||||
|
@ -86,15 +86,15 @@ class Entry:
|
||||||
if not short and self.journal.config['linewrap']:
|
if not short and self.journal.config['linewrap']:
|
||||||
# Color date / title and bold title
|
# Color date / title and bold title
|
||||||
title = ansiwrap.fill(date_str + " " +
|
title = ansiwrap.fill(date_str + " " +
|
||||||
highlight_tags_maintain_background_color(self,
|
highlight_tags_with_background_color(self,
|
||||||
self.title,
|
self.title,
|
||||||
self.journal.config['colors']['title'],
|
self.journal.config['colors']['title'],
|
||||||
bold=True),
|
bold=True),
|
||||||
self.journal.config['linewrap'])
|
self.journal.config['linewrap'])
|
||||||
body = highlight_tags_maintain_background_color(self,
|
body = highlight_tags_with_background_color(self,
|
||||||
self.body.rstrip(" \n"),
|
self.body.rstrip(" \n"),
|
||||||
self.journal.config['colors']['body'],
|
self.journal.config['colors']['body'],
|
||||||
bold=False)
|
bold=False)
|
||||||
body_text = [colorize(
|
body_text = [colorize(
|
||||||
ansiwrap.fill(
|
ansiwrap.fill(
|
||||||
line,
|
line,
|
||||||
|
@ -106,8 +106,8 @@ class Entry:
|
||||||
for line in body.rstrip(" \n").splitlines()]
|
for line in body.rstrip(" \n").splitlines()]
|
||||||
|
|
||||||
# ansiwrap doesn't handle lines with only the "\n" character and some
|
# 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
|
# 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
|
# beginning of each line has the indent character and it's colored
|
||||||
# properly. textwrap doesn't have this issue, however, it doesn't wrap
|
# properly. textwrap doesn't have this issue, however, it doesn't wrap
|
||||||
# the strings properly as it counts ANSI escapes as literal characters.
|
# the strings properly as it counts ANSI escapes as literal characters.
|
||||||
# TL;DR: I'm sorry.
|
# TL;DR: I'm sorry.
|
||||||
|
@ -116,14 +116,14 @@ class Entry:
|
||||||
else line
|
else line
|
||||||
for line in body_text])
|
for line in body_text])
|
||||||
else:
|
else:
|
||||||
title = date_str + " " + highlight_tags_maintain_background_color(self,
|
title = date_str + " " + highlight_tags_with_background_color(self,
|
||||||
self.title.rstrip("\n"),
|
self.title.rstrip("\n"),
|
||||||
self.journal.config['colors']['title'],
|
self.journal.config['colors']['title'],
|
||||||
bold=True)
|
bold=True)
|
||||||
body = highlight_tags_maintain_background_color(self,
|
body = highlight_tags_with_background_color(self,
|
||||||
self.body.rstrip("\n "),
|
self.body.rstrip("\n "),
|
||||||
self.journal.config['colors']['body'],
|
self.journal.config['colors']['body'],
|
||||||
bold=False)
|
bold=False)
|
||||||
|
|
||||||
# Suppress bodies that are just blanks and new lines.
|
# 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)
|
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
|
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
|
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`.
|
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:
|
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
|
|
||||||
pretty_printed_entries = []
|
pretty_printed_entries = []
|
||||||
for text in search_texts:
|
for text in search_texts:
|
||||||
colorized_parts = [colorize(part.strip(),
|
colorized_parts = (colorize(part.strip(),
|
||||||
color,
|
color,
|
||||||
bold)
|
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(),
|
else colorize(part.strip(),
|
||||||
config['colors']['tags'],
|
config['colors']['tags'],
|
||||||
not bold)
|
not bold)
|
||||||
for part in text.strip().split(" ")]
|
for part in text.strip().split(" "))
|
||||||
|
|
||||||
pretty_printed_entries.append(" ".join(colorized_parts))
|
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