From d3f26ece7d4383df0b22fe9c3cb3e695381ec737 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Mon, 24 Aug 2015 10:51:13 +0300 Subject: Initial push to external_lib migration --- external_libs/python/termstyle/MANIFEST.in | 1 + external_libs/python/termstyle/Makefile | 9 + external_libs/python/termstyle/README.rst | 82 +++++++++ external_libs/python/termstyle/VERSION | 1 + external_libs/python/termstyle/__init__.py | 0 .../python/termstyle/python-termstyle.xml | 183 +++++++++++++++++++++ external_libs/python/termstyle/setup.py | 27 +++ external_libs/python/termstyle/termstyle.py | 107 ++++++++++++ external_libs/python/termstyle/test2.py | 5 + external_libs/python/termstyle/test3.py | 5 + external_libs/python/termstyle/test_all.sh | 4 + 11 files changed, 424 insertions(+) create mode 100644 external_libs/python/termstyle/MANIFEST.in create mode 100644 external_libs/python/termstyle/Makefile create mode 100644 external_libs/python/termstyle/README.rst create mode 100644 external_libs/python/termstyle/VERSION create mode 100644 external_libs/python/termstyle/__init__.py create mode 100644 external_libs/python/termstyle/python-termstyle.xml create mode 100644 external_libs/python/termstyle/setup.py create mode 100644 external_libs/python/termstyle/termstyle.py create mode 100644 external_libs/python/termstyle/test2.py create mode 100644 external_libs/python/termstyle/test3.py create mode 100644 external_libs/python/termstyle/test_all.sh (limited to 'external_libs/python/termstyle') diff --git a/external_libs/python/termstyle/MANIFEST.in b/external_libs/python/termstyle/MANIFEST.in new file mode 100644 index 00000000..14dafaf3 --- /dev/null +++ b/external_libs/python/termstyle/MANIFEST.in @@ -0,0 +1 @@ +include test* diff --git a/external_libs/python/termstyle/Makefile b/external_libs/python/termstyle/Makefile new file mode 100644 index 00000000..02151dca --- /dev/null +++ b/external_libs/python/termstyle/Makefile @@ -0,0 +1,9 @@ +0: + mkzero-gfxmonk \ + -v `cat VERSION` \ + -p termstyle.py \ + -p setup.py \ + python-termstyle.xml + +pypi: + ./setup.py register sdist upload diff --git a/external_libs/python/termstyle/README.rst b/external_libs/python/termstyle/README.rst new file mode 100644 index 00000000..f3dfa0ab --- /dev/null +++ b/external_libs/python/termstyle/README.rst @@ -0,0 +1,82 @@ +========= +termstyle +========= + +termstyle is a simple python library for adding coloured output to +terminal (console) programs. The definitions come from ECMA-048_, the +"Control Functions for Coded Character Sets" standard. + +Installation: +------------- + +I thoroughly recommend using the zero-install feed (see the project homepage) to manage your dependencies if at all possible. zero-install_ provides a much better system than pip or easy_install, and works with absolutely any language and allows decentralised package management that requires no special privileges to install. + +Example Usage: +-------------- +:: + + from termstyle import * + print "%s:%s" % (red('Hey'), green('how are you?')) + print blue('How ', bold('you'), ' doin?') + +or, you can use a colour just as a string:: + + print "%sBlue!%s" % (blue, reset) + +Styles: +------- +:: + + reset or default (no colour / style) + +colour:: + + black + red + green + yellow + blue + magenta + cyan + white + +background colour:: + + bg_black + bg_red + bg_green + bg_yellow + bg_blue + bg_magenta + bg_cyan + bg_white + bg_default + +In terminals supporting transparency ``bg_default`` is often used to set +the background to transparent [#]_. + +weight:: + + bold + inverted + +style:: + + italic + underscore + +Controls: +--------- +:: + + auto() - sets colouring on only if sys.stdout is a terminal + disabe() - disable colours + enable() - enable colours + +.. [#] Supporting terminals include rxvt-unicode_, and Eterm_. + +.. _ECMA-048: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf +.. _rxvt-unicode: http://software.schmorp.de/ +.. _Eterm: http://www.eterm.org/ +.. _zero-install: http://0install.net/ + diff --git a/external_libs/python/termstyle/VERSION b/external_libs/python/termstyle/VERSION new file mode 100644 index 00000000..345f8cc0 --- /dev/null +++ b/external_libs/python/termstyle/VERSION @@ -0,0 +1 @@ +0.1.10 \ No newline at end of file diff --git a/external_libs/python/termstyle/__init__.py b/external_libs/python/termstyle/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/external_libs/python/termstyle/python-termstyle.xml b/external_libs/python/termstyle/python-termstyle.xml new file mode 100644 index 00000000..b6b08bd7 --- /dev/null +++ b/external_libs/python/termstyle/python-termstyle.xml @@ -0,0 +1,183 @@ + + + + termstyle + console colouring for python + http://github.com/gfxmonk/termstyle + +========= +termstyle +========= + +termstyle is a simple python library for adding coloured output to +terminal (console) programs. The definitions come from ECMA-048_, the +"Control Functions for Coded Character Sets" standard. + +Installation: +------------- + +I thoroughly recommend using the zero-install feed (see the project homepage) to manage your dependencies if at all possible. zero-install_ provides a much better system than pip or easy_install, and works with absolutely any language and allows decentralised package management that requires no special privileges to install. + +Example Usage: +-------------- +:: + + from termstyle import * + print "%s:%s" % (red('Hey'), green('how are you?')) + print blue('How ', bold('you'), ' doin?') + +or, you can use a colour just as a string:: + + print "%sBlue!%s" % (blue, reset) + +Styles: +------- +:: + + reset or default (no colour / style) + +colour:: + + black + red + green + yellow + blue + magenta + cyan + white + +background colour:: + + bg_black + bg_red + bg_green + bg_yellow + bg_blue + bg_magenta + bg_cyan + bg_white + bg_default + +In terminals supporting transparency ``bg_default`` is often used to set +the background to transparent [#]_. + +weight:: + + bold + inverted + +style:: + + italic + underscore + +Controls: +--------- +:: + + auto() - sets colouring on only if sys.stdout is a terminal + disabe() - disable colours + enable() - enable colours + +.. [#] Supporting terminals include rxvt-unicode_, and Eterm_. + +.. _ECMA-048: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf +.. _rxvt-unicode: http://software.schmorp.de/ +.. _Eterm: http://www.eterm.org/ +.. _zero-install: http://0install.net/ + + + + +
+

termstyle

+

termstyle is a simple python library for adding coloured output to terminal (console) programs. The definitions come from ECMA-048, the "Control Functions for Coded Character Sets" standard.

+

Installation:

+

I thoroughly recommend using the zero-install feed (see the project homepage) to manage your dependencies if at all possible. zero-install provides a much better system than pip or easy_install, and works with absolutely any language and allows decentralised package management that requires no special privileges to install.

+

Example Usage:

+
from termstyle import *
+print "%s:%s" % (red('Hey'), green('how are you?'))
+print blue('How ', bold('you'), ' doin?')
+
+

or, you can use a colour just as a string:

+
print "%sBlue!%s" % (blue, reset)
+
+

Styles:

+
reset or default (no colour / style)
+
+

colour:

+
black
+red
+green
+yellow
+blue
+magenta
+cyan
+white
+
+

background colour:

+
bg_black
+bg_red
+bg_green
+bg_yellow
+bg_blue
+bg_magenta
+bg_cyan
+bg_white
+bg_default
+
+

In terminals supporting transparency bg_default is often used to set the background to transparent [#]_.

+

weight:

+
bold
+inverted
+
+

style:

+
italic
+underscore
+
+

Controls:

+
auto() - sets colouring on only if sys.stdout is a terminal
+disabe() - disable colours
+enable() - enable colours
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/external_libs/python/termstyle/setup.py b/external_libs/python/termstyle/setup.py new file mode 100644 index 00000000..69b11cbb --- /dev/null +++ b/external_libs/python/termstyle/setup.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +## NOTE: ## +## this setup.py was generated by zero2pypi: +## http://gfxmonk.net/dist/0install/zero2pypi.xml + +from setuptools import * +setup( + packages = find_packages(exclude=['test', 'test.*']), + install_requires=['setuptools'], + version='0.1.10', + url='http://gfxmonk.net/dist/0install/python-termstyle.xml', + description='console colouring for python', + long_description='\n**Note**: This package has been built automatically by\n`zero2pypi `_.\nIf possible, you should use the zero-install feed instead:\nhttp://gfxmonk.net/dist/0install/python-termstyle.xml\n\n----------------\n\n=========\ntermstyle\n=========\n\ntermstyle is a simple python library for adding coloured output to\nterminal (console) programs. The definitions come from ECMA-048_, the\n"Control Functions for Coded Character Sets" standard.\n\nInstallation:\n-------------\n\nI thoroughly recommend using the zero-install feed (see the project homepage) to manage your dependencies if at all possible. zero-install_ provides a much better system than pip or easy_install, and works with absolutely any language and allows decentralised package management that requires no special privileges to install.\n\nExample Usage:\n--------------\n::\n\n\tfrom termstyle import *\n\tprint "%s:%s" % (red(\'Hey\'), green(\'how are you?\'))\n\tprint blue(\'How \', bold(\'you\'), \' doin?\')\n\nor, you can use a colour just as a string::\n\n\tprint "%sBlue!%s" % (blue, reset)\n\nStyles:\n-------\n::\n\n\treset or default (no colour / style)\n\ncolour::\n\n\tblack\n\tred\n\tgreen\n\tyellow\n\tblue\n\tmagenta\n\tcyan\n\twhite\n\nbackground colour::\n\n\tbg_black\n\tbg_red\n\tbg_green\n\tbg_yellow\n\tbg_blue\n\tbg_magenta\n\tbg_cyan\n\tbg_white\n\tbg_default\n\nIn terminals supporting transparency ``bg_default`` is often used to set\nthe background to transparent [#]_.\n\nweight::\n\n\tbold\n\tinverted\n\nstyle::\n\n\titalic\n\tunderscore\n\nControls:\n---------\n::\n\n\tauto() - sets colouring on only if sys.stdout is a terminal\n\tdisabe() - disable colours\n\tenable() - enable colours\n\n.. [#] Supporting terminals include rxvt-unicode_, and Eterm_.\n\n.. _ECMA-048: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf\n.. _rxvt-unicode: http://software.schmorp.de/\n.. _Eterm: http://www.eterm.org/\n.. _zero-install: http://0install.net/\n', + name='python-termstyle', + download_url='http://gfxmonk.net/dist/0install/python-termstyle/python-termstyle-0.1.10.tgz', + py_modules=['termstyle'], +classifiers=[ + "License :: OSI Approved :: BSD License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + keywords='output colour console ansi', + license='BSD', +) diff --git a/external_libs/python/termstyle/termstyle.py b/external_libs/python/termstyle/termstyle.py new file mode 100644 index 00000000..62a3a920 --- /dev/null +++ b/external_libs/python/termstyle/termstyle.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python +# Copyright (c) 2009, Tim Cuthbertson +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the organisation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY +# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +import sys + +class Style(object): + prefix='\x1b[' + suffix='m' + enabled = True + + def __init__(self, on_codes, off_codes = 0): + self._on = self.sequence(on_codes) + self._off = self.sequence(off_codes) + + def _get_on(self): return self._on if self.enabled else '' + def _get_off(self): return self._off if self.enabled else '' + on = property(_get_on) + off = property(_get_off) + + @classmethod + def sequence(cls, codes): + wrap_single = lambda code: "%s%s%s" % (cls.prefix, code, cls.suffix) + try: + return ''.join([wrap_single(code) for code in codes]) + except TypeError: + return wrap_single(codes) + + def __str__(self): + if not self.enabled: + return '' + return self.on + + def __call__(self, *args): + contents = ''.join(["%s%s" % (self.on, arg) for arg in args]) + return "%s%s" % (contents, self.off) + + +def auto(): + """set colouring on if STDOUT is a terminal device, off otherwise""" + try: + Style.enabled = False + Style.enabled = sys.stdout.isatty() + except (AttributeError, TypeError): + pass + +def enable(): + """force coloured output""" + Style.enabled = True + +def disable(): + """disable coloured output""" + Style.enabled = False + +default = reset = Style(0) + +black = Style(30) +red = Style(31) +green = Style(32) +yellow = Style(33) +blue = Style(34) +magenta = Style(35) +cyan = Style(36) +white = Style(37) + +bg_black = Style(40) +bg_red = Style(41) +bg_green = Style(42) +bg_yellow = Style(43) +bg_blue = Style(44) +bg_magenta = Style(45) +bg_cyan = Style(46) +bg_white = Style(47) +bg_default = Style(49) + +bold = Style(1) +underscore = Style(4) +inverted = Style(7) +italic = Style(3) + diff --git a/external_libs/python/termstyle/test2.py b/external_libs/python/termstyle/test2.py new file mode 100644 index 00000000..2d84c375 --- /dev/null +++ b/external_libs/python/termstyle/test2.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python2 + +from termstyle import * + +print green(u"unicod\xe9!") diff --git a/external_libs/python/termstyle/test3.py b/external_libs/python/termstyle/test3.py new file mode 100644 index 00000000..861c44f9 --- /dev/null +++ b/external_libs/python/termstyle/test3.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +from termstyle import * + +print(green("unicod\xe9!")) diff --git a/external_libs/python/termstyle/test_all.sh b/external_libs/python/termstyle/test_all.sh new file mode 100644 index 00000000..d28545a9 --- /dev/null +++ b/external_libs/python/termstyle/test_all.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -ex +./test2.py +./test3.py -- cgit 1.2.3-korg