From 166ca60568837db5330be6bfdd53a25d4dd9122e Mon Sep 17 00:00:00 2001 From: Suhas Date: Sat, 6 Feb 2021 18:56:27 -0500 Subject: [PATCH] Revert "make color handling more robust" This reverts commit ce930a27a13ccbe9d63ba7c56c29a3f0a09d3c98. --- jrnl/Entry.py | 32 +++++++------------------------- jrnl/color.py | 10 ++-------- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/jrnl/Entry.py b/jrnl/Entry.py index 22668c0d..67ba84f3 100755 --- a/jrnl/Entry.py +++ b/jrnl/Entry.py @@ -99,25 +99,9 @@ class Entry: else: indent = "" - if "colors" in self.journal.config and "date" in self.journal.config["colors"]: - date_color = self.journal.config["colors"]["date"] - else: - date_color = None - title_color = ( - self.journal.config["colors"]["title"] - if "colors" in self.journal.config - and "title" in self.journal.config["colors"] - else None - ) - body_color = ( - self.journal.config["colors"]["body"] - if "colors" in self.journal.config - and "title" in self.journal.config["colors"] - else None - ) date_str = colorize( self.date.strftime(self.journal.config["timeformat"]), - date_color, + self.journal.config["colors"]["date"], bold=True, ) @@ -129,13 +113,13 @@ class Entry: + highlight_tags_with_background_color( self, self.title, - title_color, + self.journal.config["colors"]["title"], is_title=True, ), self.journal.config["linewrap"], ) body = highlight_tags_with_background_color( - self, self.body.rstrip(" \n"), body_color + self, self.body.rstrip(" \n"), self.journal.config["colors"]["body"] ) body_text = [ colorize( @@ -146,7 +130,7 @@ class Entry: subsequent_indent=indent, drop_whitespace=True, ), - body_color, + self.journal.config["colors"]["body"], ) or indent for line in body.rstrip(" \n").splitlines() @@ -158,29 +142,27 @@ class Entry: # 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, body_color) + line + colorize(indent, self.journal.config["colors"]["body"]) + line if not ansiwrap.strip_color(line).startswith(indent) else line for line in body_text ] ) else: - title = ( date_str + " " + highlight_tags_with_background_color( self, self.title.rstrip("\n"), - title_color, + self.journal.config["colors"]["title"], is_title=True, ) ) body = highlight_tags_with_background_color( - self, self.body.rstrip("\n "), body_color + self, self.body.rstrip("\n "), self.journal.config["colors"]["body"] ) # Suppress bodies that are just blanks and new lines. diff --git a/jrnl/color.py b/jrnl/color.py index 28f36be1..3bdd4149 100644 --- a/jrnl/color.py +++ b/jrnl/color.py @@ -2,7 +2,6 @@ import re from string import punctuation from string import whitespace -from typing import Union import colorama @@ -16,16 +15,11 @@ ERROR_COLOR = colorama.Fore.RED RESET_COLOR = colorama.Fore.RESET -def colorize(string, color: Union[str, None], bold=False): +def colorize(string, color, bold=False): """Returns the string colored with colorama.Fore.color. If the color set by the user is "NONE" or the color doesn't exist in the colorama.Fore attributes, it returns the string without any modification.""" - - if color is not None: - color_escape = getattr(colorama.Fore, color.upper(), None) - else: - color_escape = None - + color_escape = getattr(colorama.Fore, color.upper(), None) if not color_escape: return string elif not bold: