18 Commits

Author SHA1 Message Date
Kenneth Reitz 4336c354de v0.3.1 2012-01-16 09:25:54 -05:00
Kenneth Reitz 43b152cf0e Merge branch 'develop' of github.com:kennethreitz/clint into develop 2012-01-16 09:22:05 -05:00
Kenneth Reitz 0d0d482156 Merge branch 'f/unicode' of https://github.com/collinwat/clint 2012-01-16 09:15:29 -05:00
Collin Watson 3a40b682f4 Support python 3 by checking if the decode attribute exists. 2012-01-14 17:03:10 -08:00
Collin Watson 1d1bb71203 Added unicode file and input examples 2012-01-14 12:17:46 -08:00
Collin Watson b917e68837 Removed unnecessary interpolation since it's a known string 2012-01-14 12:17:29 -08:00
Kenneth Reitz 66a6148088 Merge pull request #30 from alejandrogomez/develop
Add a mill progress indicator to `progress.py`
2012-01-14 10:20:52 -08:00
Alejandro Gómez a95e803268 Add a mill progress indicator to progress.py
I've created a progress indicator that outputs a "mill" and added it to
the `progress.py` file.

Very simple stuff but its more compact than the other progress bars and
it can be useful when using long labels.
2012-01-14 19:01:23 +01:00
Collin Watson 7e1c739755 Ignore unicode strings as they are already decoded 2012-01-14 01:11:47 -08:00
Collin Watson ec46d65bd2 Added support for colored unicode 2012-01-14 00:59:44 -08:00
Kenneth Reitz 73a9cd836b Merge pull request #24 from kracekumar/develop
Develop - fixed issue 9
2012-01-11 05:42:50 -08:00
kracekumar c9bf3bac3a works perfectly fine with ipython, standard python interpreter and unfortuantely clint colors wont work in dreampie :( 2012-01-07 21:54:17 +05:30
kracekumar 5f2df1218a fixed spaces 2012-01-07 21:47:55 +05:30
kracekumar 526cf84ebb added a method to find current python interpreter is ipython, if so color shoudl be disabled 2012-01-07 21:45:31 +05:30
Kenneth Reitz 3709f090b4 Merge pull request #22 from teh/develop
Distribute README.rst and HISTORY.rst when building sdist.
2012-01-06 15:45:01 -08:00
Thomas Hunger d6214ababb Distribute README.rst and HISTORY.rst when building sdist. 2012-01-06 23:43:14 +00:00
Kenneth Reitz ee089c2d39 Merge branch 'develop' 2012-01-05 22:14:51 -05:00
Kenneth Reitz 53ec4c2e09 Merge branch 'develop' 2011-09-24 14:38:05 -04:00
11 changed files with 130 additions and 9 deletions
+3 -1
View File
@@ -16,4 +16,6 @@ Patches and Suggestions
- Will Thames
- Greg Haskins
- Miguel Araujo <maraujop>
- takluyver
- takluyver
- kracekumar
- Alejandro Gómez <alejandrogomez>
+1 -1
View File
@@ -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 :)
Lastly, don't take yourself too seriously :)
+8
View File
@@ -1,6 +1,14 @@
History
-------
0.3.1
+++++
* Progress mill indicator.
* Colored unicode support.
* Fix ipython nuance.
0.3.0
+++++
+2 -2
View File
@@ -19,8 +19,8 @@ from .pipes import piped_in
__title__ = 'clint'
__version__ = '0.3.0'
__build__ = 0x000300
__version__ = '0.3.1'
__build__ = 0x000301
__author__ = 'Kenneth Reitz'
__license__ = 'ISC'
__copyright__ = 'Copyright 2012 Kenneth Reitz'
+12 -4
View File
@@ -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__
+31
View File
@@ -15,10 +15,12 @@ import sys
STREAM = sys.stderr
BAR_TEMPLATE = '%s[%s%s] %i/%i\r'
MILL_TEMPLATE = '%s %s %i/%i\r'
DOTS_CHAR = '.'
BAR_FILLED_CHAR = '#'
BAR_EMPTY_CHAR = ' '
MILL_CHARS = ['|', '/', '-', '\\']
def bar(it, label='', width=32, hide=False, empty_char=BAR_EMPTY_CHAR, filled_char=BAR_FILLED_CHAR):
"""Progress iterator. Wrap your iterables with it."""
@@ -65,3 +67,32 @@ def dots(it, label='', hide=False):
STREAM.write('\n')
STREAM.flush()
def mill(it, label='', hide=False,):
"""Progress iterator. Prints a mill while iterating over the items."""
def _mill_char(_i):
if _i == 100:
return ' '
else:
return MILL_CHARS[_i % len(MILL_CHARS)]
def _show(_i):
if not hide:
STREAM.write(MILL_TEMPLATE % (
label, _mill_char(_i), _i, count))
STREAM.flush()
count = len(it)
if count:
_show(0)
for i, item in enumerate(it):
yield item
_show(i+1)
if not hide:
STREAM.write('\n')
STREAM.flush()
+3 -1
View File
@@ -17,4 +17,6 @@ if __name__ == '__main__':
for i in progress.dots(range(100)):
sleep(random() * 0.2)
for i in progress.mill(range(100)):
sleep(random() * 0.2)
+4
View File
@@ -0,0 +1,4 @@
{
"title": "Bashō's 'old pond'",
"text": "古池や蛙飛込む水の音"
}
+59
View File
@@ -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))
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env sh
python unicode.py こんにちは。 unicode.json < unicode.json
Regular → Executable
+4
View File
@@ -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',