diff --git a/jrnl/cli.py b/jrnl/cli.py index 0313f8ae..5c4585ce 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -13,6 +13,7 @@ from . import Journal from . import util from . import install from . import plugins +from .util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR import jrnl import argparse import sys @@ -252,7 +253,7 @@ def run(manual_args=None): elif args.edit: if not config['editor']: - util.prompt("[{1}ERROR{2}: You need to specify an editor in {0} to use the --edit function.]".format(install.CONFIG_FILE_PATH, "\033[31m", "\033[0m")) + util.prompt("[{1}ERROR{2}: You need to specify an editor in {0} to use the --edit function.]".format(install.CONFIG_FILE_PATH, ERROR_COLOR, RESET_COLOR)) sys.exit(1) other_entries = [e for e in old_entries if e not in journal.entries] # Edit diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index 157e01b5..346a5a37 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, unicode_literals, print_function from .text_exporter import TextExporter import re import sys +from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR class MarkdownExporter(TextExporter): @@ -49,7 +50,7 @@ class MarkdownExporter(TextExporter): newbody = newbody + previous_line # add very last line if warn_on_heading_level is True: - print("{}WARNING{}: Headings increased past H6 on export - {} {}".format("\033[33m", "\033[0m", date_str, entry.title), file=sys.stderr) + print("{}WARNING{}: Headings increased past H6 on export - {} {}".format(WARNING_COLOR, RESET_COLOR, date_str, entry.title), file=sys.stderr) return "{md} {date} {title} {body} {space}".format( md=heading, diff --git a/jrnl/plugins/text_exporter.py b/jrnl/plugins/text_exporter.py index 042c66fd..6e550956 100644 --- a/jrnl/plugins/text_exporter.py +++ b/jrnl/plugins/text_exporter.py @@ -6,6 +6,7 @@ import codecs from . import BaseExporter from ..util import u, slugify import os +from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR class TextExporter(BaseExporter): @@ -31,7 +32,7 @@ class TextExporter(BaseExporter): f.write(cls.export_journal(journal)) return "[Journal exported to {0}]".format(path) except IOError as e: - return "[ERROR: {0} {1}]".format(e.filename, e.strerror) + return "[{2}ERROR{3}: {0} {1}]".format(e.filename, e.strerror, ERROR_COLOR, RESET_COLOR) @classmethod def make_filename(cls, entry): @@ -46,7 +47,7 @@ class TextExporter(BaseExporter): with codecs.open(full_path, "w", "utf-8") as f: f.write(cls.export_entry(entry)) except IOError as e: - return "[ERROR: {0} {1}]".format(e.filename, e.strerror) + return "[{2}ERROR{3}: {0} {1}]".format(e.filename, e.strerror, ERROR_COLOR, RESET_COLOR) return "[Journal exported to {0}]".format(path) @classmethod diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py index a777c722..1442adcc 100644 --- a/jrnl/plugins/yaml_exporter.py +++ b/jrnl/plugins/yaml_exporter.py @@ -5,10 +5,11 @@ from __future__ import absolute_import, unicode_literals, print_function from .text_exporter import TextExporter import re import sys +from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR class YAMLExporter(TextExporter): - """This Exporter can convert entries and journals into Markdown with YAML front matter.""" + """This Exporter can convert entries and journals into Markdown formatted text with YAML front matter.""" names = ["yaml"] extension = "md" @@ -56,11 +57,14 @@ class YAMLExporter(TextExporter): newbody = newbody + previous_line # add very last line if warn_on_heading_level is True: - print("{}WARNING{}: Headings increased past H6 on export - {} {}".format("\033[33m", "\033[0m", date_str, entry.title), file=sys.stderr) + print("{}WARNING{}: Headings increased past H6 on export - {} {}".format(WARNING_COLOR, RESET_COLOR, date_str, entry.title), file=sys.stderr) dayone_attributes = '' if hasattr(entry, "uuid"): dayone_attributes += 'uuid: ' + entry.uuid + '\n' + # TODO: copy over pictures, if present + # source directory is entry.journal.config['journal'] + # output directory is...? return "title: {title}\ndate: {date}\nstared: {stared}\ntags: {tags}\n{dayone} {body} {space}".format( date = date_str, @@ -75,5 +79,5 @@ class YAMLExporter(TextExporter): @classmethod def export_journal(cls, journal): """Returns an error, as YAML export requires a directory as a target.""" - print("{}ERROR{}: YAML export must be to individual files. Please specify a directory to export to.".format("\033[31m", "\033[0m", file=sys.stderr)) + print("{}ERROR{}: YAML export must be to individual files. Please specify a directory to export to.".format(ERROR_COLOR, RESET_COLOR), file=sys.stderr) return diff --git a/jrnl/util.py b/jrnl/util.py index e61d0139..a38f7e11 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -23,6 +23,10 @@ STDOUT = sys.stdout TEST = False __cached_tz = None +WARNING_COLOR = "\033[33m" +ERROR_COLOR = "\033[31m" +RESET_COLOR = "\033[0m" + def getpass(prompt="Password: "): if not TEST: