From 91ec39554b01dd9221b03e16217e4e7914392553 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Thu, 2 Jan 2014 18:25:24 -0700 Subject: [PATCH] Make colorama optional --- CHANGELOG.md | 2 +- docs/advanced.rst | 4 ++++ jrnl/Journal.py | 10 ++-------- jrnl/__init__.py | 4 ++-- jrnl/util.py | 6 ++++++ requirements.txt | 1 - setup.py | 1 - 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fe17b7f..874dde48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Changelog ### 1.7 (December 22, 2013) -* __1.7.5__ Return of colorama (for color on Windows), fixes editing (stops deleting entries instead of editing them), improves Windows documentation. +* __1.7.5__ Optional return of colorama (for color on Windows), fixes editing (stops deleting entries instead of editing them), improves Windows documentation. * __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. diff --git a/docs/advanced.rst b/docs/advanced.rst index 6fcafee4..a4beacf2 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -104,6 +104,10 @@ Windows Usage A couple of tips to get jrnl working better on Windows: +To get colored output on Windows, install ``colorama`` :: + + pip install colorama + The configuration file is typically found at ``C:\Users\[Your Username\.jrnl_conf``. This is just a text file and so can be edited in a text editor (but don't use Notepad, it will mess with the line endings). For editing entries, Notepad will technically work, but doesn't play nice with line endings. A good alternative is `Notepad++ `_. To set Notepad++ as your editor, edit the jrnl config file (``.jrnl_conf``) like this: diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 8da83dd3..531b0784 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -57,12 +57,6 @@ 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: @@ -174,11 +168,11 @@ class Journal(object): for tag in self.search_tags: tagre = re.compile(re.escape(tag), re.IGNORECASE) pp = re.sub(tagre, - lambda match: self._colorize(match.group(0)), + lambda match: util.colorize(match.group(0)), pp, re.UNICODE) else: pp = re.sub(r"(?u)([{tags}]\w+)".format(tags=self.config['tagsymbols']), - lambda match: self._colorize(match.group(0)), + lambda match: util.colorize(match.group(0)), pp) return pp diff --git a/jrnl/__init__.py b/jrnl/__init__.py index 50b30f18..c57606c0 100644 --- a/jrnl/__init__.py +++ b/jrnl/__init__.py @@ -7,10 +7,10 @@ jrnl is a simple journal application for your command line. """ __title__ = 'jrnl' -__version__ = '1.7.3' +__version__ = '1.7.5' __author__ = 'Manuel Ebert' __license__ = 'MIT License' -__copyright__ = 'Copyright 2013 Manuel Ebert' +__copyright__ = 'Copyright 2013-14 Manuel Ebert' from . import Journal from . import cli diff --git a/jrnl/util.py b/jrnl/util.py index 87271d28..6cf7fda1 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -139,3 +139,9 @@ 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""" + if os.name == "nt" and not colorama: + return string + else: + return u"\033[36m{}\033[39m".format(string) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c217b127..413a3844 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ 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 30b5a026..fafd0515 100644 --- a/setup.py +++ b/setup.py @@ -75,7 +75,6 @@ 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"