object-colors


Nameobject-colors JSON
Version 2.3.1 PyPI version JSON
download
home_pagehttps://pypi.org/project/object-colors/
SummaryObject-oriented library for stylizing terminal output
upload_time2023-09-24 01:36:39
maintainerjshwi
docs_urlNone
authorjshwi
requires_python>=3.8,<4.0
licenseMIT
keywords ansi color oop terminal tty
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            object-colors
=============
.. image:: https://img.shields.io/badge/License-MIT-yellow.svg
    :target: https://opensource.org/licenses/MIT
    :alt: License
.. image:: https://img.shields.io/pypi/v/object-colors
    :target: https://pypi.org/project/object-colors/
    :alt: PyPI
.. image:: https://github.com/jshwi/object-colors/actions/workflows/build.yaml/badge.svg
    :target: https://github.com/jshwi/object-colors/actions/workflows/build.yaml
    :alt: CI
.. image:: https://github.com/jshwi/object-colors/actions/workflows/codeql-analysis.yml/badge.svg
    :target: https://github.com/jshwi/object-colors/actions/workflows/codeql-analysis.yml
    :alt: CodeQL
.. image:: https://results.pre-commit.ci/badge/github/jshwi/object-colors/master.svg
   :target: https://results.pre-commit.ci/latest/github/jshwi/object-colors/master
   :alt: pre-commit.ci status
.. image:: https://codecov.io/gh/jshwi/object-colors/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/jshwi/object-colors
    :alt: codecov.io
.. image:: https://readthedocs.org/projects/object-colors/badge/?version=latest
    :target: https://object-colors.readthedocs.io/en/latest/?badge=latest
    :alt: readthedocs.org
.. image:: https://img.shields.io/badge/python-3.8-blue.svg
    :target: https://www.python.org/downloads/release/python-380
    :alt: python3.8
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black
    :alt: Black
.. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336
    :target: https://pycqa.github.io/isort/
    :alt: isort
.. image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg
    :target: https://github.com/PyCQA/docformatter
    :alt: docformatter
.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen
    :target: https://github.com/PyCQA/pylint
    :alt: pylint
.. image:: https://img.shields.io/badge/security-bandit-yellow.svg
    :target: https://github.com/PyCQA/bandit
    :alt: Security Status
.. image:: https://snyk.io/test/github/jshwi/object-colors/badge.svg
    :target: https://snyk.io/test/github/jshwi/object-colors/badge.svg
    :alt: Known Vulnerabilities
.. image:: https://snyk.io/advisor/python/object-colors/badge.svg
    :target: https://snyk.io/advisor/python/object-colors
    :alt: object-colors

Object-oriented library for stylizing terminal output
-----------------------------------------------------

Installation
------------

.. code-block:: console

    $ pip install object-colors
..

Usage
-----

Import the ``Color`` object from ``object_colors``

.. code-block:: python

    >>> from object_colors import Color

Args can be provided as strings or as indices corresponding to their index in an ANSI escape sequence

.. code-block:: python

    >>> Color(effect="bold", fore="red", back="green")
    Color(effect=1, fore=1, back=2, objects())

The following would yield the same result

.. code-block:: python

    >>> Color(effect=1, fore=1, back=2)
    Color(effect=1, fore=1, back=2, objects())

The above options are part of the below mapping

.. code-block:: python

    >>> for i, c in enumerate(Color.colors):
    ...     print(i, c)
    0 black
    1 red
    2 green
    3 yellow
    4 blue
    5 magenta
    6 cyan
    7 white

.. code-block:: python

    >>> for i, e in enumerate(Color.effects):
    ...     print(i, e)
    0 none
    1 bold
    2 dim
    3 italic
    4 underline
    5 blink
    6 blinking
    7 negative
    8 empty
    9 strikethrough


To configure the current object either ``effect``, ``fore``, or ``back`` can be provided

They must be an ``int``, ``str``, or ``None`` type

