diff --git a/AUTHORS b/AUTHORS index 5d258aa..8896c96 100644 --- a/AUTHORS +++ b/AUTHORS @@ -16,4 +16,5 @@ Patches and Suggestions - Will Thames - Greg Haskins - Miguel Araujo -- takluyver \ No newline at end of file +- takluyver +- kracekumar diff --git a/HACKING b/HACKING index 018f9b7..46b9651 100644 --- a/HACKING +++ b/HACKING @@ -11,4 +11,4 @@ All functionality should be available in pure Python. Optional C (via Cython) implementations may be written for performance reasons, but should never replace the Python implementation. -Lastly, don't take yourself too seriously :) \ No newline at end of file +Lastly, don't take yourself too seriously :) diff --git a/clint/textui/colored.py b/clint/textui/colored.py index 63d7593..7ff3878 100644 --- a/clint/textui/colored.py +++ b/clint/textui/colored.py @@ -25,12 +25,17 @@ __all__ = ( ) COLORS = __all__[:-2] -DISABLE_COLOR = False -if not sys.stdout.isatty(): +if 'get_ipython' in dir(): + """ + when ipython is fired lot of variables like _oh, etc are used. + There are so many ways to find current python interpreter is ipython. + get_ipython is easiest is most appealing for readers to understand. + """ DISABLE_COLOR = True else: - colorama.init(autoreset=True) + DISABLE_COLOR = False + class ColoredString(object): @@ -56,7 +61,10 @@ class ColoredString(object): return "<%s-string: '%s'>" % (self.color, self.s) def __unicode__(self): - return self.color_str + value = self.color_str + if isinstance(value, str) and hasattr(value, 'decode'): + return value.decode('utf8') + return value if PY3: __str__ = __unicode__ diff --git a/examples/unicode.json b/examples/unicode.json new file mode 100644 index 0000000..94f9554 --- /dev/null +++ b/examples/unicode.json @@ -0,0 +1,4 @@ +{ + "title": "Bashō's 'old pond'", + "text": "古池や蛙飛込む水の音" +} diff --git a/examples/unicode.py b/examples/unicode.py new file mode 100644 index 0000000..8168fde --- /dev/null +++ b/examples/unicode.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os +import sys +import codecs + +sys.path.insert(0, os.path.abspath('..')) + +try: + import json +except: + import simplejson as json + +from clint import args +from clint import piped_in +from clint.textui import colored, puts, indent + +if __name__ == '__main__': + + puts('Test:') + with indent(4): + puts('%s Fake test 1.' % colored.green('✔')) + puts('%s Fake test 2.' % colored.red('✖')) + + puts('') + puts('Greet:') + with indent(4): + puts(colored.red('Здравствуйте')) + puts(colored.green('你好。')) + puts(colored.yellow('سلام')) + puts(colored.magenta('안녕하세요')) + puts(colored.blue('नमस्ते')) + puts(colored.cyan('γειά σου')) + + puts('') + puts('Arguments:') + with indent(4): + puts('%s' % colored.red(args[0])) + + puts('') + puts('File:') + with indent(4): + f = args.files[0] + puts(colored.yellow('%s:' % f)) + with indent(2): + fd = codecs.open(f, encoding='utf-8') + for line in fd: + line = line.strip('\n\r') + puts(colored.yellow(' %s' % line)) + fd.close() + + puts('') + puts('Input:') + with indent(4): + in_data = json.loads(piped_in()) + title = in_data['title'] + text = in_data['text'] + puts(colored.blue('Title: %s' % title)) + puts(colored.magenta('Text: %s' % text)) diff --git a/examples/unicode.sh b/examples/unicode.sh new file mode 100755 index 0000000..fc93c67 --- /dev/null +++ b/examples/unicode.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +python unicode.py こんにちは。 unicode.json < unicode.json diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index fd62e29..78d9904 --- a/setup.py +++ b/setup.py @@ -29,6 +29,10 @@ setup( author='Kenneth Reitz', author_email='me@kennethreitz.com', url='https://github.com/kennethreitz/clint', + data_files=[ + 'README.rst', + 'HISTORY.rst', + ], packages= [ 'clint', 'clint.textui',