64 Commits

Author SHA1 Message Date
Jason Piper fc463f16c3 0.3.3 2014-01-09 23:45:19 +00:00
Jason Piper 9324af95b2 Fixed README and HISTORY being installed to /usr 2014-01-09 22:52:08 +00:00
Jason Piper 50294ea2dc Merge pull request #95 from saimn/patch-1
Use print() function to fix install on python 3
2014-01-09 12:25:27 -08:00
kennethreitz 56fe6138b6 Merge pull request #96 from sephii/bold_support
Add support for bold text
2014-01-08 11:59:57 -08:00
Sylvain Fankhauser d22847fb95 add support for bold text 2013-12-18 17:02:38 +01:00
Simon Conseil ce25cea7e8 Use print() function to fix install on python 3
clint 0.3.2 can't be installed on python 3.3 because of a print statement.
2013-12-05 23:42:27 +01:00
Kenneth Reitz cab8004284 v0.3.1 2013-12-02 22:15:42 -05:00
Kenneth Reitz c76cc35289 support always_color 2013-12-02 22:14:57 -05:00
Kenneth Reitz 8e86e4c1fa Merge pull request #92 from joshmoore/patch-1
Point README.rst to master/examples rather than develop
2013-08-06 08:36:50 -07:00
Josh Moore 858db011d8 Point README.rst to master/examples rather than develop 2013-08-06 10:24:14 +02:00
Kenneth Reitz c111ba5d92 Update README.rst 2013-07-15 09:04:42 -04:00
Kenneth Reitz 9e43717921 Merge pull request #88 from ewa/develop
Added optional "every" argument to progress.{bar,dots,mill}
2013-06-12 23:36:28 -07:00
Kenneth Reitz 8e351ac4d0 Merge pull request #82 from techniq/patch-1
Fix test name (TabLib->Clint)
2013-04-13 20:44:12 -07:00
Eric W. Anderson cb8bcee077 And, add self to AUTHORS 2013-03-01 00:21:22 -05:00
Eric W. Anderson 3df99a6a2b Added "every" option to dots and mill as well 2013-03-01 00:19:10 -05:00
Eric W. Anderson 5b37fb544d Add "every" option to progress.bar:
Only redraw bar every "every" steps.  Useful for very long sequences of small
operations.
2013-03-01 00:05:21 -05:00
Eric W. Anderson 099a506344 Expliclity refer to pwd for arugments package 2013-02-28 23:59:31 -05:00
Kenneth Reitz d7fdbe85a9 Merge pull request #84 from sghill/develop
Fix 404 to AUTHORS in README
2013-01-24 20:00:08 -08:00
Steve Hill 7b2130e582 Fix 404 to AUTHORS in README 2013-01-24 19:50:08 -08:00
Sean Lynch f884841082 Fix test name (TabLib->Clint) 2013-01-20 23:45:31 -05:00
Kenneth Reitz 112ea81b51 Merge pull request #73 from dmedvinsky/bug/add-textui-streams-to-all
Add textui streams to __all__
2012-11-15 18:42:58 -08:00
Kenneth Reitz 399fa2bb24 Merge pull request #74 from techtonik/patch-1
Fix image
2012-11-15 17:57:43 -08:00
anatoly techtonik ab2f37219a Fix image 2012-11-07 15:06:46 +03:00
Dmitry Medvinsky 464849e575 Add textui streams to __all__
So that I could write

    from clint import textui as ui
    ui.puts(ui.colored.red('fatal error'), stream=ui.STDERR)
