escapyde


Nameescapyde JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://pypi.org/project/escapyde/
SummaryYet another ANSI escape sequence library for Python - now modernised!
upload_time2023-06-07 22:34:32
maintainerLari Liuhamo
docs_urlNone
authorLari Liuhamo
requires_python>=3.9.0,<4.0.0
licenseMIT
keywords ansi console terminal escape sequence colour color
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # escapyde

Yet another ANSI escape sequence library for Python - now modernised!

## Installation

The package is readily available on PyPI. There are no dependencies, but Python 3.9 or newer is required.

On Windows:

```sh
py -m pip install escapyde
```

On other platforms:

```sh
pip3 install escapyde
```

## Changelog

You can find the project changelog [here][changelog].

## Usage

For basic usage, pre-made colours are available for your convenience.
Use them with the pipe operator on strings you want to colour. They
end the colour changes automatically, too!

```py
import escapyde
from escapyde.examples.text import SKULL

some_text = "Hello, world!"

print(f"I want to print this red: {escapyde.FRED | some_text}, and this yellow: {escapyde.FYELLOW | 'Hi!'}.")

print(f"Here's a cyan skull:\n{escapyde.FCYAN | SKULL}")
```

You can also colour backgrounds,

```py
import escapyde

some_more_text = "This should have a blue background."

print(f"{escapyde.BBLUE | some_more_text}")
```

combine formatting options,

```py
import escapyde

even_more_text = "Lorem Ipsum dolor sit amet."

print(f"{escapyde.FRED | escapyde.BWHITE | even_more_text}")
```

and even mix formatting options on the fly (although at present you need to
separate strings with parentheses):

```py
import escapyde

print(f"{(escapyde.FRED | 'Hello') | (escapyde.FBLUE | 'World')}")
```

It is possible to use custom foreground and background colours via the
`escapyde.AnsiEscape` class; these can be either valid ANSI literals or
RGB values:

```py
from escapyde.ansi import AnsiEscape
from escapyde.colours import sequence_table

fg_white = sequence_table['fg_white']  # You can alternatively use raw integers, eg. 37 for white

gold = AnsiEscape(foreground_colour=(0xDB, 0xAC, 0x34))
white_gold = AnsiEscape(foreground_colour=fg_white, background_colour=(219, 172, 34))

print(gold | "This is gold!")
print(white_gold | "This is white text on gold background!")
```

The class defaults to the default colours of the terminal,
so you don't need to set both values.

Finally, if you have a string with multiple substrings you wish to recolour, there's a function for that:

```py
from escapyde.ansi import AnsiEscape, escape_format

mapping = {
    'match': AnsiEscape(foreground_colour=(255, 0, 0)),
    'case': AnsiEscape(foreground_colour=(255, 255, 0)),
    'print': AnsiEscape(foreground_colour=(0, 255, 0)),
}

text = """
stuff = [3, 1, 4]

match stuff:
    case [3, *rest]:
        print("It's pi-like")
    case _:
        print("Not like pi")
"""

print(escape_format(string=text, escape_map=mapping, case_sensitive=True))
```

## Screenshots

![A screenshot of the example run on IPython on Windows.][old_screenshot]
![A screenshot of the newer examples run on IPython on Windows.][new_screenshot]
![A screenshot of the newer examples run on IPython on Windows.][new_screenshot_2]

