mirror of
https://github.com/kennethreitz/clint.git
synced 2026-06-05 23:00:18 +00:00
Compare commits
144 Commits
feature/widths
...
v0.3.2
| Author | SHA1 | Date | |
|---|---|---|---|
| e172a1e282 | |||
| cab8004284 | |||
| c76cc35289 | |||
| 8e86e4c1fa | |||
| 858db011d8 | |||
| c111ba5d92 | |||
| 9e43717921 | |||
| 8e351ac4d0 | |||
| cb8bcee077 | |||
| 3df99a6a2b | |||
| 5b37fb544d | |||
| 099a506344 | |||
| d7fdbe85a9 | |||
| 7b2130e582 | |||
| f884841082 | |||
| 112ea81b51 | |||
| 399fa2bb24 | |||
| ab2f37219a | |||
| 464849e575 | |||
| acdddbabea | |||
| 1a11a670e7 | |||
| 1dc521de1a | |||
| 1e3888e530 | |||
| 2c8561a492 | |||
| 04f0cdd646 | |||
| 0bd5026d21 | |||
| b69ceb18d2 | |||
| e1bdaa4d0d | |||
| 8103032de8 | |||
| ab401e7af2 | |||
| fc841b0a61 | |||
| b591c3edc2 | |||
| 70c0680b8c | |||
| e7db8c7e37 | |||
| 944af48ba5 | |||
| a1808173d9 | |||
| c2aa315a58 | |||
| 3e03a9ceb9 | |||
| 02016e8b06 | |||
| a7e2d21273 | |||
| 911a84406e | |||
| afd410125d | |||
| e2a169ab9c | |||
| cfad07a774 | |||
| 48d9c16f0f | |||
| 86b196811f | |||
| d479ea3a3c | |||
| fc873deb3b | |||
| d4cb4e8c01 | |||
| 7c48045b57 | |||
| ea9b2186d5 | |||
| 761dce7237 | |||
| 72b04cf5af | |||
| 0378771f94 | |||
| 129fea5e4f | |||
| a9d1089bbd | |||
| 270afcca03 | |||
| c7f5296b13 | |||
| e8f6f7737a | |||
| 43b152cf0e | |||
| 0d0d482156 | |||
| 3a40b682f4 | |||
| 1d1bb71203 | |||
| b917e68837 | |||
| 66a6148088 | |||
| a95e803268 | |||
| 7e1c739755 | |||
| ec46d65bd2 | |||
| 73a9cd836b | |||
| c9bf3bac3a | |||
| 5f2df1218a | |||
| 526cf84ebb | |||
| 3709f090b4 | |||
| d6214ababb | |||
| ee089c2d39 | |||
| dbb063840a | |||
| 9a4705f090 | |||
| b16b2ce723 | |||
| 1ea4c5afdc | |||
| 39bb08253f | |||
| 8e6973253f | |||
| 84419f6bfb | |||
| 53ec4c2e09 | |||
| 7b6138eda6 | |||
| d19650b93c | |||
| 98edec43e9 | |||
| ef48a47b8d | |||
| 3be47add4a | |||
| bf99084ece | |||
| 705cda4443 | |||
| 79cf7a023b | |||
| 7900853dbc | |||
| 96827698df | |||
| 23689f8b0a | |||
| 1a9e15dbba | |||
| a07602fdeb | |||
| 0855525fca | |||
| 872c78a5b9 | |||
| 5d7485c144 | |||
| 25b8d6a10e | |||
| 003411ebcd | |||
| f651e71093 | |||
| e500773da3 | |||
| 4b9e35c631 | |||
| e85fffdbb6 | |||
| b58f8dccdc | |||
| 3d63ed01f9 | |||
| 81165754a4 | |||
| 6f106e2f12 | |||
| 8adda14a27 | |||
| cc072a18f3 | |||
| c226b6b736 | |||
| 3406ab5329 | |||
| cf0c0bda70 | |||
| a4c2be8865 | |||
| fa2bbf9a0d | |||
| 9736b4cd71 | |||
| 2e68207d0a | |||
| 164d68ce37 | |||
| aa5008b2e0 | |||
| 8b7161b15b | |||
| 763ca94e7b | |||
| 2d200e3709 | |||
| d0f2375a7b | |||
| 2369bc387d | |||
| f12e47fa7c | |||
| 5d733d123d | |||
| 9e1ea1ef91 | |||
| 6d151a0794 | |||
| 13afb11dea | |||
| faeacbbfad | |||
| 401344ff1e | |||
| 598deda4d9 | |||
| bf7b5d0930 | |||
| 6404b0e49c | |||
| b92f3204c9 | |||
| 61225d90e6 | |||
| 3688a2a67b | |||
| dda561387c | |||
| 06af338874 | |||
| 9b91cf16b5 | |||
| ec8fe4a0b7 | |||
| dc6a9c63ea | |||
| 82d31e555f |
@@ -1,2 +1,5 @@
|
|||||||
.idea
|
.idea
|
||||||
MANIFEST
|
MANIFEST
|
||||||
|
*.pyc
|
||||||
|
.tox
|
||||||
|
build/
|
||||||
|
|||||||
@@ -13,3 +13,15 @@ Patches and Suggestions
|
|||||||
- Jeff Forcier
|
- Jeff Forcier
|
||||||
- Morgan Goose
|
- Morgan Goose
|
||||||
- Travis Swicegood
|
- Travis Swicegood
|
||||||
|
- Will Thames
|
||||||
|
- Greg Haskins
|
||||||
|
- Miguel Araujo <maraujop>
|
||||||
|
- 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
|
||||||
|
|||||||
+53
-4
@@ -1,10 +1,57 @@
|
|||||||
History
|
History
|
||||||
-------
|
-------
|
||||||
|
|
||||||
0.1.0 (2011-03-20)
|
0.3.0
|
||||||
|
+++++
|
||||||
|
|
||||||
|
* Python 3 support!
|
||||||
|
|
||||||
|
0.2.4
|
||||||
|
+++++
|
||||||
|
|
||||||
|
* New eng module
|
||||||
|
* Win32 Bugfix
|
||||||
|
|
||||||
|
|
||||||
|
0.2.3
|
||||||
|
+++++
|
||||||
|
|
||||||
|
* Only init colors if they are used (iPython compatability)
|
||||||
|
* New progress module
|
||||||
|
* Various bugfixes
|
||||||
|
|
||||||
|
|
||||||
|
0.2.2
|
||||||
|
+++++
|
||||||
|
|
||||||
|
* Auto Color Disabling
|
||||||
|
* Progress Namespace Change
|
||||||
|
* New Progress Bars
|
||||||
|
* textui.puts newline fix
|
||||||
|
|
||||||
|
|
||||||
|
0.2.1 (2011-03-24)
|
||||||
++++++++++++++++++
|
++++++++++++++++++
|
||||||
|
|
||||||
* Initial Release!
|
* Python 2.5 Support
|
||||||
|
* List of available colors
|
||||||
|
|
||||||
|
|
||||||
|
0.2.0 (2011-03-23)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
* Column Printing!!!
|
||||||
|
* (Auto/Manual) Disabling of Colors
|
||||||
|
* Smarter Colors
|
||||||
|
* max_width, min_width
|
||||||
|
* Strip cli colors
|
||||||
|
* bug fixes
|
||||||
|
|
||||||
|
|
||||||
|
0.1.2 (2011-03-21)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
* Bugfixes
|
||||||
|
|
||||||
|
|
||||||
0.1.1 (2011-03-20)
|
0.1.1 (2011-03-20)
|
||||||
@@ -16,7 +63,9 @@ History
|
|||||||
* Lots of Examples
|
* Lots of Examples
|
||||||
|
|
||||||
|
|
||||||
0.1.2 (2011-03-21)
|
|
||||||
|
0.1.0 (2011-03-20)
|
||||||
++++++++++++++++++
|
++++++++++++++++++
|
||||||
|
|
||||||
* Bugfixes
|
* Initial Release!
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
Clint includes some vendorized python libraries: appdirs, colorama, ordereddict.
|
Clint includes some vendorized python libraries: appdirs, applib, colorama, ordereddict.
|
||||||
|
|
||||||
AppDirs License
|
AppDirs License
|
||||||
===============
|
===============
|
||||||
@@ -25,6 +25,33 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|||||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
AppLib License (console width detection functions are from this library)
|
||||||
|
==============
|
||||||
|
|
||||||
|
# This is the MIT license
|
||||||
|
|
||||||
|
# Copyright (c) 2010 ActiveState Software Inc. All rights reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Colorama License
|
Colorama License
|
||||||
================
|
================
|
||||||
|
|||||||
+33
-6
@@ -4,7 +4,7 @@ Clint: Python Command-line Application Tools
|
|||||||
**Clint** is a module filled with a set of awesome tools for developing
|
**Clint** is a module filled with a set of awesome tools for developing
|
||||||
commandline applications.
|
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
|
**C** ommand
|
||||||
**L** ine
|
**L** ine
|
||||||
@@ -12,16 +12,43 @@ commandline applications.
|
|||||||
**T** ools
|
**T** ools
|
||||||
.
|
.
|
||||||
|
|
||||||
Features:
|
|
||||||
---------
|
|
||||||
|
|
||||||
|
Clint is awesome. Crazy awesome. It supports colors, but detects if the session is a TTY, so doesn't render the colors if you're piping stuff around. Automagically.
|
||||||
|
|
||||||
|
Awesome nest-able indentation context manager. Example: (``with indent(4): puts('indented text')``). It supports custom email-style quotes. Of course, it supports color too, if and when needed.
|
||||||
|
|
||||||
|
It has an awesome Column printer with optional auto-expanding columns. It detects how wide your current console is and adjusts accordingly. It wraps your words properly to fit the column size. With or without colors mixed in. All with a single function call.
|
||||||
|
|
||||||
|
The world's easiest to use implicit argument system w/ chaining methods for filtering. Seriously.
|
||||||
|
|
||||||
|
|
||||||
|
Run the various executables in examples_ to get a good feel for what Clint offers.
|
||||||
|
|
||||||
|
.. _examples: https://github.com/kennethreitz/clint/tree/master/examples
|
||||||
|
|
||||||
|
You'll never want to not use it.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Current Features:
|
||||||
|
-----------------
|
||||||
|
- Little Documentation (bear with me for now)
|
||||||
- CLI Colors and Indents
|
- CLI Colors and Indents
|
||||||
|
- Extremely Simple + Powerful Column Printer
|
||||||
- Iterator-based Progress Bar
|
- Iterator-based Progress Bar
|
||||||
- Implicit Argument Handling
|
- Implicit Argument Handling
|
||||||
- Simple Support for Unix Pipes
|
- Simple Support for Incoming Unix Pipes
|
||||||
- Application Directory management
|
- Application Directory management
|
||||||
|
|
||||||
|
|
||||||
|
Future Features:
|
||||||
|
----------------
|
||||||
|
- Documentation!
|
||||||
|
- Simple choice system ``Are you sure? [Yn]``
|
||||||
|
- Default query system ``Installation Path [/usr/local/bin/]``
|
||||||
|
- Suggestions welcome.
|
||||||
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
-------
|
-------
|
||||||
|
|
||||||
@@ -43,7 +70,7 @@ I want to quote my console text (like email). ::
|
|||||||
>>> puts('pretty cool, eh?')
|
>>> puts('pretty cool, eh?')
|
||||||
|
|
||||||
not indented text
|
not indented text
|
||||||
> indented text
|
> quoted text
|
||||||
> pretty cool, eh?
|
> pretty cool, eh?
|
||||||
|
|
||||||
I want to color my console text. ::
|
I want to color my console text. ::
|
||||||
@@ -133,4 +160,4 @@ Roadmap
|
|||||||
|
|
||||||
|
|
||||||
.. _`the repository`: http://github.com/kennethreitz/clint
|
.. _`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
|
||||||
|
|||||||
+11
-7
@@ -11,7 +11,14 @@ This module sets up the main interface for all of clint.
|
|||||||
|
|
||||||
from __future__ import absolute_import
|
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 textui
|
||||||
from . import utils
|
from . import utils
|
||||||
from .pipes import piped_in
|
from .pipes import piped_in
|
||||||
@@ -19,12 +26,9 @@ from .pipes import piped_in
|
|||||||
|
|
||||||
|
|
||||||
__title__ = 'clint'
|
__title__ = 'clint'
|
||||||
__version__ = '0.1.2'
|
__version__ = '0.3.2'
|
||||||
__build__ = 0x000102
|
__build__ = 0x000302
|
||||||
__author__ = 'Kenneth Reitz'
|
__author__ = 'Kenneth Reitz'
|
||||||
__license__ = 'ISC'
|
__license__ = 'ISC'
|
||||||
__copyright__ = 'Copyright 2011 Kenneth Reitz'
|
__copyright__ = 'Copyright 2012 Kenneth Reitz'
|
||||||
__docformat__ = 'restructuredtext'
|
__docformat__ = 'restructuredtext'
|
||||||
|
|
||||||
|
|
||||||
args = arguments.Args()
|
|
||||||
|
|||||||
+8
-24
@@ -13,33 +13,17 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from glob import glob
|
|
||||||
|
|
||||||
from .packages.ordereddict import OrderedDict
|
|
||||||
from .utils import is_collection
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from collections import OrderedDict
|
||||||
|
except ImportError:
|
||||||
|
from .packages.ordereddict import OrderedDict
|
||||||
|
|
||||||
|
from .utils import expand_path, is_collection
|
||||||
|
|
||||||
__all__ = ('Args', )
|
__all__ = ('Args', )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _expand_path(path):
|
|
||||||
"""Expands directories and globs in given path."""
|
|
||||||
|
|
||||||
paths = []
|
|
||||||
|
|
||||||
if os.path.isdir(path):
|
|
||||||
|
|
||||||
for (dir, dirs, files) in os.walk(path):
|
|
||||||
for file in files:
|
|
||||||
paths.append(os.path.join(dir, file))
|
|
||||||
else:
|
|
||||||
paths.extend(glob(path))
|
|
||||||
|
|
||||||
return paths
|
|
||||||
|
|
||||||
|
|
||||||
class Args(object):
|
class Args(object):
|
||||||
"""CLI Argument management."""
|
"""CLI Argument management."""
|
||||||
|
|
||||||
@@ -257,7 +241,7 @@ class Args(object):
|
|||||||
for arg in self.all:
|
for arg in self.all:
|
||||||
if arg.startswith('-'):
|
if arg.startswith('-'):
|
||||||
_current_group = arg
|
_current_group = arg
|
||||||
collection[arg] = Args(no_argv=True)
|
collection.setdefault(arg, Args(no_argv=True))
|
||||||
else:
|
else:
|
||||||
if _current_group:
|
if _current_group:
|
||||||
collection[_current_group]._args.append(arg)
|
collection[_current_group]._args.append(arg)
|
||||||
@@ -341,7 +325,7 @@ class Args(object):
|
|||||||
_paths = []
|
_paths = []
|
||||||
|
|
||||||
for arg in self.all:
|
for arg in self.all:
|
||||||
for path in _expand_path(arg):
|
for path in expand_path(arg):
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
if absolute:
|
if absolute:
|
||||||
_paths.append(os.path.abspath(path))
|
_paths.append(os.path.abspath(path))
|
||||||
@@ -358,7 +342,7 @@ class Args(object):
|
|||||||
_args = []
|
_args = []
|
||||||
|
|
||||||
for arg in self.all:
|
for arg in self.all:
|
||||||
if not len(_expand_path(arg)):
|
if not len(expand_path(arg)):
|
||||||
if not os.path.exists(arg):
|
if not os.path.exists(arg):
|
||||||
_args.append(arg)
|
_args.append(arg)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
clint.eng
|
||||||
|
~~~~~~~~~
|
||||||
|
|
||||||
|
This module provides English language string helpers.
|
||||||
|
|
||||||
|
"""
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
MORON_MODE = False
|
||||||
|
COMMA = ','
|
||||||
|
CONJUNCTION = 'and'
|
||||||
|
SPACE = ' '
|
||||||
|
|
||||||
|
try:
|
||||||
|
unicode
|
||||||
|
except NameError:
|
||||||
|
unicode = str
|
||||||
|
|
||||||
|
|
||||||
|
def join(l, conj=CONJUNCTION, im_a_moron=MORON_MODE, separator=COMMA):
|
||||||
|
"""Joins lists of words. Oxford comma and all."""
|
||||||
|
|
||||||
|
collector = []
|
||||||
|
left = len(l)
|
||||||
|
separator = separator + SPACE
|
||||||
|
conj = conj + SPACE
|
||||||
|
|
||||||
|
for _l in l[:]:
|
||||||
|
|
||||||
|
left += -1
|
||||||
|
|
||||||
|
collector.append(_l)
|
||||||
|
if left == 1:
|
||||||
|
if len(l) == 2 or im_a_moron:
|
||||||
|
collector.append(SPACE)
|
||||||
|
else:
|
||||||
|
collector.append(separator)
|
||||||
|
|
||||||
|
collector.append(conj)
|
||||||
|
|
||||||
|
elif left is not 0:
|
||||||
|
collector.append(separator)
|
||||||
|
|
||||||
|
return unicode(str().join(collector))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print(join(['blue', 'red', 'yellow'], conj='or', im_a_moron=True))
|
||||||
|
print(join(['blue', 'red', 'yellow'], conj='or'))
|
||||||
|
print(join(['blue', 'red'], conj='or'))
|
||||||
|
print(join(['blue', 'red'], conj='and'))
|
||||||
|
print(join(['blue'], conj='and'))
|
||||||
|
print(join(['blue', 'red', 'yellow', 'green', 'ello'], conj='and'))
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from .initialise import init
|
from .initialise import init, deinit, reinit
|
||||||
from .ansi import Fore, Back, Style
|
from .ansi import Fore, Back, Style
|
||||||
from .ansitowin32 import AnsiToWin32
|
from .ansitowin32 import AnsiToWin32
|
||||||
|
|
||||||
VERSION = '0.1.18'
|
VERSION = '0.2.3'
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class AnsiToWin32(object):
|
|||||||
def reset_all(self):
|
def reset_all(self):
|
||||||
if self.convert:
|
if self.convert:
|
||||||
self.call_win32('m', (0,))
|
self.call_win32('m', (0,))
|
||||||
else:
|
elif is_a_tty(self.wrapped):
|
||||||
self.wrapped.write(Style.RESET_ALL)
|
self.wrapped.write(Style.RESET_ALL)
|
||||||
|
|
||||||
|
|
||||||
@@ -173,4 +173,10 @@ class AnsiToWin32(object):
|
|||||||
args = func_args[1:]
|
args = func_args[1:]
|
||||||
kwargs = dict(on_stderr=self.on_stderr)
|
kwargs = dict(on_stderr=self.on_stderr)
|
||||||
func(*args, **kwargs)
|
func(*args, **kwargs)
|
||||||
|
elif command in ('H', 'f'): # set cursor position
|
||||||
|
func = winterm.set_cursor_position
|
||||||
|
func(params, on_stderr=self.on_stderr)
|
||||||
|
elif command in ('J'):
|
||||||
|
func = winterm.erase_data
|
||||||
|
func(params, on_stderr=self.on_stderr)
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ from .ansitowin32 import AnsiToWin32
|
|||||||
orig_stdout = sys.stdout
|
orig_stdout = sys.stdout
|
||||||
orig_stderr = sys.stderr
|
orig_stderr = sys.stderr
|
||||||
|
|
||||||
|
wrapped_stdout = sys.stdout
|
||||||
|
wrapped_stderr = sys.stderr
|
||||||
|
|
||||||
atexit_done = False
|
atexit_done = False
|
||||||
|
|
||||||
|
|
||||||
@@ -16,11 +19,14 @@ def reset_all():
|
|||||||
|
|
||||||
def init(autoreset=False, convert=None, strip=None, wrap=True):
|
def init(autoreset=False, convert=None, strip=None, wrap=True):
|
||||||
|
|
||||||
if wrap==False and (autoreset==True or convert==True or strip==True):
|
if not wrap and any([autoreset, convert, strip]):
|
||||||
raise ValueError('wrap=False conflicts with any other arg=True')
|
raise ValueError('wrap=False conflicts with any other arg=True')
|
||||||
|
|
||||||
sys.stdout = wrap_stream(orig_stdout, convert, strip, autoreset, wrap)
|
global wrapped_stdout, wrapped_stderr
|
||||||
sys.stderr = wrap_stream(orig_stderr, convert, strip, autoreset, wrap)
|
sys.stdout = wrapped_stdout = \
|
||||||
|
wrap_stream(orig_stdout, convert, strip, autoreset, wrap)
|
||||||
|
sys.stderr = wrapped_stderr = \
|
||||||
|
wrap_stream(orig_stderr, convert, strip, autoreset, wrap)
|
||||||
|
|
||||||
global atexit_done
|
global atexit_done
|
||||||
if not atexit_done:
|
if not atexit_done:
|
||||||
@@ -28,6 +34,16 @@ def init(autoreset=False, convert=None, strip=None, wrap=True):
|
|||||||
atexit_done = True
|
atexit_done = True
|
||||||
|
|
||||||
|
|
||||||
|
def deinit():
|
||||||
|
sys.stdout = orig_stdout
|
||||||
|
sys.stderr = orig_stderr
|
||||||
|
|
||||||
|
|
||||||
|
def reinit():
|
||||||
|
sys.stdout = wrapped_stdout
|
||||||
|
sys.stderr = wrapped_stdout
|
||||||
|
|
||||||
|
|
||||||
def wrap_stream(stream, convert, strip, autoreset, wrap):
|
def wrap_stream(stream, convert, strip, autoreset, wrap):
|
||||||
if wrap:
|
if wrap:
|
||||||
wrapper = AnsiToWin32(stream,
|
wrapper = AnsiToWin32(stream,
|
||||||
@@ -36,3 +52,4 @@ def wrap_stream(stream, convert, strip, autoreset, wrap):
|
|||||||
stream = wrapper.stream
|
stream = wrapper.stream
|
||||||
return stream
|
return stream
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -48,8 +48,16 @@ else:
|
|||||||
("srWindow", SMALL_RECT),
|
("srWindow", SMALL_RECT),
|
||||||
("dwMaximumWindowSize", COORD),
|
("dwMaximumWindowSize", COORD),
|
||||||
]
|
]
|
||||||
|
def __str__(self):
|
||||||
|
return '(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)' % (
|
||||||
|
self.dwSize.Y, self.dwSize.X
|
||||||
|
, self.dwCursorPosition.Y, self.dwCursorPosition.X
|
||||||
|
, self.wAttributes
|
||||||
|
, self.srWindow.Top, self.srWindow.Left, self.srWindow.Bottom, self.srWindow.Right
|
||||||
|
, self.dwMaximumWindowSize.Y, self.dwMaximumWindowSize.X
|
||||||
|
)
|
||||||
|
|
||||||
def GetConsoleScreenBufferInfo(stream_id):
|
def GetConsoleScreenBufferInfo(stream_id=STDOUT):
|
||||||
handle = handles[stream_id]
|
handle = handles[stream_id]
|
||||||
csbi = CONSOLE_SCREEN_BUFFER_INFO()
|
csbi = CONSOLE_SCREEN_BUFFER_INFO()
|
||||||
success = windll.kernel32.GetConsoleScreenBufferInfo(
|
success = windll.kernel32.GetConsoleScreenBufferInfo(
|
||||||
@@ -62,34 +70,54 @@ else:
|
|||||||
|
|
||||||
def SetConsoleTextAttribute(stream_id, attrs):
|
def SetConsoleTextAttribute(stream_id, attrs):
|
||||||
handle = handles[stream_id]
|
handle = handles[stream_id]
|
||||||
success = windll.kernel32.SetConsoleTextAttribute(handle, attrs)
|
return windll.kernel32.SetConsoleTextAttribute(handle, attrs)
|
||||||
assert success
|
|
||||||
|
|
||||||
def SetConsoleCursorPosition(stream_id, position):
|
def SetConsoleCursorPosition(stream_id, position):
|
||||||
handle = handles[stream_id]
|
|
||||||
position = COORD(*position)
|
position = COORD(*position)
|
||||||
success = windll.kernel32.SetConsoleCursorPosition(handle, position)
|
# If the position is out of range, do nothing.
|
||||||
assert success
|
if position.Y <= 0 or position.X <= 0:
|
||||||
|
return
|
||||||
|
# Adjust for Windows' SetConsoleCursorPosition:
|
||||||
|
# 1. being 0-based, while ANSI is 1-based.
|
||||||
|
# 2. expecting (x,y), while ANSI uses (y,x).
|
||||||
|
adjusted_position = COORD(position.Y - 1, position.X - 1)
|
||||||
|
# Adjust for viewport's scroll position
|
||||||
|
sr = GetConsoleScreenBufferInfo(STDOUT).srWindow
|
||||||
|
adjusted_position.Y += sr.Top
|
||||||
|
adjusted_position.X += sr.Left
|
||||||
|
# Resume normal processing
|
||||||
|
handle = handles[stream_id]
|
||||||
|
success = windll.kernel32.SetConsoleCursorPosition(handle, adjusted_position)
|
||||||
|
return success
|
||||||
|
|
||||||
def FillConsoleOutputCharacter(stream_id, char, length, start):
|
def FillConsoleOutputCharacter(stream_id, char, length, start):
|
||||||
handle = handles[stream_id]
|
handle = handles[stream_id]
|
||||||
char = TCHAR(char)
|
char = TCHAR(char)
|
||||||
length = DWORD(length)
|
length = DWORD(length)
|
||||||
start = COORD(*start)
|
|
||||||
num_written = DWORD(0)
|
num_written = DWORD(0)
|
||||||
# AttributeError: function 'FillConsoleOutputCharacter' not found
|
# Note that this is hard-coded for ANSI (vs wide) bytes.
|
||||||
# could it just be that my types are wrong?
|
success = windll.kernel32.FillConsoleOutputCharacterA(
|
||||||
success = windll.kernel32.FillConsoleOutputCharacter(
|
|
||||||
handle, char, length, start, byref(num_written))
|
handle, char, length, start, byref(num_written))
|
||||||
assert success
|
|
||||||
return num_written.value
|
return num_written.value
|
||||||
|
|
||||||
|
def FillConsoleOutputAttribute(stream_id, attr, length, start):
|
||||||
|
''' FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten )'''
|
||||||
|
handle = handles[stream_id]
|
||||||
|
attribute = WORD(attr)
|
||||||
|
length = DWORD(length)
|
||||||
|
num_written = DWORD(0)
|
||||||
|
# Note that this is hard-coded for ANSI (vs wide) bytes.
|
||||||
|
success = windll.kernel32.FillConsoleOutputAttribute(
|
||||||
|
handle, attribute, length, start, byref(num_written))
|
||||||
|
return success
|
||||||
|
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
x = GetConsoleScreenBufferInfo(STDOUT)
|
x = GetConsoleScreenBufferInfo(STDOUT)
|
||||||
print(x.dwSize)
|
print(x)
|
||||||
print(x.dwCursorPosition)
|
print('dwSize(height,width) = (%d,%d)' % (x.dwSize.Y, x.dwSize.X))
|
||||||
print(x.wAttributes)
|
print('dwCursorPosition(y,x) = (%d,%d)' % (x.dwCursorPosition.Y, x.dwCursorPosition.X))
|
||||||
print(x.srWindow)
|
print('wAttributes(color) = %d = 0x%02x' % (x.wAttributes, x.wAttributes))
|
||||||
print(x.dwMaximumWindowSize)
|
print('srWindow(Top,Left)-(Bottom,Right) = (%d,%d)-(%d,%d)' % (x.srWindow.Top, x.srWindow.Left, x.srWindow.Bottom, x.srWindow.Right))
|
||||||
|
print('dwMaximumWindowSize(maxHeight,maxWidth) = (%d,%d)' % (x.dwMaximumWindowSize.Y, x.dwMaximumWindowSize.X))
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ class WinStyle(object):
|
|||||||
class WinTerm(object):
|
class WinTerm(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._default = \
|
self._default = win32.GetConsoleScreenBufferInfo(win32.STDOUT).wAttributes
|
||||||
win32.GetConsoleScreenBufferInfo(win32.STDOUT).wAttributes
|
|
||||||
self.set_attrs(self._default)
|
self.set_attrs(self._default)
|
||||||
self._default_fore = self._fore
|
self._default_fore = self._fore
|
||||||
self._default_back = self._back
|
self._default_back = self._back
|
||||||
@@ -67,3 +66,37 @@ class WinTerm(object):
|
|||||||
handle = win32.STDERR
|
handle = win32.STDERR
|
||||||
win32.SetConsoleTextAttribute(handle, attrs)
|
win32.SetConsoleTextAttribute(handle, attrs)
|
||||||
|
|
||||||
|
def set_cursor_position(self, position=None, on_stderr=False):
|
||||||
|
if position is None:
|
||||||
|
#I'm not currently tracking the position, so there is no default.
|
||||||
|
#position = self.get_position()
|
||||||
|
return
|
||||||
|
handle = win32.STDOUT
|
||||||
|
if on_stderr:
|
||||||
|
handle = win32.STDERR
|
||||||
|
win32.SetConsoleCursorPosition(handle, position)
|
||||||
|
|
||||||
|
def erase_data(self, mode=0, on_stderr=False):
|
||||||
|
# 0 (or None) should clear from the cursor to the end of the screen.
|
||||||
|
# 1 should clear from the cursor to the beginning of the screen.
|
||||||
|
# 2 should clear the entire screen. (And maybe move cursor to (1,1)?)
|
||||||
|
#
|
||||||
|
# At the moment, I only support mode 2. From looking at the API, it
|
||||||
|
# should be possible to calculate a different number of bytes to clear,
|
||||||
|
# and to do so relative to the cursor position.
|
||||||
|
if mode[0] not in (2,):
|
||||||
|
return
|
||||||
|
handle = win32.STDOUT
|
||||||
|
if on_stderr:
|
||||||
|
handle = win32.STDERR
|
||||||
|
# here's where we'll home the cursor
|
||||||
|
coord_screen = win32.COORD(0,0)
|
||||||
|
csbi = win32.GetConsoleScreenBufferInfo(handle)
|
||||||
|
# get the number of character cells in the current buffer
|
||||||
|
dw_con_size = csbi.dwSize.X * csbi.dwSize.Y
|
||||||
|
# fill the entire screen with blanks
|
||||||
|
win32.FillConsoleOutputCharacter(handle, ord(' '), dw_con_size, coord_screen)
|
||||||
|
# now set the buffer's attributes accordingly
|
||||||
|
win32.FillConsoleOutputAttribute(handle, self.get_attrs(), dw_con_size, coord_screen );
|
||||||
|
# put the cursor at (0, 0)
|
||||||
|
win32.SetConsoleCursorPosition(handle, (coord_screen.X, coord_screen.Y))
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ This module contains the helper functions for dealing with unix pipes.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -10,6 +10,7 @@ This module contains all the application resource features of clint.
|
|||||||
|
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
from os import remove, removedirs
|
from os import remove, removedirs
|
||||||
@@ -114,7 +115,7 @@ class AppDir(object):
|
|||||||
remove(fn)
|
remove(fn)
|
||||||
else:
|
else:
|
||||||
removedirs(fn)
|
removedirs(fn)
|
||||||
except OSError, why:
|
except OSError as why:
|
||||||
if why.errno == errno.ENOENT:
|
if why.errno == errno.ENOENT:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -7,9 +7,13 @@ clint.textui
|
|||||||
This module provides the text output helper system.
|
This module provides the text output helper system.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import sys
|
||||||
from __future__ import absolute_import
|
if sys.platform.startswith('win'):
|
||||||
|
from ..packages import colorama
|
||||||
|
colorama.init()
|
||||||
|
|
||||||
from . import colored
|
from . import colored
|
||||||
|
from . import progress
|
||||||
|
from . import prompt
|
||||||
|
|
||||||
from .core import *
|
from .core import *
|
||||||
|
|||||||
+65
-37
@@ -14,33 +14,57 @@ from __future__ import absolute_import
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
PY3 = sys.version_info[0] >= 3
|
||||||
|
|
||||||
from ..packages import colorama
|
from ..packages import colorama
|
||||||
|
|
||||||
DISABLE_COLOR = False
|
|
||||||
|
|
||||||
if sys.stdout.isatty():
|
|
||||||
colorama.init(autoreset=True)
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'red', 'green', 'yellow', 'blue',
|
'red', 'green', 'yellow', 'blue',
|
||||||
'black', 'magenta', 'cyan', 'white',
|
'black', 'magenta', 'cyan', 'white',
|
||||||
'clean', 'disable'
|
'clean', 'disable'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
DISABLE_COLOR = True
|
||||||
|
else:
|
||||||
|
DISABLE_COLOR = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ColoredString(object):
|
class ColoredString(object):
|
||||||
"""Enhanced string for __len__ operations on Colored output."""
|
"""Enhanced string for __len__ operations on Colored output."""
|
||||||
def __init__(self, color, s):
|
def __init__(self, color, s, always_color=False):
|
||||||
super(ColoredString, self).__init__()
|
super(ColoredString, self).__init__()
|
||||||
self.s = s
|
self.s = s
|
||||||
self.color = color
|
self.color = color
|
||||||
|
self.always_color = always_color
|
||||||
|
|
||||||
|
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
|
@property
|
||||||
def color_str(self):
|
def color_str(self):
|
||||||
if sys.stdout.isatty() and not DISABLE_COLOR:
|
c = '%s%s%s' % (getattr(colorama.Fore, self.color), self.s, colorama.Fore.RESET)
|
||||||
return '%s%s%s' % (
|
|
||||||
getattr(colorama.Fore, self.color), self.s, colorama.Fore.RESET)
|
if self.always_color:
|
||||||
|
return c
|
||||||
|
elif sys.stdout.isatty() and not DISABLE_COLOR:
|
||||||
|
return c
|
||||||
else:
|
else:
|
||||||
return self.s
|
return self.s
|
||||||
|
|
||||||
@@ -51,26 +75,30 @@ class ColoredString(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s-string: '%s'>" % (self.color, self.s)
|
return "<%s-string: '%s'>" % (self.color, self.s)
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.__unicode__().encode('utf8')
|
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.color_str
|
value = self.color_str
|
||||||
|
if isinstance(value, bytes):
|
||||||
|
return value.decode('utf8')
|
||||||
|
return value
|
||||||
|
|
||||||
|
if PY3:
|
||||||
|
__str__ = __unicode__
|
||||||
|
else:
|
||||||
|
def __str__(self):
|
||||||
|
return unicode(self).encode('utf8')
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.color_str)
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
self.s += other
|
return str(self.color_str) + str(other)
|
||||||
return self
|
|
||||||
|
|
||||||
def __radd__(self, other):
|
def __radd__(self, other):
|
||||||
self.s = other + self.s
|
return str(other) + str(self.color_str)
|
||||||
return self
|
|
||||||
|
|
||||||
def __mul__(self, other):
|
def __mul__(self, other):
|
||||||
return (self.color_str * other)
|
return (self.color_str * other)
|
||||||
|
|
||||||
def split(self, x=' '):
|
|
||||||
return map(self._new, self.s.split(x))
|
|
||||||
|
|
||||||
def _new(self, s):
|
def _new(self, s):
|
||||||
return ColoredString(self.color, s)
|
return ColoredString(self.color, s)
|
||||||
|
|
||||||
@@ -85,29 +113,29 @@ def clean(s):
|
|||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
|
||||||
def black(string):
|
def black(string, always=False):
|
||||||
return ColoredString('BLACK', string)
|
return ColoredString('BLACK', string, always_color=always)
|
||||||
|
|
||||||
def red(string):
|
def red(string, always=False):
|
||||||
return ColoredString('RED', string)
|
return ColoredString('RED', string, always_color=always)
|
||||||
|
|
||||||
def green(string):
|
def green(string, always=False):
|
||||||
return ColoredString('GREEN', string)
|
return ColoredString('GREEN', string, always_color=always)
|
||||||
|
|
||||||
def yellow(string):
|
def yellow(string, always=False):
|
||||||
return ColoredString('YELLOW', string)
|
return ColoredString('YELLOW', string, always_color=always)
|
||||||
|
|
||||||
def blue(string):
|
def blue(string, always=False):
|
||||||
return ColoredString('BLUE', string)
|
return ColoredString('BLUE', string, always_color=always)
|
||||||
|
|
||||||
def magenta(string):
|
def magenta(string, always=False):
|
||||||
return ColoredString('MAGENTA', string)
|
return ColoredString('MAGENTA', string, always_color=always)
|
||||||
|
|
||||||
def cyan(string):
|
def cyan(string, always=False):
|
||||||
return ColoredString('CYAN', string)
|
return ColoredString('CYAN', string, always_color=always)
|
||||||
|
|
||||||
def white(string):
|
def white(string, always=False):
|
||||||
return ColoredString('WHITE', string)
|
return ColoredString('WHITE', string, always_color=always)
|
||||||
|
|
||||||
def disable():
|
def disable():
|
||||||
"""Disables colors."""
|
"""Disables colors."""
|
||||||
|
|||||||
+52
-57
@@ -13,12 +13,15 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .progress import progressbar
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from .formatters import max_width, min_width
|
from .formatters import max_width, min_width
|
||||||
|
from .cols import columns
|
||||||
from ..utils import tsplit
|
from ..utils import tsplit
|
||||||
|
|
||||||
|
|
||||||
__all__ = ('puts', 'puts_err', 'indent', 'progressbar', 'max_width', 'min_width')
|
__all__ = ('puts', 'puts_err', 'indent', 'dedent', 'columns', 'max_width',
|
||||||
|
'min_width', 'STDOUT', 'STDERR')
|
||||||
|
|
||||||
|
|
||||||
STDOUT = sys.stdout.write
|
STDOUT = sys.stdout.write
|
||||||
@@ -26,68 +29,60 @@ STDERR = sys.stderr.write
|
|||||||
|
|
||||||
NEWLINES = ('\n', '\r', '\r\n')
|
NEWLINES = ('\n', '\r', '\r\n')
|
||||||
|
|
||||||
|
INDENT_STRINGS = []
|
||||||
|
|
||||||
|
# Private
|
||||||
|
|
||||||
class Writer(object):
|
def _indent(indent=0, quote='', indent_char=' '):
|
||||||
"""WriterUtilized by context managers."""
|
"""Indent util function, compute new indent_string"""
|
||||||
|
if indent > 0:
|
||||||
shared = dict(indent_level=0, indent_strings=[])
|
indent_string = ''.join((
|
||||||
|
str(quote),
|
||||||
|
(indent_char * (indent - len(quote)))
|
||||||
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 ''
|
|
||||||
))
|
))
|
||||||
stream(_str)
|
else:
|
||||||
|
indent_string = ''.join((
|
||||||
|
('\x08' * (-1 * (indent - len(quote)))),
|
||||||
|
str(quote))
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(indent_string):
|
||||||
|
INDENT_STRINGS.append(indent_string)
|
||||||
|
|
||||||
def puts(s, newline=True):
|
# Public
|
||||||
"""Prints given string to stdout via Writer interface."""
|
|
||||||
Writer()(s, stream=STDOUT)
|
|
||||||
|
|
||||||
|
def puts(s='', newline=True, stream=STDOUT):
|
||||||
|
"""Prints given string to stdout."""
|
||||||
|
if newline:
|
||||||
|
s = tsplit(s, NEWLINES)
|
||||||
|
s = map(str, s)
|
||||||
|
indent = ''.join(INDENT_STRINGS)
|
||||||
|
|
||||||
def puts_err(s, newline=True):
|
s = (str('\n' + indent)).join(s)
|
||||||
"""Prints given string to stderr via Writer interface."""
|
|
||||||
Writer()(s, stream=STDERR)
|
|
||||||
|
|
||||||
|
_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."""
|
||||||
|
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=''):
|
def indent(indent=4, quote=''):
|
||||||
"""Indentation context manager."""
|
"""Indentation manager, return an indentation context manager."""
|
||||||
return Writer(indent=indent, quote=quote)
|
_indent(indent, quote)
|
||||||
|
return _indent_context()
|
||||||
|
|||||||
+104
-10
@@ -11,22 +11,116 @@ This module provides the progressbar functionality.
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import sys
|
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
|
||||||
|
|
||||||
def progressbar(it, prefix='', size=32, hide=False):
|
BAR_TEMPLATE = '%s[%s%s] %i/%i - %s\r'
|
||||||
|
MILL_TEMPLATE = '%s %s %i/%i\r'
|
||||||
|
|
||||||
|
DOTS_CHAR = '.'
|
||||||
|
BAR_FILLED_CHAR = '#'
|
||||||
|
BAR_EMPTY_CHAR = ' '
|
||||||
|
MILL_CHARS = ['|', '/', '-', '\\']
|
||||||
|
|
||||||
|
#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."""
|
"""Progress iterator. Wrap your iterables with it."""
|
||||||
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()
|
|
||||||
|
|
||||||
|
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:
|
||||||
|
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) 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)
|
_show(0)
|
||||||
|
|
||||||
for i, item in enumerate(it):
|
for i, item in enumerate(it):
|
||||||
|
|
||||||
yield item
|
yield item
|
||||||
_show(i+1)
|
_show(i+1)
|
||||||
|
|
||||||
if not hide:
|
if not hide:
|
||||||
sys.stdout.write("\n")
|
STREAM.write('\n')
|
||||||
sys.stdout.flush()
|
STREAM.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def dots(it, label='', hide=HIDE_DEFAULT, every=1):
|
||||||
|
"""Progress iterator. Prints a dot for each item being iterated"""
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
if not hide:
|
||||||
|
STREAM.write(label)
|
||||||
|
|
||||||
|
for (i, item) in enumerate(it):
|
||||||
|
if not hide:
|
||||||
|
if (i % every)==0: # True every "every" updates
|
||||||
|
STREAM.write(DOTS_CHAR)
|
||||||
|
sys.stderr.flush()
|
||||||
|
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
yield item
|
||||||
|
|
||||||
|
STREAM.write('\n')
|
||||||
|
STREAM.flush()
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
if _i == 100:
|
||||||
|
return ' '
|
||||||
|
else:
|
||||||
|
return MILL_CHARS[_i % len(MILL_CHARS)]
|
||||||
|
|
||||||
|
def _show(_i):
|
||||||
|
if not hide:
|
||||||
|
if ((_i % every)==0 or # True every "every" updates
|
||||||
|
(_i == count)): # And when we're done
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
for i, item in enumerate(it):
|
||||||
|
|
||||||
|
yield item
|
||||||
|
_show(i+1)
|
||||||
|
|
||||||
|
if not hide:
|
||||||
|
STREAM.write('\n')
|
||||||
|
STREAM.flush()
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
# -*- coding: utf8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
clint.textui.prompt
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Module for simple interactive prompts handling
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
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
|
||||||
+26
-1
@@ -9,10 +9,35 @@ Various Python helpers used within clint.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import sys
|
|
||||||
import errno
|
import errno
|
||||||
|
import os.path
|
||||||
from os import makedirs
|
from os import makedirs
|
||||||
|
from glob import glob
|
||||||
|
|
||||||
|
try:
|
||||||
|
basestring
|
||||||
|
except NameError:
|
||||||
|
basestring = str
|
||||||
|
|
||||||
|
def expand_path(path):
|
||||||
|
"""Expands directories and globs in given path."""
|
||||||
|
|
||||||
|
paths = []
|
||||||
|
path = os.path.expanduser(path)
|
||||||
|
path = os.path.expandvars(path)
|
||||||
|
|
||||||
|
if os.path.isdir(path):
|
||||||
|
|
||||||
|
for (dir, dirs, files) in os.walk(path):
|
||||||
|
for file in files:
|
||||||
|
paths.append(os.path.join(dir, file))
|
||||||
|
else:
|
||||||
|
paths.extend(glob(path))
|
||||||
|
|
||||||
|
return paths
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def is_collection(obj):
|
def is_collection(obj):
|
||||||
|
|||||||
@@ -17,3 +17,4 @@ with indent(4, quote='>>>'):
|
|||||||
puts(colored.red('Grouped Arguments: ') + str(dict(args.grouped)))
|
puts(colored.red('Grouped Arguments: ') + str(dict(args.grouped)))
|
||||||
|
|
||||||
print
|
print
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -12,5 +14,5 @@ text = 'THIS TEXT IS COLORED %s!'
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
for color in colored.__all__:
|
for color in colored.COLORS:
|
||||||
print getattr(colored, color)(text % color.upper())
|
print(getattr(colored, color)(text % color.upper()))
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.abspath('..'))
|
||||||
|
|
||||||
|
from clint.eng import join
|
||||||
|
from clint.textui import colored, indent, puts
|
||||||
|
|
||||||
|
colors = [
|
||||||
|
colored.blue('blue'),
|
||||||
|
colored.red('red'),
|
||||||
|
colored.yellow('yellow'),
|
||||||
|
colored.green('green'),
|
||||||
|
colored.magenta('magenta')
|
||||||
|
]
|
||||||
|
|
||||||
|
colors = [str(cs) for cs in colors]
|
||||||
|
|
||||||
|
|
||||||
|
puts('Smart:')
|
||||||
|
with indent(4):
|
||||||
|
for i in range(len(colors)):
|
||||||
|
puts(join(colors[:i+1]))
|
||||||
|
puts('\n')
|
||||||
|
puts('Stupid:')
|
||||||
|
with indent(4):
|
||||||
|
for i in range(len(colors)):
|
||||||
|
puts(join(colors[:i+1], im_a_moron=True, conj='\'n'))
|
||||||
@@ -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)
|
||||||
|
|
||||||
Executable
+4
@@ -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
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -8,12 +8,20 @@ sys.path.insert(0, os.path.abspath('..'))
|
|||||||
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from random import random
|
from random import random
|
||||||
from clint.textui import progressbar
|
from clint.textui import progress
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
for i in progressbar(range(100)):
|
for i in progress.bar(range(100)):
|
||||||
sleep(random() * 0.2)
|
sleep(random() * 0.2)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -13,16 +15,16 @@ resources.init('kennethreitz', 'clint')
|
|||||||
lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
|
lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
|
||||||
|
|
||||||
|
|
||||||
print '%s created.' % resources.user.path
|
print('%s created.' % resources.user.path)
|
||||||
|
|
||||||
resources.user.write('lorem.txt', lorem)
|
resources.user.write('lorem.txt', lorem)
|
||||||
print 'lorem.txt created'
|
print('lorem.txt created')
|
||||||
|
|
||||||
assert resources.user.read('lorem.txt') == lorem
|
assert resources.user.read('lorem.txt') == lorem
|
||||||
print 'lorem.txt has correct contents'
|
print('lorem.txt has correct contents')
|
||||||
|
|
||||||
resources.user.delete('lorem.txt')
|
resources.user.delete('lorem.txt')
|
||||||
print 'lorem.txt deleted'
|
print('lorem.txt deleted')
|
||||||
|
|
||||||
assert resources.user.read('lorem.txt') == None
|
assert resources.user.read('lorem.txt') == None
|
||||||
print 'lorem.txt deletion confirmed'
|
print('lorem.txt deletion confirmed')
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import os
|
|||||||
sys.path.insert(0, os.path.abspath('..'))
|
sys.path.insert(0, os.path.abspath('..'))
|
||||||
|
|
||||||
from clint.textui import puts, colored
|
from clint.textui import puts, colored
|
||||||
from clint.textui.columns import columns
|
from clint.textui import columns
|
||||||
|
|
||||||
lorem = 'Lorem ipsum dolor sit amet, consehdfhdfhdfhdfhdfhctetur adi pisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
|
lorem = 'Lorem ipsum dolor sit amet, consehdfhdfhdfhdfhdfhctetur adi pisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
|
||||||
|
|
||||||
@@ -19,5 +19,6 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
col = 60
|
col = 60
|
||||||
|
|
||||||
puts(columns([(colored.red('Column 1')), col], [(colored.green('Column Two')), None], [(colored.magenta('Column III')), col]))
|
puts(columns([(colored.red('Column 1')), col], [(colored.green('Column Two')), None],
|
||||||
|
[(colored.magenta('Column III')), col]))
|
||||||
puts(columns(['hi there my name is kenneth and this is a columns', col], [lorem, None], ['kenneths', col]))
|
puts(columns(['hi there my name is kenneth and this is a columns', col], [lorem, None], ['kenneths', col]))
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"title": "Bashō's 'old pond'",
|
||||||
|
"text": "古池や蛙飛込む水の音"
|
||||||
|
}
|
||||||
@@ -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))
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
python unicode.py こんにちは。 unicode.json < unicode.json
|
||||||
@@ -4,7 +4,13 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from distutils.core import setup
|
try:
|
||||||
|
from setuptools import setup
|
||||||
|
except ImportError:
|
||||||
|
from distutils.core import setup
|
||||||
|
|
||||||
|
import clint
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def publish():
|
def publish():
|
||||||
@@ -15,35 +21,41 @@ if sys.argv[-1] == "publish":
|
|||||||
publish()
|
publish()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
required = []
|
required = ['args']
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='clint',
|
name='clint',
|
||||||
version='0.1.2',
|
version=clint.__version__,
|
||||||
description='Python Command-line Application Tools',
|
description='Python Command-line Application Tools',
|
||||||
long_description=open('README.rst').read() + '\n\n' +
|
long_description=open('README.rst').read() + '\n\n' +
|
||||||
open('HISTORY.rst').read(),
|
open('HISTORY.rst').read(),
|
||||||
author='Kenneth Reitz',
|
author='Kenneth Reitz',
|
||||||
author_email='me@kennethreitz.com',
|
author_email='me@kennethreitz.com',
|
||||||
url='https://github.com/kennethreitz/clint',
|
url='https://github.com/kennethreitz/clint',
|
||||||
|
data_files=[
|
||||||
|
'README.rst',
|
||||||
|
'HISTORY.rst',
|
||||||
|
],
|
||||||
packages= [
|
packages= [
|
||||||
'clint',
|
'clint',
|
||||||
'clint.textui',
|
'clint.textui',
|
||||||
|
|
||||||
'clint.packages', 'clint.packages.colorama'
|
'clint.packages', 'clint.packages.colorama'
|
||||||
],
|
],
|
||||||
install_requires=required,
|
install_requires=required,
|
||||||
license='ISC',
|
license='ISC',
|
||||||
classifiers=(
|
classifiers=(
|
||||||
# 'Development Status :: 5 - Production/Stable',
|
# 'Development Status :: 5 - Production/Stable',
|
||||||
|
'Environment :: Console',
|
||||||
'Intended Audience :: Developers',
|
'Intended Audience :: Developers',
|
||||||
'Natural Language :: English',
|
'Natural Language :: English',
|
||||||
'License :: OSI Approved :: ISC License (ISCL)',
|
'License :: OSI Approved :: ISC License (ISCL)',
|
||||||
'Programming Language :: Python',
|
'Programming Language :: Python',
|
||||||
# 'Programming Language :: Python :: 2.5',
|
'Programming Language :: Python :: 2',
|
||||||
'Programming Language :: Python :: 2.6',
|
'Programming Language :: Python :: 2.6',
|
||||||
'Programming Language :: Python :: 2.7',
|
'Programming Language :: Python :: 2.7',
|
||||||
# 'Programming Language :: Python :: 3.0',
|
'Programming Language :: Python :: 3',
|
||||||
# 'Programming Language :: Python :: 3.1',
|
'Programming Language :: Python :: 3.1',
|
||||||
|
'Programming Language :: Python :: 3.2',
|
||||||
|
'Topic :: Terminals :: Terminal Emulators/X Terminals',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
+28
-2
@@ -6,8 +6,8 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
class TablibTestCase(unittest.TestCase):
|
class ClintTestCase(unittest.TestCase):
|
||||||
"""Tablib test cases."""
|
"""Clint test cases."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
import clint
|
import clint
|
||||||
@@ -16,5 +16,31 @@ class TablibTestCase(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user