.. code-block:: python

    >>> c = Color()
    >>> c.set(effect="bold", fore="red", back="red")
    >>> c
    Color(effect=1, fore=1, back=1, objects())

Create new objects with by providing a ``dict`` object with any keyword argument

Use ``set`` to set multiple parameters

.. code-block:: python

    >>> c = Color()
    >>> c.set(bold_green=dict(effect="bold", fore="green"))
    >>> c
    Color(effect=None, fore=None, back=None, objects(bold_green))

Return ``str`` or ``tuple`` using ``get``

.. code-block:: python

    >>> c = Color()
    >>> c.set(red=dict(fore="red"))
    >>> c.set(yellow=dict(fore="yellow"))
    >>> f"{c.red.get('*')} {c.yellow.get('Warning')}"
    '\x1b[31m*\x1b[0;0m \x1b[33mWarning\x1b[0;0m'

.. code-block:: python

    >>> c = Color()
    >>> c.set(red=dict(fore="red"))
    >>> xyz = c.red.get("x", "y", "z")
    >>> xyz
    ('\x1b[31mx\x1b[0;0m', '\x1b[31my\x1b[0;0m', '\x1b[31mz\x1b[0;0m')
    >>> x, y, z = xyz
    >>> f"{x} {y} {z}"
    '\x1b[31mx\x1b[0;0m \x1b[31my\x1b[0;0m \x1b[31mz\x1b[0;0m'

Print the result using ``print``

.. code-block:: python

    >>> c = Color(effect="bold", fore="cyan")
    >>> # doctest strips ansi codes from print
    >>> c.print("bold cyan")  # '\x1b[1;36mbold cyan\x1b[0;0m'
    bold cyan

Load all ``effect``, ``fore``, or ``back`` elements using ``populate()``

.. code-block:: python

    >>> c = Color()
    >>> c.populate("fore")
    >>> c
    Color(effect=None, fore=None, back=None, objects(black, red, green, yellow, blue, magenta, cyan, white))

