From 419b2cb1a87068d5715c33f668b0cedb86235a66 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Thu, 2 Jan 2014 17:05:00 -0700 Subject: [PATCH 1/8] Revert "Gets rid of colorama" This reverts commit fcd8c4d214e1a8b4111eeaa8cbcec46bb9a2efe9. We need colorama for Windows. Conflicts: setup.py --- CHANGELOG.md | 1 - jrnl/Journal.py | 15 +++++++++++++-- jrnl/__init__.py | 2 +- jrnl/install.py | 5 +++++ jrnl/util.py | 4 ---- requirements.txt | 1 + setup.py | 1 + 7 files changed, 21 insertions(+), 8 deletions(-) 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" From dd58becad2a235f0c59b82c16009550291dffa63 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Thu, 2 Jan 2014 17:38:54 -0700 Subject: [PATCH 2/8] Make editing work the deleted lines were wiping the temp file, and thus the entry you were trying to edit --- jrnl/util.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/jrnl/util.py b/jrnl/util.py index 504be650..7191cb69 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -129,8 +129,6 @@ def get_text_from_editor(config, template=""): if template: with codecs.open(tmpfile, 'w', "utf-8") as f: f.write(template) - with open(tmpfile, 'w'): - pass subprocess.call(config['editor'].split() + [tmpfile]) with codecs.open(tmpfile, "r", "utf-8") as f: raw = f.read() From 3fadd6e933d78fd7283565445d66f7c644607e22 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Thu, 2 Jan 2014 17:58:49 -0700 Subject: [PATCH 3/8] Windows documentation --- docs/advanced.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/advanced.rst b/docs/advanced.rst index b00c4525..6fcafee4 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -99,3 +99,26 @@ Your ``default`` and your ``food`` journals won't be encrypted, however your ``w Changing ``encrypt`` to a different value will not encrypt or decrypt your journal file, it merely says whether or not your journal `is` encrypted. Hence manually changing this option will most likely result in your journal file being impossible to load. +Windows Usage +------------- + +A couple of tips to get jrnl working better on Windows: + +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: + +.. code-block:: javascript + + { + ... + "editor": "C:\\Program Files (x86)\\Notepad++\\notepad++.exe -multiInst", + } + +The double backslashes are needed so jrnl can read the file path correctly. The ``-multiInst`` option will cause jrnl to open its own Notepad++ windows. When you're done editing an entry in Notepad++, save the file and close the Notepad++ window for jrnl to know you're done editing and record your changes. + +Known Issues +~~~~~~~~~~~~ + +- The Windows shell prior to Windows 7 has issues with unicode encoding. If you want to use non-ascii characters, change the codepage with ``chcp 1252`` before using `jrnl` (Thanks to Yves Pouplard for solving this!) +- _jrnl_ relies on the `PyCrypto` package to encrypt journals, which has some known problems with installing on Windows and within virtual environments. From 7e496bd51bde8b5b6a4b2b808b7633e6fdb5d72c Mon Sep 17 00:00:00 2001 From: William Minchin Date: Thu, 2 Jan 2014 18:05:10 -0700 Subject: [PATCH 4/8] Still touch the tempfile before editing --- jrnl/util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jrnl/util.py b/jrnl/util.py index 7191cb69..87271d28 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -126,6 +126,8 @@ def load_and_fix_json(json_path): def get_text_from_editor(config, template=""): tmpfile = os.path.join(tempfile.gettempdir(), "jrnl") + with open(tmpfile, 'w'): + pass if template: with codecs.open(tmpfile, 'w', "utf-8") as f: f.write(template) From 60decf9fe09a65c846cd6e8c3284c913b5e25b01 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Thu, 2 Jan 2014 18:05:23 -0700 Subject: [PATCH 5/8] Update Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e644f568..5fe17b7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ 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.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. From 91ec39554b01dd9221b03e16217e4e7914392553 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Thu, 2 Jan 2014 18:25:24 -0700 Subject: [PATCH 6/8] 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" From afb5c0338992c654645c861c1d53856e57d1ba6e Mon Sep 17 00:00:00 2001 From: William Minchin Date: Thu, 2 Jan 2014 18:28:05 -0700 Subject: [PATCH 7/8] install only recommends colorama for Windows --- jrnl/install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jrnl/install.py b/jrnl/install.py index 7a6fa5c4..4ad2b748 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -83,7 +83,7 @@ def install_jrnl(config_path='~/.jrnl_config'): 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"): + if os.name == "nt" and 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 From 516b01bb188e3fa23670c1dbc23e670e0c4014a5 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Thu, 2 Jan 2014 18:53:16 -0700 Subject: [PATCH 8/8] fix issues on namespace of 'colorama' variable --- jrnl/Journal.py | 5 ++--- jrnl/util.py | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 531b0784..b42d9ba1 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -168,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: util.colorize(match.group(0)), + lambda match: util.colorize(match.group(0), colorama), 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: util.colorize(match.group(0), colorama), pp) return pp @@ -435,4 +435,3 @@ class DayOne(Journal): self._deleted_entries = [e for e in self.entries if e.uuid not in edited_uuids] self.entries[:] = [e for e in self.entries if e.uuid in edited_uuids] return entries - diff --git a/jrnl/util.py b/jrnl/util.py index 6cf7fda1..5f6dca4d 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -139,9 +139,9 @@ def get_text_from_editor(config, template=""): prompt('[Nothing saved to file]') return raw -def colorize(string): +def colorize(string, colorama=None): """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 + return u"\033[36m{}\033[39m".format(string)