Skip to content

Commit

Permalink
colorama fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchinWeb committed Jan 3, 2014
1 parent d4a1a10 commit 447fb4d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions jrnl/util.py
Expand Up @@ -10,6 +10,7 @@
except ImportError: import json
if "win32" in sys.platform:
import colorama
colorama.init()

This comment has been minimized.

Copy link
@maebert

maebert Jan 3, 2014

Very good, thanks!

This comment has been minimized.

Copy link
@MinchinWeb

MinchinWeb Jan 3, 2014

Author Owner

:)

import re
import tempfile
import subprocess
Expand Down Expand Up @@ -141,7 +142,5 @@ def get_text_from_editor(config, template=""):

def colorize(string):
"""Returns the string wrapped in cyan ANSI escape"""
if "win32" in sys.platform:
return colorama.Fore.CYAN + string + colorama.Fore.RESET
return u"\033[36m{}\033[39m".format(string)

This comment has been minimized.

Copy link
@maebert

maebert Jan 3, 2014

The point is, if you're not using windows, then colorama won't be installed, imported, or initialised. (See above: if 'win32' in sys.platform must be true to import colorama). On platforms that support ANSI control codes, we don't need a fat wrapper around them.

This comment has been minimized.

Copy link
@MinchinWeb

MinchinWeb Jan 3, 2014

Author Owner

But with coloama installed/initialized, you don't need this conditional test. The colorama color codes are just shortcuts for the ANSI codes.

colorama.Fore.CYAN == u"\033[36m"

This comment has been minimized.

Copy link
@MinchinWeb

MinchinWeb Jan 3, 2014

Author Owner

Ultimately, the program works both with and without these two lines.I just thought the program would be a little cleaner without them.

This comment has been minimized.

Copy link
@maebert

maebert Jan 3, 2014

Aaaah, wait, my bad. Are you saying that on Windows,

import colorama
colorama.init()
print "Hello \033[36mWorld\033[39m"

actually works and prints "World" in Cyan, whereas

import colorama
# colorama.init()
print "Hello \033[36mWorld\033[39m"

will literally print Hello \033[36mWorld\033[39m ?

This comment has been minimized.

Copy link
@MinchinWeb

MinchinWeb Jan 3, 2014

Author Owner

Yes and yes, exactly.

although in the second case the output is Hello ←[36mWorld←[39m (so basically the same. I have no idea why the arrows, but that's what shows up)


0 comments on commit 447fb4d

Please sign in to comment.