mirror of
https://github.com/kennethreitz/clint.git
synced 2026-06-05 23:00:18 +00:00
many fixes
This commit is contained in:
+6
-4
@@ -1,7 +1,9 @@
|
||||
from . import arguments
|
||||
from . import textui
|
||||
from . import utils
|
||||
from .pipes import piped_in
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import arguments
|
||||
import textui
|
||||
import utils
|
||||
from pipes import piped_in
|
||||
|
||||
|
||||
__title__ = 'clint'
|
||||
|
||||
+6
-10
@@ -1,15 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
x
|
||||
clint.textui.core
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
|
||||
from progress import progressbar
|
||||
|
||||
|
||||
__all__ = ('puts', 'puts_err', 'indent', 'maxwidth')
|
||||
__all__ = ('puts', 'puts_err', 'indent', 'progressbar')
|
||||
|
||||
|
||||
STDOUT = sys.stdout.write
|
||||
@@ -52,7 +54,7 @@ class Writer(object):
|
||||
'\n' if newline else ''
|
||||
))
|
||||
stream(_str)
|
||||
|
||||
|
||||
|
||||
def puts(s, newline=True):
|
||||
"""Prints given string to stdout via Writer interface."""
|
||||
@@ -67,9 +69,3 @@ def puts_err(s, newline=True):
|
||||
def indent(indent=4, quote=''):
|
||||
"""Indentation context manager"""
|
||||
return Writer(indent=indent, quote=quote)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def maxwidth(x=None):
|
||||
# if none, detect from applib
|
||||
print x
|
||||
@@ -0,0 +1,18 @@
|
||||
import sys
|
||||
|
||||
def progressbar(it, prefix='', size=32, hide=False):
|
||||
count = len(it)
|
||||
if count:
|
||||
def _show(_i):
|
||||
x = int(size*_i/count)
|
||||
if not hide:
|
||||
sys.stdout.write("%s[%s>%s] %i/%i\r" % (prefix, "="*x, "-"*(size-x), _i, count))
|
||||
sys.stdout.flush()
|
||||
|
||||
_show(0)
|
||||
for i, item in enumerate(it):
|
||||
yield item
|
||||
_show(i+1)
|
||||
if not hide:
|
||||
sys.stdout.write("\n")
|
||||
sys.stdout.flush()
|
||||
@@ -4,26 +4,6 @@ import sys
|
||||
import errno
|
||||
from os import makedirs
|
||||
|
||||
|
||||
|
||||
def progressbar(it, prefix='', size=32, hide=False):
|
||||
count = len(it)
|
||||
if count:
|
||||
def _show(_i):
|
||||
x = int(size*_i/count)
|
||||
if not hide:
|
||||
sys.stdout.write("%s[%s>%s] %i/%i\r" % (prefix, "="*x, "-"*(size-x), _i, count))
|
||||
sys.stdout.flush()
|
||||
|
||||
_show(0)
|
||||
for i, item in enumerate(it):
|
||||
yield item
|
||||
_show(i+1)
|
||||
if not hide:
|
||||
sys.stdout.write("\n")
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def is_collection(obj):
|
||||
"""Tests if an object is a collection"""
|
||||
|
||||
|
||||
@@ -27,7 +27,10 @@ setup(
|
||||
author_email='me@kennethreitz.com',
|
||||
url='https://github.com/kennethreitz/clint',
|
||||
packages= [
|
||||
'clint', 'clint.packages', 'clint.packages.colorama'
|
||||
'clint',
|
||||
'clint.textui',
|
||||
|
||||
'clint.packages', 'clint.packages.colorama'
|
||||
],
|
||||
install_requires=required,
|
||||
license='ISC',
|
||||
|
||||
Reference in New Issue
Block a user