This commit is contained in:
MinchinWeb 2014-01-02 17:53:36 -08:00
commit 8e6e426a90
6 changed files with 49 additions and 10 deletions

View file

@ -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.

View file

@ -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++ <http://notepad-plus-plus.org/>`_. 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.

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"""
if os.name == "nt" and not colorama:
return string
else:
return u"\033[36m{}\033[39m".format(string)