summaryrefslogtreecommitdiffstats
path: root/external_libs/python/termstyle
diff options
context:
space:
mode:
Diffstat (limited to 'external_libs/python/termstyle')
-rw-r--r--external_libs/python/termstyle/MANIFEST.in1
-rw-r--r--external_libs/python/termstyle/Makefile9
-rw-r--r--external_libs/python/termstyle/README.rst82
-rw-r--r--external_libs/python/termstyle/VERSION1
-rw-r--r--external_libs/python/termstyle/__init__.py0
-rw-r--r--external_libs/python/termstyle/python-termstyle.xml183
-rw-r--r--external_libs/python/termstyle/setup.py27
-rw-r--r--external_libs/python/termstyle/termstyle.py107
-rw-r--r--external_libs/python/termstyle/test2.py5
-rw-r--r--external_libs/python/termstyle/test3.py5
-rw-r--r--external_libs/python/termstyle/test_all.sh4
11 files changed, 424 insertions, 0 deletions
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
--- /dev/null
+++ b/external_libs/python/termstyle/__init__.py
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 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type='text/xsl' href='interface.xsl'?>
+<interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface" uri="http://gfxmonk.net/dist/0install/python-termstyle.xml">
+ <name>termstyle</name>
+ <summary>console colouring for python</summary>
+ <homepage>http://github.com/gfxmonk/termstyle</homepage>
+ <description>
+=========
+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/
+
+ </description>
+ <pypi-extra xmlns="http://gfxmonk.net/dist/0install"><![CDATA[
+ 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',
+ ]]></pypi-extra>
+ <rich-description xmlns="http://gfxmonk.net/dist/0install">
+ <div xmlns="http://www.w3.org/1999/xhtml">
+ <h1 id="termstyle">termstyle</h1>
+ <p>termstyle is a simple python library for adding coloured output to terminal (console) programs. The definitions come from <a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf">ECMA-048</a>, the "Control Functions for Coded Character Sets" standard.</p>
+ <h2 id="installation">Installation:</h2>
+ <p>I thoroughly recommend using the zero-install feed (see the project homepage) to manage your dependencies if at all possible. <a href="http://0install.net/">zero-install</a> 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.</p>
+ <h2 id="example-usage">Example Usage:</h2>
+ <pre><code>from termstyle import *
+print "%s:%s" % (red('Hey'), green('how are you?'))
+print blue('How ', bold('you'), ' doin?')
+</code></pre>
+ <p>or, you can use a colour just as a string:</p>
+ <pre><code>print "%sBlue!%s" % (blue, reset)
+</code></pre>
+ <h2 id="styles">Styles:</h2>
+ <pre><code>reset or default (no colour / style)
+</code></pre>
+ <p>colour:</p>
+ <pre><code>black
+red
+green
+yellow
+blue
+magenta
+cyan
+white
+</code></pre>
+ <p>background colour:</p>
+ <pre><code>bg_black
+bg_red
+bg_green
+bg_yellow
+bg_blue
+bg_magenta
+bg_cyan
+bg_white
+bg_default
+</code></pre>
+ <p>In terminals supporting transparency <code>bg_default</code> is often used to set the background to transparent [#]_.</p>
+ <p>weight:</p>
+ <pre><code>bold
+inverted
+</code></pre>
+ <p>style:</p>
+ <pre><code>italic
+underscore
+</code></pre>
+ <h2 id="controls">Controls:</h2>
+ <pre><code>auto() - sets colouring on only if sys.stdout is a terminal
+disabe() - disable colours
+enable() - enable colours
+</code></pre>
+ </div>
+ </rich-description>
+ <group>
+ <environment insert="" mode="prepend" name="PYTHONPATH"/>
+ <implementation id="sha1new=1f5b66dcd48fa38740aa98bb2796f0adb7eeab04" released="2010-07-18" version="0.1.5">
+ <manifest-digest sha256="9b0ff9b07c1d424484b5aa20fc2db7827a372d84515e8caf46b005f54a034e07"/>
+ <archive href="http://gfxmonk.net/dist/0install/python-termstyle/python-termstyle-0.1.2.tgz" size="3114"/>
+ </implementation>
+ <implementation id="sha1new=9f728d8ba0eb5379c907b85a9662c54935f1e0ca" released="2010-11-05" version="0.1.6">
+ <manifest-digest sha256="a7283c6fe262bc88ed270a91304da243c474d32353c2c9d6c6f4003bacfce27c"/>
+ <archive href="http://gfxmonk.net/dist/0install/python-termstyle/python-termstyle-0.1.6.tgz" size="3607"/>
+ </implementation>
+ <implementation id="sha1new=93d781ad4b723d154462f990254f78d3bab7456e" released="2011-01-29" version="0.1.7">
+ <manifest-digest sha256="31488cd005a3f9182e6738068a5e9ddfd6d28db370d8b0a0b16d5bbc53048665"/>
+ <archive href="http://gfxmonk.net/dist/0install/python-termstyle/python-termstyle-0.1.7.tgz" size="4265"/>
+ </implementation>
+ <implementation id="sha1new=ada58698e40a6f11b40dbebaa11f70061b47172d" released="2011-03-15" version="0.1.8">
+ <manifest-digest sha256="cbcee0509b194eec74a5fe923999b505293c5d0a20b3d79203fa6f47a942b24e"/>
+ <archive href="http://gfxmonk.net/dist/0install/python-termstyle/python-termstyle-0.1.8.tgz" size="4312"/>
+ </implementation>
+ <implementation id="sha1new=e718d149b78028f3ac39ee4de42e0b7644ad48fb" released="2011-03-16" version="0.1.9">
+ <manifest-digest sha256="ee3dc9b097ac0b7682fab8753a5dab45f0a9c189544c13a369ada8b9e1f4fde8"/>
+ <archive href="http://gfxmonk.net/dist/0install/python-termstyle/python-termstyle-0.1.9.tgz" size="2901"/>
+ </implementation>
+ <implementation id="sha1new=0c4adef2eccc7ddcb48264c4bc2d84fcfa1072a4" released="2011-04-30" version="0.1.10">
+ <manifest-digest sha256="df3b9e11077995f515239eb8382acdfa1741c35e867916917cf70ce53e49bd59"/>
+ <archive href="http://gfxmonk.net/dist/0install/python-termstyle/python-termstyle-0.1.10.tgz" size="2903"/>
+ </implementation>
+ </group>
+</interface>
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 <http://gfxmonk.net/dist/0install/zero2pypi.xml>`_.\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