colorclass


Namecolorclass JSON
Version 2.2.2 PyPI version JSON
download
home_pagehttps://github.com/matthewdeanmartin/colorclass
SummaryColorful worry-free console applications for Linux, Mac OS X, and Windows.
upload_time2021-12-09 00:41:35
maintainer
docs_urlNone
authorRobpol86
requires_python>=2.6
licenseMIT
keywords shell bash ansi ascii terminal console colors automatic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # colorclass

Yet another ANSI color text library for Python. Provides "auto colors" for dark/light terminals. Works on Linux, OS X,
and Windows. For Windows support you just need to call ``Windows.enable()`` in your application.

On Linux/OS X ``autocolors`` are toggled by calling ``set_light_background()`` and ``set_dark_background()``. On Windows
this can be done automatically if you call ``Windows.enable(auto_colors=True)``. Even though the latest Windows 10 does
support ANSI color codes natively, you still need to run Windows.enable() to take advantage of automatically detecting
the console's background color.

In Python2.x this library subclasses ``unicode``, while on Python3.x it subclasses ``str``.

* Python 2.6, 2.7, PyPy, PyPy3, 3.3, 3.4, and 3.5 supported on Linux and OS X.
* Python 2.6, 2.7, 3.3, 3.4, and 3.5 supported on Windows (both 32 and 64 bit versions of Python).

## Quickstart
Install:
```bash
    pip install colorclass
```

## Piped Command Line
It is possible to pipe curly-bracket tagged (or regular ANSI coded) text to Python in the command line to produce color
text. Some examples:

```bash
    echo "{red}Red{/red}" |python -m colorclass  # Red colored text.
    echo -e "\033[31mRed\033[0m" | COLOR_DISABLE=true python -m colorclass  # Strip colors
    echo -e "\033[31mRed\033[0m" | COLOR_ENABLE=true python -m colorclass &> file.txt  # Force colors.
```
Export these environment variables as "true" to enable/disable some features:

    =============== ============================================
    Env Variable    Description
    =============== ============================================
    COLOR_ENABLE    Force colors even when piping to a file.
    COLOR_DISABLE   Strip all colors from incoming text.
    COLOR_LIGHT     Use light colored text for dark backgrounds.
    COLOR_DARK      Use dark colored text for light backgrounds.
    =============== ============================================

## Example Implementation