.. code-block:: python

    >>> c = Color()
    >>> c.set(red=dict(fore="red"))
    >>> c.red.populate("effect")
    >>> c.red
    Color(effect=None, fore=1, back=None, objects(none, bold, dim, italic, underline, blink, blinking, negative, empty, strikethrough))
    >>> # doctest strips ansi codes from print
    >>> c.red.strikethrough.print("strikethrough red")  # '\x1b[9;31mstrikethrough red\x1b[0;0m'
    strikethrough red

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/object-colors/",
    "name": "object-colors",
    "maintainer": "jshwi",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "stephen@jshwisolutions.com",
    "keywords": "ansi,color,oop,terminal,tty",
    "author": "jshwi",
    "author_email": "stephen@jshwisolutions.com",
    "download_url": "https://files.pythonhosted.org/packages/a3/6a/bab560526a8749cf62c4c8d4f83c62358a8c46786966eb19af30329145bc/object_colors-2.3.1.tar.gz",
    "platform": null,
    "description": "object-colors\n=============\n.. image:: https://img.shields.io/badge/License-MIT-yellow.svg\n    :target: https://opensource.org/licenses/MIT\n    :alt: License\n.. image:: https://img.shields.io/pypi/v/object-colors\n    :target: https://pypi.org/project/object-colors/\n    :alt: PyPI\n.. image:: https://github.com/jshwi/object-colors/actions/workflows/build.yaml/badge.svg\n    :target: https://github.com/jshwi/object-colors/actions/workflows/build.yaml\n    :alt: CI\n.. image:: https://github.com/jshwi/object-colors/actions/workflows/codeql-analysis.yml/badge.svg\n    :target: https://github.com/jshwi/object-colors/actions/workflows/codeql-analysis.yml\n    :alt: CodeQL\n.. image:: https://results.pre-commit.ci/badge/github/jshwi/object-colors/master.svg\n   :target: https://results.pre-commit.ci/latest/github/jshwi/object-colors/master\n   :alt: pre-commit.ci status\n.. image:: https://codecov.io/gh/jshwi/object-colors/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/jshwi/object-colors\n    :alt: codecov.io\n.. image:: https://readthedocs.org/projects/object-colors/badge/?version=latest\n    :target: https://object-colors.readthedocs.io/en/latest/?badge=latest\n    :alt: readthedocs.org\n.. image:: https://img.shields.io/badge/python-3.8-blue.svg\n    :target: https://www.python.org/downloads/release/python-380\n    :alt: python3.8\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n    :alt: Black\n.. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336\n    :target: https://pycqa.github.io/isort/\n    :alt: isort\n.. image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg\n    :target: https://github.com/PyCQA/docformatter\n    :alt: docformatter\n.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen\n    :target: https://github.com/PyCQA/pylint\n    :alt: pylint\n.. image:: https://img.shields.io/badge/security-bandit-yellow.svg\n    :target: https://github.com/PyCQA/bandit\n    :alt: Security Status\n.. image:: https://snyk.io/test/github/jshwi/object-colors/badge.svg\n    :target: https://snyk.io/test/github/jshwi/object-colors/badge.svg\n    :alt: Known Vulnerabilities\n.. image:: https://snyk.io/advisor/python/object-colors/badge.svg\n    :target: https://snyk.io/advisor/python/object-colors\n    :alt: object-colors\n\nObject-oriented library for stylizing terminal output\n-----------------------------------------------------\n\nInstallation\n------------\n\n.. code-block:: console\n\n    $ pip install object-colors\n..\n\nUsage\n-----\n\nImport the ``Color`` object from ``object_colors``\n\n.. code-block:: python\n\n    >>> from object_colors import Color\n\nArgs can be provided as strings or as indices corresponding to their index in an ANSI escape sequence\n\n.. code-block:: python\n\n    >>> Color(effect=\"bold\", fore=\"red\", back=\"green\")\n    Color(effect=1, fore=1, back=2, objects())\n\nThe following would yield the same result\n\n.. code-block:: python\n\n    >>> Color(effect=1, fore=1, back=2)\n    Color(effect=1, fore=1, back=2, objects())\n\nThe above options are part of the below mapping\n\n.. code-block:: python\n\n    >>> for i, c in enumerate(Color.colors):\n    ...     print(i, c)\n    0 black\n    1 red\n    2 green\n    3 yellow\n    4 blue\n    5 magenta\n    6 cyan\n    7 white\n\n.. code-block:: python\n\n    >>> for i, e in enumerate(Color.effects):\n    ...     print(i, e)\n    0 none\n    1 bold\n    2 dim\n    3 italic\n    4 underline\n    5 blink\n    6 blinking\n    7 negative\n    8 empty\n    9 strikethrough\n\n\nTo configure the current object either ``effect``, ``fore``, or ``back`` can be provided\n\nThey must be an ``int``, ``str``, or ``None`` type\n\n.. code-block:: python\n\n    >>> c = Color()\n    >>> c.set(effect=\"bold\", fore=\"red\", back=\"red\")\n    >>> c\n    Color(effect=1, fore=1, back=1, objects())\n\nCreate new objects with by providing a ``dict`` object with any keyword argument\n\nUse ``set`` to set multiple parameters\n\n.. code-block:: python\n\n    >>> c = Color()\n    >>> c.set(bold_green=dict(effect=\"bold\", fore=\"green\"))\n    >>> c\n    Color(effect=None, fore=None, back=None, objects(bold_green))\n\nReturn ``str`` or ``tuple`` using ``get``\n\n.. code-block:: python\n\n    >>> c = Color()\n    >>> c.set(red=dict(fore=\"red\"))\n    >>> c.set(yellow=dict(fore=\"yellow\"))\n    >>> f\"{c.red.get('*')} {c.yellow.get('Warning')}\"\n    '\\x1b[31m*\\x1b[0;0m \\x1b[33mWarning\\x1b[0;0m'\n\n.. code-block:: python\n\n    >>> c = Color()\n    >>> c.set(red=dict(fore=\"red\"))\n    >>> xyz = c.red.get(\"x\", \"y\", \"z\")\n    >>> xyz\n    ('\\x1b[31mx\\x1b[0;0m', '\\x1b[31my\\x1b[0;0m', '\\x1b[31mz\\x1b[0;0m')\n    >>> x, y, z = xyz\n    >>> f\"{x} {y} {z}\"\n    '\\x1b[31mx\\x1b[0;0m \\x1b[31my\\x1b[0;0m \\x1b[31mz\\x1b[0;0m'\n\nPrint the result using ``print``\n\n.. code-block:: python\n\n    >>> c = Color(effect=\"bold\", fore=\"cyan\")\n    >>> # doctest strips ansi codes from print\n    >>> c.print(\"bold cyan\")  # '\\x1b[1;36mbold cyan\\x1b[0;0m'\n    bold cyan\n\nLoad all ``effect``, ``fore``, or ``back`` elements using ``populate()``\n\n.. code-block:: python\n\n    >>> c = Color()\n    >>> c.populate(\"fore\")\n    >>> c\n    Color(effect=None, fore=None, back=None, objects(black, red, green, yellow, blue, magenta, cyan, white))\n\n.. code-block:: python\n\n    >>> c = Color()\n    >>> c.set(red=dict(fore=\"red\"))\n    >>> c.red.populate(\"effect\")\n    >>> c.red\n    Color(effect=None, fore=1, back=None, objects(none, bold, dim, italic, underline, blink, blinking, negative, empty, strikethrough))\n    >>> # doctest strips ansi codes from print\n    >>> c.red.strikethrough.print(\"strikethrough red\")  # '\\x1b[9;31mstrikethrough red\\x1b[0;0m'\n    strikethrough red\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Object-oriented library for stylizing terminal output",
    "version": "2.3.1",
    "project_urls": {
        "Documentation": "https://object-colors.readthedocs.io/en/latest",
        "Homepage": "https://pypi.org/project/object-colors/",
        "Repository": "https://github.com/jshwi/object-colors"
    },
    "split_keywords": [
        "ansi",
        "color",
        "oop",
        "terminal",
        "tty"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "051608bb4bf77b7c5f1ce9fe2111cefedb7afa9f7fa5a4327a1a9e82db15c342",
                "md5": "2e05b4aafb8c06da5683c42829fb860d",
                "sha256": "be4484add2dcc380a3bef6f19684a96b2a0a578285453fa2a44b9e37949d4f84"
            },
            "downloads": -1,
            "filename": "object_colors-2.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2e05b4aafb8c06da5683c42829fb860d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 7053,
            "upload_time": "2023-09-24T01:36:38",
            "upload_time_iso_8601": "2023-09-24T01:36:38.044333Z",
            "url": "https://files.pythonhosted.org/packages/05/16/08bb4bf77b7c5f1ce9fe2111cefedb7afa9f7fa5a4327a1a9e82db15c342/object_colors-2.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a36abab560526a8749cf62c4c8d4f83c62358a8c46786966eb19af30329145bc",
                "md5": "7e72d2daf3f4ad65d415514948bcb4b0",
                "sha256": "05edbd30bb3adc8257c804162df0acb05191d3237786e528801f4aba048205b9"
            },
            "downloads": -1,
            "filename": "object_colors-2.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7e72d2daf3f4ad65d415514948bcb4b0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 6835,
            "upload_time": "2023-09-24T01:36:39",
            "upload_time_iso_8601": "2023-09-24T01:36:39.279369Z",
            "url": "https://files.pythonhosted.org/packages/a3/6a/bab560526a8749cf62c4c8d4f83c62358a8c46786966eb19af30329145bc/object_colors-2.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-24 01:36:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jshwi",
    "github_project": "object-colors",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "object-colors"
}
        
Elapsed time: 0.25669s