diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d26aac0..874dde48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog ### 1.7 (December 22, 2013) +* __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 b00c4525..a4beacf2 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -99,3 +99,30 @@ 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: + +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: + +.. 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. diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 0fa9eada..b42d9ba1 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 @@ -163,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 @@ -430,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/__init__.py b/jrnl/__init__.py index 33c20aa5..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.4' +__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/install.py b/jrnl/install.py index 3240a206..4ad2b748 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 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 + 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..5f6dca4d 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -126,11 +126,11 @@ 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) - with open(tmpfile, 'w'): - pass subprocess.call(config['editor'].split() + [tmpfile]) with codecs.open(tmpfile, "r", "utf-8") as f: raw = f.read() @@ -139,7 +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""" - return u"\033[36m{}\033[39m".format(string) - + if os.name == "nt" and not colorama: + return string + else: + return u"\033[36m{}\033[39m".format(string)