mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Colorize error and warning messages
This commit is contained in:
parent
00c836032d
commit
1a220243bc
5 changed files with 18 additions and 7 deletions
|
@ -13,6 +13,7 @@ from . import Journal
|
||||||
from . import util
|
from . import util
|
||||||
from . import install
|
from . import install
|
||||||
from . import plugins
|
from . import plugins
|
||||||
|
from .util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR
|
||||||
import jrnl
|
import jrnl
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
@ -252,7 +253,7 @@ def run(manual_args=None):
|
||||||
|
|
||||||
elif args.edit:
|
elif args.edit:
|
||||||
if not config['editor']:
|
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)
|
sys.exit(1)
|
||||||
other_entries = [e for e in old_entries if e not in journal.entries]
|
other_entries = [e for e in old_entries if e not in journal.entries]
|
||||||
# Edit
|
# Edit
|
||||||
|
|
|
@ -5,6 +5,7 @@ from __future__ import absolute_import, unicode_literals, print_function
|
||||||
from .text_exporter import TextExporter
|
from .text_exporter import TextExporter
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR
|
||||||
|
|
||||||
|
|
||||||
class MarkdownExporter(TextExporter):
|
class MarkdownExporter(TextExporter):
|
||||||
|
@ -49,7 +50,7 @@ class MarkdownExporter(TextExporter):
|
||||||
newbody = newbody + previous_line # add very last line
|
newbody = newbody + previous_line # add very last line
|
||||||
|
|
||||||
if warn_on_heading_level is True:
|
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(
|
return "{md} {date} {title} {body} {space}".format(
|
||||||
md=heading,
|
md=heading,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import codecs
|
||||||
from . import BaseExporter
|
from . import BaseExporter
|
||||||
from ..util import u, slugify
|
from ..util import u, slugify
|
||||||
import os
|
import os
|
||||||
|
from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR
|
||||||
|
|
||||||
|
|
||||||
class TextExporter(BaseExporter):
|
class TextExporter(BaseExporter):
|
||||||
|
@ -31,7 +32,7 @@ class TextExporter(BaseExporter):
|
||||||
f.write(cls.export_journal(journal))
|
f.write(cls.export_journal(journal))
|
||||||
return "[Journal exported to {0}]".format(path)
|
return "[Journal exported to {0}]".format(path)
|
||||||
except IOError as e:
|
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
|
@classmethod
|
||||||
def make_filename(cls, entry):
|
def make_filename(cls, entry):
|
||||||
|
@ -46,7 +47,7 @@ class TextExporter(BaseExporter):
|
||||||
with codecs.open(full_path, "w", "utf-8") as f:
|
with codecs.open(full_path, "w", "utf-8") as f:
|
||||||
f.write(cls.export_entry(entry))
|
f.write(cls.export_entry(entry))
|
||||||
except IOError as e:
|
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)
|
return "[Journal exported to {0}]".format(path)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -5,10 +5,11 @@ from __future__ import absolute_import, unicode_literals, print_function
|
||||||
from .text_exporter import TextExporter
|
from .text_exporter import TextExporter
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR
|
||||||
|
|
||||||
|
|
||||||
class YAMLExporter(TextExporter):
|
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"]
|
names = ["yaml"]
|
||||||
extension = "md"
|
extension = "md"
|
||||||
|
|
||||||
|
@ -56,11 +57,14 @@ class YAMLExporter(TextExporter):
|
||||||
newbody = newbody + previous_line # add very last line
|
newbody = newbody + previous_line # add very last line
|
||||||
|
|
||||||
if warn_on_heading_level is True:
|
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 = ''
|
dayone_attributes = ''
|
||||||
if hasattr(entry, "uuid"):
|
if hasattr(entry, "uuid"):
|
||||||
dayone_attributes += 'uuid: ' + entry.uuid + '\n'
|
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(
|
return "title: {title}\ndate: {date}\nstared: {stared}\ntags: {tags}\n{dayone} {body} {space}".format(
|
||||||
date = date_str,
|
date = date_str,
|
||||||
|
@ -75,5 +79,5 @@ class YAMLExporter(TextExporter):
|
||||||
@classmethod
|
@classmethod
|
||||||
def export_journal(cls, journal):
|
def export_journal(cls, journal):
|
||||||
"""Returns an error, as YAML export requires a directory as a target."""
|
"""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
|
return
|
||||||
|
|
|
@ -23,6 +23,10 @@ STDOUT = sys.stdout
|
||||||
TEST = False
|
TEST = False
|
||||||
__cached_tz = None
|
__cached_tz = None
|
||||||
|
|
||||||
|
WARNING_COLOR = "\033[33m"
|
||||||
|
ERROR_COLOR = "\033[31m"
|
||||||
|
RESET_COLOR = "\033[0m"
|
||||||
|
|
||||||
|
|
||||||
def getpass(prompt="Password: "):
|
def getpass(prompt="Password: "):
|
||||||
if not TEST:
|
if not TEST:
|
||||||
|
|
Loading…
Add table
Reference in a new issue