[changelog]: ./CHANGELOG.md
[old_screenshot]: ./docs/assets/readme_screenshot.png "Not bad, not bad at all."
[new_screenshot]: ./docs/assets/readme_20230608.png "That's colour over there!"
[new_screenshot_2]: ./docs/assets/readme_20230608_2.png "That's colour over there!"

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/escapyde/",
    "name": "escapyde",
    "maintainer": "Lari Liuhamo",
    "docs_url": null,
    "requires_python": ">=3.9.0,<4.0.0",
    "maintainer_email": "lari.liuhamo+pypi@gmail.com",
    "keywords": "ansi,console,terminal,escape,sequence,colour,color",
    "author": "Lari Liuhamo",
    "author_email": "lari.liuhamo+pypi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/1f/7f/dff5120369936bed1315ec448d7c733beb19838c19a6f5326a1a74bbc9bf/escapyde-1.0.1.tar.gz",
    "platform": null,
    "description": "# escapyde\n\nYet another ANSI escape sequence library for Python - now modernised!\n\n## Installation\n\nThe package is readily available on PyPI. There are no dependencies, but Python 3.9 or newer is required.\n\nOn Windows:\n\n```sh\npy -m pip install escapyde\n```\n\nOn other platforms:\n\n```sh\npip3 install escapyde\n```\n\n## Changelog\n\nYou can find the project changelog [here][changelog].\n\n## Usage\n\nFor basic usage, pre-made colours are available for your convenience.\nUse them with the pipe operator on strings you want to colour. They\nend the colour changes automatically, too!\n\n```py\nimport escapyde\nfrom escapyde.examples.text import SKULL\n\nsome_text = \"Hello, world!\"\n\nprint(f\"I want to print this red: {escapyde.FRED | some_text}, and this yellow: {escapyde.FYELLOW | 'Hi!'}.\")\n\nprint(f\"Here's a cyan skull:\\n{escapyde.FCYAN | SKULL}\")\n```\n\nYou can also colour backgrounds,\n\n```py\nimport escapyde\n\nsome_more_text = \"This should have a blue background.\"\n\nprint(f\"{escapyde.BBLUE | some_more_text}\")\n```\n\ncombine formatting options,\n\n```py\nimport escapyde\n\neven_more_text = \"Lorem Ipsum dolor sit amet.\"\n\nprint(f\"{escapyde.FRED | escapyde.BWHITE | even_more_text}\")\n```\n\nand even mix formatting options on the fly (although at present you need to\nseparate strings with parentheses):\n\n```py\nimport escapyde\n\nprint(f\"{(escapyde.FRED | 'Hello') | (escapyde.FBLUE | 'World')}\")\n```\n\nIt is possible to use custom foreground and background colours via the\n`escapyde.AnsiEscape` class; these can be either valid ANSI literals or\nRGB values:\n\n```py\nfrom escapyde.ansi import AnsiEscape\nfrom escapyde.colours import sequence_table\n\nfg_white = sequence_table['fg_white']  # You can alternatively use raw integers, eg. 37 for white\n\ngold = AnsiEscape(foreground_colour=(0xDB, 0xAC, 0x34))\nwhite_gold = AnsiEscape(foreground_colour=fg_white, background_colour=(219, 172, 34))\n\nprint(gold | \"This is gold!\")\nprint(white_gold | \"This is white text on gold background!\")\n```\n\nThe class defaults to the default colours of the terminal,\nso you don't need to set both values.\n\nFinally, if you have a string with multiple substrings you wish to recolour, there's a function for that:\n\n```py\nfrom escapyde.ansi import AnsiEscape, escape_format\n\nmapping = {\n    'match': AnsiEscape(foreground_colour=(255, 0, 0)),\n    'case': AnsiEscape(foreground_colour=(255, 255, 0)),\n    'print': AnsiEscape(foreground_colour=(0, 255, 0)),\n}\n\ntext = \"\"\"\nstuff = [3, 1, 4]\n\nmatch stuff:\n    case [3, *rest]:\n        print(\"It's pi-like\")\n    case _:\n        print(\"Not like pi\")\n\"\"\"\n\nprint(escape_format(string=text, escape_map=mapping, case_sensitive=True))\n```\n\n## Screenshots\n\n![A screenshot of the example run on IPython on Windows.][old_screenshot]\n![A screenshot of the newer examples run on IPython on Windows.][new_screenshot]\n![A screenshot of the newer examples run on IPython on Windows.][new_screenshot_2]\n\n[changelog]: ./CHANGELOG.md\n[old_screenshot]: ./docs/assets/readme_screenshot.png \"Not bad, not bad at all.\"\n[new_screenshot]: ./docs/assets/readme_20230608.png \"That's colour over there!\"\n[new_screenshot_2]: ./docs/assets/readme_20230608_2.png \"That's colour over there!\"\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Yet another ANSI escape sequence library for Python - now modernised!",
    "version": "1.0.1",
    "project_urls": {
        "Changelog": "https://github.com/Diapolo10/escapyde/blob/main/CHANGELOG.md",
        "Documentation": "https://github.com/Diapolo10/escapyde/tree/main/docs",
        "Homepage": "https://pypi.org/project/escapyde/",
        "Repository": "https://github.com/Diapolo10/escapyde",
        "Source code": "https://github.com/Diapolo10/escapyde",
        "Tracker": "https://github.com/Diapolo10/escapyde/issues"
    },
    "split_keywords": [
        "ansi",
        "console",
        "terminal",
        "escape",
        "sequence",
        "colour",
        "color"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e1642a75cc2823a230cb1ea1b6b03011d1cec4764f6db5c376f4ab8bc6807ac",
                "md5": "8facd40f0b5b189a17f3eed986732f1d",
                "sha256": "bb12c4f48f88b74376bcd5523f4a91890fac4a0988f38b5dcb00cfba467edeaa"
            },
            "downloads": -1,
            "filename": "escapyde-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8facd40f0b5b189a17f3eed986732f1d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9.0,<4.0.0",
            "size": 11124,
            "upload_time": "2023-06-07T22:34:31",
            "upload_time_iso_8601": "2023-06-07T22:34:31.120881Z",
            "url": "https://files.pythonhosted.org/packages/8e/16/42a75cc2823a230cb1ea1b6b03011d1cec4764f6db5c376f4ab8bc6807ac/escapyde-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1f7fdff5120369936bed1315ec448d7c733beb19838c19a6f5326a1a74bbc9bf",
                "md5": "da32821ab7438a429db4d21452b948d8",
                "sha256": "9f8fd786412d4fed89d56e5ded210c458cd5ed83720996f6ac91eba7c0f32723"
            },
            "downloads": -1,
            "filename": "escapyde-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "da32821ab7438a429db4d21452b948d8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.0,<4.0.0",
            "size": 10635,
            "upload_time": "2023-06-07T22:34:32",
            "upload_time_iso_8601": "2023-06-07T22:34:32.679462Z",
            "url": "https://files.pythonhosted.org/packages/1f/7f/dff5120369936bed1315ec448d7c733beb19838c19a6f5326a1a74bbc9bf/escapyde-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-07 22:34:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Diapolo10",
    "github_project": "escapyde",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "escapyde"
}
        
Elapsed time: 0.07407s