diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d26aac0..e644f568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,6 @@ Changelog ### 1.7 (December 22, 2013) -* __1.7.4__ Gets rid of colorama. * __1.7.3__ Touches temporary files before opening them to allow more external editors. * __1.7.2__ Dateutil added to requirements. * __1.7.1__ Fixes issues with parsing time information in entries. diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 0fa9eada..8da83dd3 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -21,6 +21,11 @@ try: except ImportError: crypto_installed = False import hashlib +try: + import colorama + colorama.init() +except ImportError: + colorama = None import plistlib import pytz import uuid @@ -52,6 +57,12 @@ class Journal(object): """Returns the number of entries""" return len(self.entries) + def _colorize(self, string): + if colorama: + return colorama.Fore.CYAN + string + colorama.Fore.RESET + else: + return string + def _decrypt(self, cipher): """Decrypts a cipher string using self.key as the key and the first 16 byte of the cipher as the IV""" if not crypto_installed: @@ -163,11 +174,11 @@ class Journal(object): for tag in self.search_tags: tagre = re.compile(re.escape(tag), re.IGNORECASE) pp = re.sub(tagre, - lambda match: util.colorize(match.group(0)), + lambda match: self._colorize(match.group(0)), pp, re.UNICODE) else: pp = re.sub(r"(?u)([{tags}]\w+)".format(tags=self.config['tagsymbols']), - lambda match: util.colorize(match.group(0)), + lambda match: self._colorize(match.group(0)), pp) return pp diff --git a/jrnl/__init__.py b/jrnl/__init__.py index 33c20aa5..50b30f18 100644 --- a/jrnl/__init__.py +++ b/jrnl/__init__.py @@ -7,7 +7,7 @@ jrnl is a simple journal application for your command line. """ __title__ = 'jrnl' -__version__ = '1.7.4' +__version__ = '1.7.3' __author__ = 'Manuel Ebert' __license__ = 'MIT License' __copyright__ = 'Copyright 2013 Manuel Ebert' diff --git a/jrnl/install.py b/jrnl/install.py index 3240a206..7a6fa5c4 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -82,6 +82,11 @@ def install_jrnl(config_path='~/.jrnl_config'): password = None print("PyCrypto not found. To encrypt your journal, install the PyCrypto package from http://www.pycrypto.org or with 'pip install pycrypto' and run 'jrnl --encrypt'. For now, your journal will be stored in plain text.") + # Use highlighting: + if not module_exists("colorama"): + print("colorama not found. To turn on highlighting, install colorama and set highlight to true in your .jrnl_conf.") + default_config['highlight'] = False + open(default_config['journals']['default'], 'a').close() # Touch to make sure it's there # Write config to ~/.jrnl_conf diff --git a/jrnl/util.py b/jrnl/util.py index 102433c7..504be650 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -139,7 +139,3 @@ def get_text_from_editor(config, template=""): prompt('[Nothing saved to file]') return raw -def colorize(string): - """Returns the string wrapped in cyan ANSI escape""" - return u"\033[36m{}\033[39m".format(string) - diff --git a/requirements.txt b/requirements.txt index 413a3844..c217b127 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ parsedatetime >= 1.1.2 pytz >= 2013b +colorama >= 0.2.5 pycrypto >= 2.6 argparse==1.2.1 tzlocal == 1.0 diff --git a/setup.py b/setup.py index fafd0515..30b5a026 100644 --- a/setup.py +++ b/setup.py @@ -75,6 +75,7 @@ setup( "slugify>=0.0.1", "keyring>=3.3", "python-dateutil>=2.2" + "colorama>=0.2.5", ] + [p for p, cond in conditional_dependencies.items() if cond], extras_require = { "encrypted": "pycrypto>=2.6"