From d6214ababb34f9fe5ae77fabb415ca87f0e3dd72 Mon Sep 17 00:00:00 2001 From: Thomas Hunger Date: Fri, 6 Jan 2012 23:40:43 +0000 Subject: [PATCH 1/9] Distribute README.rst and HISTORY.rst when building sdist. --- setup.py | 4 ++++ 1 file changed, 4 insertions(+) mode change 100644 => 100755 setup.py 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', From 526cf84ebb63f1b2f9758a347da76edae5c0d8b1 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Sat, 7 Jan 2012 21:45:31 +0530 Subject: [PATCH 2/9] added a method to find current python interpreter is ipython, if so color shoudl be disabled --- AUTHORS | 3 ++- HACKING | 2 +- clint/textui/colored.py | 11 ++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) 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..f93f50f 100644 --- a/clint/textui/colored.py +++ b/clint/textui/colored.py @@ -25,7 +25,16 @@ __all__ = ( ) COLORS = __all__[:-2] -DISABLE_COLOR = False + +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: + DISABLE_COLOR = False if not sys.stdout.isatty(): DISABLE_COLOR = True From 5f2df1218a00df595d660bbea31c7bbc3cf573f7 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Sat, 7 Jan 2012 21:47:55 +0530 Subject: [PATCH 3/9] fixed spaces --- clint/textui/colored.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clint/textui/colored.py b/clint/textui/colored.py index f93f50f..78e4393 100644 --- a/clint/textui/colored.py +++ b/clint/textui/colored.py @@ -27,11 +27,11 @@ __all__ = ( COLORS = __all__[:-2] 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. -""" + """ + 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: DISABLE_COLOR = False From c9bf3bac3a75e009dfe05f19555c2831892abf59 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Sat, 7 Jan 2012 21:54:17 +0530 Subject: [PATCH 4/9] works perfectly fine with ipython, standard python interpreter and unfortuantely clint colors wont work in dreampie :( --- clint/textui/colored.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/clint/textui/colored.py b/clint/textui/colored.py index 78e4393..10c8931 100644 --- a/clint/textui/colored.py +++ b/clint/textui/colored.py @@ -27,7 +27,7 @@ __all__ = ( COLORS = __all__[:-2] 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. @@ -36,10 +36,6 @@ if 'get_ipython' in dir(): else: DISABLE_COLOR = False -if not sys.stdout.isatty(): - DISABLE_COLOR = True -else: - colorama.init(autoreset=True) class ColoredString(object): From ec46d65bd273f4cbb0fdecf68fca2facdf24151b Mon Sep 17 00:00:00 2001 From: Collin Watson Date: Sat, 14 Jan 2012 00:59:44 -0800 Subject: [PATCH 5/9] Added support for colored unicode --- clint/textui/colored.py | 5 ++++- examples/unicode.py | 32 ++++++++++++++++++++++++++++++++ examples/unicode.sh | 3 +++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 examples/unicode.py create mode 100755 examples/unicode.sh diff --git a/clint/textui/colored.py b/clint/textui/colored.py index 10c8931..6b40942 100644 --- a/clint/textui/colored.py +++ b/clint/textui/colored.py @@ -61,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, basestring): + return ('%s' % value).decode('utf8') + return value if PY3: __str__ = __unicode__ diff --git a/examples/unicode.py b/examples/unicode.py new file mode 100644 index 0000000..3df92fc --- /dev/null +++ b/examples/unicode.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys +sys.path.insert(0, os.path.abspath('..')) + +from clint import args +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): + for arg in args.all: + puts('%s' % colored.red(arg)) diff --git a/examples/unicode.sh b/examples/unicode.sh new file mode 100755 index 0000000..47a95e9 --- /dev/null +++ b/examples/unicode.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +python unicode.py こんにちは。 From 7e1c7397553a0f8bdbd55ee18613cf5066cef09b Mon Sep 17 00:00:00 2001 From: Collin Watson Date: Sat, 14 Jan 2012 01:11:47 -0800 Subject: [PATCH 6/9] Ignore unicode strings as they are already decoded --- clint/textui/colored.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clint/textui/colored.py b/clint/textui/colored.py index 6b40942..5ff2b43 100644 --- a/clint/textui/colored.py +++ b/clint/textui/colored.py @@ -62,7 +62,7 @@ class ColoredString(object): def __unicode__(self): value = self.color_str - if isinstance(value, basestring): + if isinstance(value, str): return ('%s' % value).decode('utf8') return value From b917e688379f8b7c74bfab40ac23e99dab925828 Mon Sep 17 00:00:00 2001 From: Collin Watson Date: Sat, 14 Jan 2012 12:17:29 -0800 Subject: [PATCH 7/9] Removed unnecessary interpolation since it's a known string --- clint/textui/colored.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clint/textui/colored.py b/clint/textui/colored.py index 5ff2b43..db70729 100644 --- a/clint/textui/colored.py +++ b/clint/textui/colored.py @@ -63,7 +63,7 @@ class ColoredString(object): def __unicode__(self): value = self.color_str if isinstance(value, str): - return ('%s' % value).decode('utf8') + return value.decode('utf8') return value if PY3: From 1d1bb71203fc4a963b8bdaeca97094c95656e62b Mon Sep 17 00:00:00 2001 From: Collin Watson Date: Sat, 14 Jan 2012 12:17:46 -0800 Subject: [PATCH 8/9] Added unicode file and input examples --- examples/unicode.json | 4 ++++ examples/unicode.py | 33 ++++++++++++++++++++++++++++++--- examples/unicode.sh | 2 +- 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 examples/unicode.json 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 index 3df92fc..8168fde 100644 --- a/examples/unicode.py +++ b/examples/unicode.py @@ -1,11 +1,18 @@ #!/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__': @@ -28,5 +35,25 @@ if __name__ == '__main__': puts('') puts('Arguments:') with indent(4): - for arg in args.all: - puts('%s' % colored.red(arg)) + 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 index 47a95e9..fc93c67 100755 --- a/examples/unicode.sh +++ b/examples/unicode.sh @@ -1,3 +1,3 @@ #!/usr/bin/env sh -python unicode.py こんにちは。 +python unicode.py こんにちは。 unicode.json < unicode.json From 3a40b682f44ae34b93c9097fb0bdda5fff8622b1 Mon Sep 17 00:00:00 2001 From: Collin Watson Date: Sat, 14 Jan 2012 17:03:10 -0800 Subject: [PATCH 9/9] Support python 3 by checking if the decode attribute exists. --- clint/textui/colored.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clint/textui/colored.py b/clint/textui/colored.py index db70729..7ff3878 100644 --- a/clint/textui/colored.py +++ b/clint/textui/colored.py @@ -62,7 +62,7 @@ class ColoredString(object): def __unicode__(self): value = self.color_str - if isinstance(value, str): + if isinstance(value, str) and hasattr(value, 'decode'): return value.decode('utf8') return value