2012-09-24 18:59:52 +04:00
Kenneth Reitz acdddbabea Merge pull request #42 from takluyver/colorama-init2
Initialise colorama for textui on Windows.
2012-09-24 07:23:17 -07:00
Kenneth Reitz 1a11a670e7 Merge pull request #57 from aerenchyma/fix-issue56
Fix - issue56
2012-09-24 07:19:32 -07:00
Kenneth Reitz 1dc521de1a Merge pull request #63 from dendright/develop
Only write progress bars to terminal by default
2012-09-24 07:18:52 -07:00
Kenneth Reitz 1e3888e530 Merge pull request #70 from gekitsuu/develop
changed import args to import arguments
2012-09-10 16:26:18 -07:00
Adam Glenn 2c8561a492 changed import args to import arguments 2012-09-10 12:52:51 -04:00
Kenneth Reitz 04f0cdd646 Merge pull request #69 from brandly/develop
Fix minor spelling mistake
2012-09-09 14:14:24 -07:00
Matthew Brandly 0bd5026d21 Fix minor spelling mistake 2012-09-09 14:54:52 -04:00
jczetta b69ceb18d2 redefined __getattr__ so all str methods work
All str methods work for ColoredStrings with expected functionality, excepting .join(). Retained some other method definitions in order to retain expected functionality. Added tests for ColoredString.
2012-08-25 12:43:29 -04:00
Jack Riches e1bdaa4d0d More robust checking for if output is a tty 2012-08-14 09:47:34 +01:00
Jack Riches 8103032de8 Only write progress bars to terminal by default
This removes unwanted progress bar output when piping to another command
or file. Progress bars may be explicitly shown in this case with
progess.bar(iterable, hide=False)
2012-08-08 15:01:06 +01:00
Kenneth Reitz ab401e7af2 Merge pull request #61 from barberj/args_integration
Args integration
2012-08-01 09:32:49 -07:00
barberj fc841b0a61 consistency is key 2012-08-01 09:15:58 -04:00
barberj b591c3edc2 forgot to include args dependency 2012-08-01 08:49:48 -04:00
barberj 70c0680b8c credit 2012-08-01 08:47:29 -04:00
barberj e7db8c7e37 Updated to use arguments module.
Removed py25 support and tox testing since try/except statements were >=2.5.
Try setup import from setuptools so python setup.py develop is available.
2012-08-01 08:42:34 -04:00
Kenneth Reitz 944af48ba5 Merge pull request #55 from donspaulding/develop
Added an expected_size parameter to progress.bar and progress.mill.
2012-06-14 10:30:43 -07:00
Don Spaulding a1808173d9 Added an expected_size parameter to progress.bar and progress.mill.
Some objects you might want to show progress on while iterating over
do not support calling len().  In these cases you can now pass
`expected_size` in to the progress.bar and progress.mill functions
to avoid the len() call on the iterable.
2012-06-14 12:23:05 -05:00
Kenneth Reitz c2aa315a58 Merge pull request #53 from johtso/develop
Make prompt module accessible
2012-06-14 10:07:15 -07:00
Johannes 3e03a9ceb9 Make prompt module accessible 2012-05-14 12:43:19 +02:00
Kenneth Reitz 02016e8b06 Merge pull request #38 from Lothiraldan/develop
Try a reimplementation of clint.textui.core
2012-05-09 16:28:42 -07:00
Kenneth Reitz a7e2d21273 Merge pull request #51 from kracekumar/develop
Develop
2012-05-09 11:19:39 -07:00
kracekumar 911a84406e added an example get_each_args.py 2012-05-09 01:06:03 +05:30
kracekumar afd410125d added an example get_each_args.py 2012-05-09 01:05:32 +05:30
Kenneth Reitz e2a169ab9c Merge pull request #44 from mjs2600/develop
Fixed a typo in README.rst
2012-04-22 17:55:01 -07:00
Kenneth Reitz cfad07a774 Merge pull request #49 from gbrindisi/prompt
Added basic yes/no prompt module
2012-04-06 10:05:22 -07:00
Gianluca Brindisi 48d9c16f0f Added basic yes/no prompt module 2012-04-06 15:01:14 +02:00
Michael Simpson 86b196811f Update README.rst 2012-02-23 14:26:05 -05:00
Thomas Kluyver d479ea3a3c Initialise colorama for textui on Windows.
Closes gh-39
2012-02-23 10:08:55 +00:00
Kenneth Reitz fc873deb3b Merge pull request #40 from verigak/develop
Allow multiple occurences of a flag in grouped
2012-02-14 14:04:00 -08:00
Giorgos Verigakis d4cb4e8c01 Allow multiple occurences of a flag in grouped 2012-02-14 23:57:45 +02:00
FELD Boris 7c48045b57 Update clint.textui.core's docstrings 2012-02-12 17:46:33 +01:00
FELD Boris ea9b2186d5 More simple implementation of indent context 2012-02-12 17:32:59 +01:00
FELD Boris 761dce7237 Try to reimplement clint.textui.core in a more simpler way 2012-02-12 17:27:18 +01:00
Boris Feld 72b04cf5af Add a dedent util function, useful when using indent otherwise than as a context. 2012-02-11 22:51:20 +01:00
Kenneth Reitz 0378771f94 Merge pull request #32 from jpiper/develop
Added ETA timer to progress.bar
2012-01-23 11:04:07 -08:00
Jason Piper 129fea5e4f added myself to AUTHORS 2012-01-23 14:38:39 +00:00
Jason Piper a9d1089bbd Updated averaging method
Calculates a simple moving average based on the number of iterations
done in (1) second intervals over the last (10) seconds
2012-01-23 14:27:57 +00:00
Jason Piper 270afcca03 Added progress bar ETA
Very simplistic, currently updates every iteration (not a performance
issue, but not the prettiest way to do it)
2012-01-23 13:50:45 +00:00
Kenneth Reitz c7f5296b13 Merge pull request #31 from collinwat/f/unicode-bytes
Explicitly chack for instances of bytes to distinguish between py2 and py3
2012-01-20 09:12:51 -08:00
Collin Watson e8f6f7737a Explicitly chack for instances of bytes to distinguish between py2 and py3. 2012-01-17 08:07:42 -08:00
18 changed files with 282 additions and 130 deletions
+6
View File
@@ -19,3 +19,9 @@ Patches and Suggestions
- takluyver
- kracekumar
- Alejandro Gómez <alejandrogomez>
- Jason Piper <jpiper>
- Gianluca Brindisi <gbrindisi>
- Don Spaulding <donspauldingii@gmail.com>
- Justin Barber <barber.justin (at) gmail>
- Dmitry Medvinsky
- Eric Anderson
+11 -5
View File
@@ -1,13 +1,19 @@
History
-------
0.3.3
+++++
* Fixed Python 3 build issues
* Fixed README and HISTORY being installed to /usr
* Support added for bold text
0.3.2
+++++
* Unknown
0.3.1
+++++
* Progress mill indicator.
* Colored unicode support.
* Fix ipython nuance.
* Unknown
0.3.0
+++++
+4 -4
View File
@@ -4,7 +4,7 @@ Clint: Python Command-line Application Tools
**Clint** is a module filled with a set of awesome tools for developing
commandline applications.
.. image:: https://github.com/kennethreitz/clint/raw/master/misc/clint.jpeg
.. image:: https://raw.github.com/kennethreitz/clint/master/misc/clint.jpeg
**C** ommand
**L** ine
@@ -24,7 +24,7 @@ The world's easiest to use implicit argument system w/ chaining methods for filt
Run the various executables in examples_ to get a good feel for what Clint offers.
.. _examples: https://github.com/kennethreitz/clint/tree/develop/examples
.. _examples: https://github.com/kennethreitz/clint/tree/master/examples
You'll never want to not use it.
@@ -70,7 +70,7 @@ I want to quote my console text (like email). ::
>>> puts('pretty cool, eh?')
not indented text
> indented text
> quoted text
> pretty cool, eh?
I want to color my console text. ::
@@ -160,4 +160,4 @@ Roadmap
.. _`the repository`: http://github.com/kennethreitz/clint
.. _AUTHORS: http://github.com/kennethreitz/clint/blob/master/AUTHORS
.. _AUTHORS: http://github.com/kennethreitz/clint/blob/develop/AUTHORS
+10 -6
View File
@@ -11,7 +11,14 @@ This module sets up the main interface for all of clint.
from __future__ import absolute_import
from . import arguments
try:
from collections import OrderedDict
except ImportError:
from .packages.ordereddict import OrderedDict
import collections
collections.OrderedDict = OrderedDict
from .arguments import *
from . import textui
from . import utils
from .pipes import piped_in
@@ -19,12 +26,9 @@ from .pipes import piped_in
__title__ = 'clint'
__version__ = '0.3.1'
__build__ = 0x000301
__version__ = '0.3.3'
__build__ = 0x000303
__author__ = 'Kenneth Reitz'
__license__ = 'ISC'
__copyright__ = 'Copyright 2012 Kenneth Reitz'
__docformat__ = 'restructuredtext'
args = arguments.Args()
+1 -1
View File
@@ -241,7 +241,7 @@ class Args(object):
for arg in self.all:
if arg.startswith('-'):
_current_group = arg
collection[arg] = Args(no_argv=True)
collection.setdefault(arg, Args(no_argv=True))
else:
if _current_group:
collection[_current_group]._args.append(arg)
+4 -4
View File
@@ -20,12 +20,12 @@ except NameError:
unicode = str
def join(l, conj=CONJUNCTION, im_a_moron=MORON_MODE, seperator=COMMA):
def join(l, conj=CONJUNCTION, im_a_moron=MORON_MODE, separator=COMMA):
"""Joins lists of words. Oxford comma and all."""
collector = []
left = len(l)
seperator = seperator + SPACE
separator = separator + SPACE
conj = conj + SPACE
for _l in l[:]:
@@ -37,12 +37,12 @@ def join(l, conj=CONJUNCTION, im_a_moron=MORON_MODE, seperator=COMMA):
if len(l) == 2 or im_a_moron:
collector.append(SPACE)
else:
collector.append(seperator)
collector.append(separator)
collector.append(conj)
elif left is not 0:
collector.append(seperator)
collector.append(separator)
return unicode(str().join(collector))
+5 -1
View File
@@ -7,9 +7,13 @@ clint.textui
This module provides the text output helper system.
"""
import sys
if sys.platform.startswith('win'):
from ..packages import colorama
colorama.init()
from . import colored
from . import progress
from . import prompt
from .core import *
+38 -24
View File
@@ -40,16 +40,33 @@ else:
class ColoredString(object):
"""Enhanced string for __len__ operations on Colored output."""
def __init__(self, color, s):
def __init__(self, color, s, always_color=False, bold=False):
super(ColoredString, self).__init__()
self.s = s
self.color = color
self.always_color = always_color
self.bold = bold
def __getattr__(self, att):
def func_help(*args, **kwargs):
result = getattr(self.s, att)(*args, **kwargs)
if isinstance(result, basestring):
return self._new(result)
elif isinstance(result, list):
return [self._new(x) for x in result]
else:
return result
return func_help
@property
def color_str(self):
if sys.stdout.isatty() and not DISABLE_COLOR:
return '%s%s%s' % (
getattr(colorama.Fore, self.color), self.s, colorama.Fore.RESET)
style = 'BRIGHT' if self.bold else 'NORMAL'
c = '%s%s%s%s' % (getattr(colorama.Fore, self.color), getattr(colorama.Style, style), self.s, colorama.Fore.RESET)
if self.always_color:
return c
elif sys.stdout.isatty() and not DISABLE_COLOR:
return c
else:
return self.s
@@ -62,7 +79,7 @@ class ColoredString(object):
def __unicode__(self):
value = self.color_str
if isinstance(value, str) and hasattr(value, 'decode'):
if isinstance(value, bytes):
return value.decode('utf8')
return value
@@ -84,9 +101,6 @@ class ColoredString(object):
def __mul__(self, other):
return (self.color_str * other)
def split(self, sep=None):
return [self._new(s) for s in self.s.split(sep)]
def _new(self, s):
return ColoredString(self.color, s)
@@ -101,29 +115,29 @@ def clean(s):
return txt
def black(string):
return ColoredString('BLACK', string)
def black(string, always=False, bold=False):
return ColoredString('BLACK', string, always_color=always, bold=bold)
def red(string):
return ColoredString('RED', string)
def red(string, always=False, bold=False):
return ColoredString('RED', string, always_color=always, bold=bold)
def green(string):
return ColoredString('GREEN', string)
def green(string, always=False, bold=False):
return ColoredString('GREEN', string, always_color=always, bold=bold)
def yellow(string):
return ColoredString('YELLOW', string)
def yellow(string, always=False, bold=False):
return ColoredString('YELLOW', string, always_color=always, bold=bold)
def blue(string):
return ColoredString('BLUE', string)
def blue(string, always=False, bold=False):
return ColoredString('BLUE', string, always_color=always, bold=bold)
def magenta(string):
return ColoredString('MAGENTA', string)
def magenta(string, always=False, bold=False):
return ColoredString('MAGENTA', string, always_color=always, bold=bold)
def cyan(string):
return ColoredString('CYAN', string)
def cyan(string, always=False, bold=False):
return ColoredString('CYAN', string, always_color=always, bold=bold)
def white(string):
return ColoredString('WHITE', string)
def white(string, always=False, bold=False):
return ColoredString('WHITE', string, always_color=always, bold=bold)
def disable():
"""Disables colors."""
+49 -54
View File
@@ -13,12 +13,15 @@ from __future__ import absolute_import
import sys
from contextlib import contextmanager
from .formatters import max_width, min_width
from .cols import columns
from ..utils import tsplit
__all__ = ('puts', 'puts_err', 'indent', 'columns', 'max_width', 'min_width')
__all__ = ('puts', 'puts_err', 'indent', 'dedent', 'columns', 'max_width',
'min_width', 'STDOUT', 'STDERR')
STDOUT = sys.stdout.write
@@ -26,68 +29,60 @@ STDERR = sys.stderr.write
NEWLINES = ('\n', '\r', '\r\n')
INDENT_STRINGS = []
# Private
class Writer(object):
"""WriterUtilized by context managers."""
shared = dict(indent_level=0, indent_strings=[])
def __init__(self, indent=0, quote='', indent_char=' '):
self.indent = indent
self.indent_char = indent_char
self.indent_quote = quote
if self.indent > 0:
self.indent_string = ''.join((
str(quote),
(self.indent_char * (indent - len(self.indent_quote)))
))
else:
self.indent_string = ''.join((
('\x08' * (-1 * (indent - len(self.indent_quote)))),
str(quote))
)
if len(self.indent_string):
self.shared['indent_strings'].append(self.indent_string)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.shared['indent_strings'].pop()
def __call__(self, s, newline=True, stream=STDOUT):
if newline:
s = tsplit(s, NEWLINES)
s = map(str, s)
indent = ''.join(self.shared['indent_strings'])
s = (str('\n' + indent)).join(s)
_str = ''.join((
''.join(self.shared['indent_strings']),
str(s),
'\n' if newline else ''
def _indent(indent=0, quote='', indent_char=' '):
"""Indent util function, compute new indent_string"""
if indent > 0:
indent_string = ''.join((
str(quote),
(indent_char * (indent - len(quote)))
))
stream(_str)
else:
indent_string = ''.join((
('\x08' * (-1 * (indent - len(quote)))),
str(quote))
)
if len(indent_string):
INDENT_STRINGS.append(indent_string)
# Public
def puts(s='', newline=True, stream=STDOUT):
"""Prints given string to stdout via Writer interface."""
Writer()(s, newline, stream=stream)
"""Prints given string to stdout."""
if newline:
s = tsplit(s, NEWLINES)
s = map(str, s)
indent = ''.join(INDENT_STRINGS)
s = (str('\n' + indent)).join(s)
_str = ''.join((
''.join(INDENT_STRINGS),
str(s),
'\n' if newline else ''
))
stream(_str)
def puts_err(s='', newline=True, stream=STDERR):
"""Prints given string to stderr via Writer interface."""
Writer()(s, newline, stream=stream)
"""Prints given string to stderr."""
puts(s, newline, stream)
def dedent():
"""Dedent next strings, use only if you use indent otherwise than as a
context."""
INDENT_STRINGS.pop()
@contextmanager
def _indent_context():
"""Indentation context manager."""
yield
dedent()
def indent(indent=4, quote=''):
"""Indentation context manager."""
return Writer(indent=indent, quote=quote)
"""Indentation manager, return an indentation context manager."""
_indent(indent, quote)
return _indent_context()
+45 -17
View File
@@ -11,10 +11,16 @@ This module provides the progressbar functionality.
from __future__ import absolute_import
import sys
import time
STREAM = sys.stderr
# Only show bar in terminals by default (better for piping, logging etc.)
try:
HIDE_DEFAULT = not STREAM.isatty()
except AttributeError: # output does not support isatty()
HIDE_DEFAULT = True
BAR_TEMPLATE = '%s[%s%s] %i/%i\r'
BAR_TEMPLATE = '%s[%s%s] %i/%i - %s\r'
MILL_TEMPLATE = '%s %s %i/%i\r'
DOTS_CHAR = '.'
@@ -22,17 +28,35 @@ 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):
#How long to wait before recalculating the ETA
ETA_INTERVAL = 1
#How many intervals (excluding the current one) to calculate the simple moving average
ETA_SMA_WINDOW = 9
def bar(it, label='', width=32, hide=HIDE_DEFAULT, empty_char=BAR_EMPTY_CHAR, filled_char=BAR_FILLED_CHAR, expected_size=None, every=1):
"""Progress iterator. Wrap your iterables with it."""
def _show(_i):
if (time.time() - bar.etadelta) > ETA_INTERVAL:
bar.etadelta = time.time()
bar.ittimes = bar.ittimes[-ETA_SMA_WINDOW:]+[-(bar.start-time.time())/(_i+1)]
bar.eta = sum(bar.ittimes)/float(len(bar.ittimes)) * (count-_i)
bar.etadisp = time.strftime('%H:%M:%S', time.gmtime(bar.eta))
x = int(width*_i/count)
if not hide:
STREAM.write(BAR_TEMPLATE % (
label, filled_char*x, empty_char*(width-x), _i, count))
STREAM.flush()
if ((_i % every)==0 or # True every "every" updates
(_i == count)): # And when we're done
STREAM.write(BAR_TEMPLATE % (
label, filled_char*x, empty_char*(width-x), _i, count, bar.etadisp))
STREAM.flush()
count = len(it)
count = len(it) if expected_size is None else expected_size
bar.start = time.time()
bar.ittimes = []
bar.eta = 0
bar.etadelta = time.time()
bar.etadisp = time.strftime('%H:%M:%S', time.gmtime(bar.eta))
if count:
_show(0)
@@ -43,11 +67,11 @@ def bar(it, label='', width=32, hide=False, empty_char=BAR_EMPTY_CHAR, filled_ch
_show(i+1)
if not hide:
STREAM.write('\n')
STREAM.flush()
STREAM.write('\n')
STREAM.flush()
def dots(it, label='', hide=False):
def dots(it, label='', hide=HIDE_DEFAULT, every=1):
"""Progress iterator. Prints a dot for each item being iterated"""
count = 0
@@ -55,10 +79,11 @@ def dots(it, label='', hide=False):
if not hide:
STREAM.write(label)
for item in it:
for (i, item) in enumerate(it):
if not hide:
STREAM.write(DOTS_CHAR)
sys.stderr.flush()
if (i % every)==0: # True every "every" updates
STREAM.write(DOTS_CHAR)
sys.stderr.flush()
count += 1
@@ -68,7 +93,7 @@ def dots(it, label='', hide=False):
STREAM.flush()
def mill(it, label='', hide=False,):
def mill(it, label='', hide=HIDE_DEFAULT, expected_size=None, every=1):
"""Progress iterator. Prints a mill while iterating over the items."""
def _mill_char(_i):
@@ -79,11 +104,14 @@ def mill(it, label='', hide=False,):
def _show(_i):
if not hide:
STREAM.write(MILL_TEMPLATE % (
label, _mill_char(_i), _i, count))
STREAM.flush()
if ((_i % every)==0 or # True every "every" updates
(_i == count)): # And when we're done
count = len(it)
STREAM.write(MILL_TEMPLATE % (
label, _mill_char(_i), _i, count))
STREAM.flush()
count = len(it) if expected_size is None else expected_size
if count:
_show(0)
+49
View File
@@ -0,0 +1,49 @@
# -*- coding: utf8 -*-
"""
clint.textui.prompt
~~~~~~~~~~~~~~~~~~~
Module for simple interactive prompts handling
"""
from __future__ import absolute_import, print_function
from re import match, I
def yn(prompt, default='y', batch=False):
# A sanity check against default value
# If not y/n then y is assumed
if default not in ['y', 'n']:
default = 'y'
# Let's build the prompt
choicebox = '[Y/n]' if default == 'y' else '[y/N]'
prompt = prompt + ' ' + choicebox + ' '
# If input is not a yes/no variant or empty
# keep asking
while True:
# If batch option is True then auto reply
# with default input
if not batch:
input = raw_input(prompt).strip()
else:
print(prompt)
input = ''
# If input is empty default choice is assumed
# so we return True
if input == '':
return True
# Given 'yes' as input if default choice is y
# then return True, False otherwise
if match('y(?:es)?', input, I):
return True if default == 'y' else False
# Given 'no' as input if default choice is n
# then return True, False otherwise
elif match('n(?:o)?', input, I):
return True if default == 'n' else False
+2 -1
View File
@@ -16,4 +16,5 @@ with indent(4, quote='>>>'):
puts(colored.red('NOT Files detected: ') + str(args.not_files))
puts(colored.red('Grouped Arguments: ') + str(dict(args.grouped)))
print
print
+13
View File
@@ -0,0 +1,13 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from clint import args
from clint.textui import puts, colored
all_args = args.grouped
for item in all_args:
if item is not '_':
puts(colored.red("key:%s"%item))
print(all_args[item].all)
+4
View File
@@ -0,0 +1,4 @@
echo "python get_each_args.py --name kracekumar --email me@kracekumar.com"
python get_each_args.py --name kracekumar --email me@kracekumar.com
echo "python get_each_args.py --languages python c html ruby --email me@kracekumar.com"
python get_each_args.py --langauges python c html ruby --email me@kracekumar.com
+6 -1
View File
@@ -17,6 +17,11 @@ 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)
# Override the expected_size, for iterables that don't support len()
D = dict(zip(range(100), range(100)))
for k, v in progress.bar(D.iteritems(), expected_size=len(D)):
sleep(random() * 0.2)
+5 -9
View File
@@ -4,12 +4,13 @@
import os
import sys
from distutils.core import setup
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
import clint
def publish():
"""Publish to PyPi"""
os.system("python setup.py sdist upload")
@@ -18,7 +19,7 @@ if sys.argv[-1] == "publish":
publish()
sys.exit()
required = []
required = ['args']
setup(
name='clint',
@@ -29,10 +30,6 @@ 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',
@@ -48,7 +45,6 @@ setup(
'License :: OSI Approved :: ISC License (ISCL)',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
+28 -2
View File
@@ -6,8 +6,8 @@
import unittest
class TablibTestCase(unittest.TestCase):
"""Tablib test cases."""
class ClintTestCase(unittest.TestCase):
"""Clint test cases."""
def setUp(self):
import clint
@@ -16,5 +16,31 @@ class TablibTestCase(unittest.TestCase):
def tearDown(self):
pass
class ColoredStringTestCase(unittest.TestCase):
def setUp(self):
from clint.textui.colored import ColoredString
def tearDown(self):
pass
def test_split(self):
from clint.textui.colored import ColoredString
new_str = ColoredString('red', "hello world")
output = new_str.split()
assert output[0].s == "hello"
def test_find(self):
from clint.textui.colored import ColoredString
new_str = ColoredString('blue', "hello world")
output = new_str.find('h')
self.assertEqual(output, 0)
def test_replace(self):
from clint.textui.colored import ColoredString
new_str = ColoredString('green', "hello world")
output = new_str.replace("world", "universe")
assert output.s == "hello universe"
if __name__ == '__main__':
unittest.main()
+2 -1
View File
@@ -1,9 +1,10 @@
[tox]
envlist = py25,py26,py27,py3
envlist = py26,py27,py3
[testenv]
commands=py.test --junitxml=junit-{envname}.xml
deps = pytest
args
[testenv:pypy]
basepython=/usr/bin/pypy-c