![Example Script Screenshot](https://github.com/Robpol86/colorclass/raw/master/example.png?raw=true)

![Example Windows Screenshot](https://github.com/Robpol86/colorclass/raw/master/example_windows.png?raw=true)

Source code for the example code is: [example.py](https://github.com/Robpol86/colorclass/blob/master/example.py)

## Usage

Different colors are chosen using curly-bracket tags, such as ``{red}{/red}``. For a list of available colors, call
``colorclass.list_tags()``.

The available "auto colors" tags are:

* autoblack
* autored
* autogreen
* autoyellow
* autoblue
* automagenta
* autocyan
* autowhite
* autobgblack
* autobgred
* autobggreen
* autobgyellow
* autobgblue
* autobgmagenta
* autobgcyan
* autobgwhite

Methods of Class instances try to return sane data, such as:

```python
    from colorclass import Color
    color_string = Color('{red}Test{/red}')

    >>> color_string
    u'\x1b[31mTest\x1b[39m'

    >>> len(color_string)
    4

    >>> color_string.istitle()
    True
```
There are also a couple of helper attributes for all Color instances:

```python
    >>> color_string.value_colors
    '\x1b[31mTest\x1b[39m'

    >>> color_string.value_no_colors
    'Test'
```

[Change Log](https://github.com/matthewdeanmartin/colorclass/blob/master/CHANGELOG.md)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/matthewdeanmartin/colorclass",
    "name": "colorclass",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.6",
    "maintainer_email": "",
    "keywords": "Shell,Bash,ANSI,ASCII,terminal,console,colors,automatic",
    "author": "Robpol86",
    "author_email": "robpol86@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d7/1a/31ff00a33569a3b59d65bbdc445c73e12f92ad28195b7ace299f68b9af70/colorclass-2.2.2.tar.gz",
    "platform": "",
    "description": "# colorclass\n\nYet another ANSI color text library for Python. Provides \"auto colors\" for dark/light terminals. Works on Linux, OS X,\nand Windows. For Windows support you just need to call ``Windows.enable()`` in your application.\n\nOn Linux/OS X ``autocolors`` are toggled by calling ``set_light_background()`` and ``set_dark_background()``. On Windows\nthis can be done automatically if you call ``Windows.enable(auto_colors=True)``. Even though the latest Windows 10 does\nsupport ANSI color codes natively, you still need to run Windows.enable() to take advantage of automatically detecting\nthe console's background color.\n\nIn Python2.x this library subclasses ``unicode``, while on Python3.x it subclasses ``str``.\n\n* Python 2.6, 2.7, PyPy, PyPy3, 3.3, 3.4, and 3.5 supported on Linux and OS X.\n* Python 2.6, 2.7, 3.3, 3.4, and 3.5 supported on Windows (both 32 and 64 bit versions of Python).\n\n## Quickstart\nInstall:\n```bash\n    pip install colorclass\n```\n\n## Piped Command Line\nIt is possible to pipe curly-bracket tagged (or regular ANSI coded) text to Python in the command line to produce color\ntext. Some examples:\n\n```bash\n    echo \"{red}Red{/red}\" |python -m colorclass  # Red colored text.\n    echo -e \"\\033[31mRed\\033[0m\" | COLOR_DISABLE=true python -m colorclass  # Strip colors\n    echo -e \"\\033[31mRed\\033[0m\" | COLOR_ENABLE=true python -m colorclass &> file.txt  # Force colors.\n```\nExport these environment variables as \"true\" to enable/disable some features:\n\n    =============== ============================================\n    Env Variable    Description\n    =============== ============================================\n    COLOR_ENABLE    Force colors even when piping to a file.\n    COLOR_DISABLE   Strip all colors from incoming text.\n    COLOR_LIGHT     Use light colored text for dark backgrounds.\n    COLOR_DARK      Use dark colored text for light backgrounds.\n    =============== ============================================\n\n## Example Implementation\n\n![Example Script Screenshot](https://github.com/Robpol86/colorclass/raw/master/example.png?raw=true)\n\n![Example Windows Screenshot](https://github.com/Robpol86/colorclass/raw/master/example_windows.png?raw=true)\n\nSource code for the example code is: [example.py](https://github.com/Robpol86/colorclass/blob/master/example.py)\n\n## Usage\n\nDifferent colors are chosen using curly-bracket tags, such as ``{red}{/red}``. For a list of available colors, call\n``colorclass.list_tags()``.\n\nThe available \"auto colors\" tags are:\n\n* autoblack\n* autored\n* autogreen\n* autoyellow\n* autoblue\n* automagenta\n* autocyan\n* autowhite\n* autobgblack\n* autobgred\n* autobggreen\n* autobgyellow\n* autobgblue\n* autobgmagenta\n* autobgcyan\n* autobgwhite\n\nMethods of Class instances try to return sane data, such as:\n\n```python\n    from colorclass import Color\n    color_string = Color('{red}Test{/red}')\n\n    >>> color_string\n    u'\\x1b[31mTest\\x1b[39m'\n\n    >>> len(color_string)\n    4\n\n    >>> color_string.istitle()\n    True\n```\nThere are also a couple of helper attributes for all Color instances:\n\n```python\n    >>> color_string.value_colors\n    '\\x1b[31mTest\\x1b[39m'\n\n    >>> color_string.value_no_colors\n    'Test'\n```\n\n[Change Log](https://github.com/matthewdeanmartin/colorclass/blob/master/CHANGELOG.md)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Colorful worry-free console applications for Linux, Mac OS X, and Windows.",
    "version": "2.2.2",
    "split_keywords": [
        "shell",
        "bash",
        "ansi",
        "ascii",
        "terminal",
        "console",
        "colors",
        "automatic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "7e83bff652ee0cc93d77b3d8b1c8beec",
                "sha256": "6f10c273a0ef7a1150b1120b6095cbdd68e5cf36dfd5d0fc957a2500bbf99a55"
            },
            "downloads": -1,
            "filename": "colorclass-2.2.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7e83bff652ee0cc93d77b3d8b1c8beec",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=2.6",
            "size": 18995,
            "upload_time": "2021-12-09T00:41:34",
            "upload_time_iso_8601": "2021-12-09T00:41:34.653140Z",
            "url": "https://files.pythonhosted.org/packages/30/b6/daf3e2976932da4ed3579cff7a30a53d22ea9323ee4f0d8e43be60454897/colorclass-2.2.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "b5003ff65d4956fed23cb848e1611906",
                "sha256": "6d4fe287766166a98ca7bc6f6312daf04a0481b1eda43e7173484051c0ab4366"
            },
            "downloads": -1,
            "filename": "colorclass-2.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b5003ff65d4956fed23cb848e1611906",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.6",
            "size": 16709,
            "upload_time": "2021-12-09T00:41:35",
            "upload_time_iso_8601": "2021-12-09T00:41:35.661966Z",
            "url": "https://files.pythonhosted.org/packages/d7/1a/31ff00a33569a3b59d65bbdc445c73e12f92ad28195b7ace299f68b9af70/colorclass-2.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-12-09 00:41:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "matthewdeanmartin",
    "github_project": "colorclass",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "colorclass"
}
        
Elapsed time: 0.08266s