Name | pyansistring JSON |
Version |
0.0.2
JSON |
| download |
home_page | None |
Summary | A small library for fast color styling of the string using ANSI escape sequences. |
upload_time | 2024-09-13 22:19:47 |
maintainer | None |
docs_url | None |
author | Volodymyr Horshenin |
requires_python | >=3.10 |
license | MIT License Copyright (c) 2024 Volodymyr Horshenin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
ansi escape sequences
colored string
colored text
colors
terminal
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# pyansistring
![pyansistring Banner](./images/banner.png)
[***`pyansistring`***](https://github.com/l1asis/pyansistring) is a small library for fast **color styling** of the string using **ANSI escape sequences**. The base class inherits from Python's `str`. You can split, join, slice the string while preserving the styling.
Inspired by [***`rich`***](https://github.com/Textualize/rich) Python library.
## **Features**
- Preservation of the `str` methods.
- RGB foreground and background coloring.
- Per-word coloring.
- Align left, right and center without the problems caused by the length of the string.
#### For a more comprehensive list of what's been done so far, see the [***TODO***](./TODO.md) section.
## **Install**
Since the library is published on [PyPI](https://pypi.org/), it can be installed using pip:
```
pip install pyansistring
```
Or locally, by cloning the project:
```
git clone https://github.com/l1asis/pyansistring
cd ./pyansistring/
pip install .
```
## **Contributing**
Any ideas (vectors) for improvements, actual help with implementations, bug fixes
and anything else is highly appreciated. You can also contribute by adding your
own art to the `arts.py` file in the `.\src\pyansistring` directory if you like.
## **Usage**
```python
from pyansistring import ANSIString
from pyansistring.constants import SGR, Foreground, Background
# Does what it should: prints all text in bold, with magenta foreground and white background.
print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).bg_4b(Background.WHITE).fm(SGR.BOLD))
# But you can do the same on a specific slice:
print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA, (0, 4)).bg_4b(Background.WHITE, (2, 4)).fm(SGR.BOLD, (4, 6)))
# Or if you want to apply styles to a specific word
print(ANSIString("Hello, World!").fg_4b_w(Foreground.MAGENTA, "Hello", "World").bg_4b_w(Background.WHITE, "World").fm_w(SGR.BOLD, ","))
# You may find predefined colors boring, let's do it with RGB:
print(ANSIString("Hello, World!").fg_24b(255, 0, 255).bg_24b(255, 255, 255))
# And of course you can do the same tricks with words:
print(ANSIString("Hello, World!").fg_24b_w(255, 0, 255, "Hello").bg_24b_w(255, 255, 255, "World"))
# By the way...
print(len(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA)) == len("Hello, World!"))
# -> True
# Why? Because I wanted it to behave this way. But at the same time:
print(len(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).styled) == len("Hello, World!"))
# -> False
print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).actual_length == len("Hello, World!"))
# -> False
# If you need the original string:
print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).plain)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "pyansistring",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "ANSI escape sequences, colored string, colored text, colors, terminal",
"author": "Volodymyr Horshenin",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/ca/08/143af4d608c033474abfc76ee23faa8e4db42f62ec99f5eff5e9409ff87e/pyansistring-0.0.2.tar.gz",
"platform": null,
"description": "# pyansistring\n\n![pyansistring Banner](./images/banner.png)\n\n[***`pyansistring`***](https://github.com/l1asis/pyansistring) is a small library for fast **color styling** of the string using **ANSI escape sequences**. The base class inherits from Python's `str`. You can split, join, slice the string while preserving the styling. \n\nInspired by [***`rich`***](https://github.com/Textualize/rich) Python library.\n\n## **Features**\n- Preservation of the `str` methods.\n- RGB foreground and background coloring.\n- Per-word coloring.\n- Align left, right and center without the problems caused by the length of the string.\n\n#### For a more comprehensive list of what's been done so far, see the [***TODO***](./TODO.md) section.\n\n## **Install**\nSince the library is published on [PyPI](https://pypi.org/), it can be installed using pip:\n```\npip install pyansistring\n```\nOr locally, by cloning the project:\n```\ngit clone https://github.com/l1asis/pyansistring\ncd ./pyansistring/\npip install .\n```\n\n## **Contributing**\nAny ideas (vectors) for improvements, actual help with implementations, bug fixes \nand anything else is highly appreciated. You can also contribute by adding your \nown art to the `arts.py` file in the `.\\src\\pyansistring` directory if you like.\n\n## **Usage**\n```python\nfrom pyansistring import ANSIString\nfrom pyansistring.constants import SGR, Foreground, Background\n\n# Does what it should: prints all text in bold, with magenta foreground and white background.\nprint(ANSIString(\"Hello, World!\").fg_4b(Foreground.MAGENTA).bg_4b(Background.WHITE).fm(SGR.BOLD))\n\n# But you can do the same on a specific slice:\nprint(ANSIString(\"Hello, World!\").fg_4b(Foreground.MAGENTA, (0, 4)).bg_4b(Background.WHITE, (2, 4)).fm(SGR.BOLD, (4, 6)))\n\n# Or if you want to apply styles to a specific word\nprint(ANSIString(\"Hello, World!\").fg_4b_w(Foreground.MAGENTA, \"Hello\", \"World\").bg_4b_w(Background.WHITE, \"World\").fm_w(SGR.BOLD, \",\"))\n\n# You may find predefined colors boring, let's do it with RGB:\nprint(ANSIString(\"Hello, World!\").fg_24b(255, 0, 255).bg_24b(255, 255, 255))\n\n# And of course you can do the same tricks with words:\nprint(ANSIString(\"Hello, World!\").fg_24b_w(255, 0, 255, \"Hello\").bg_24b_w(255, 255, 255, \"World\"))\n\n# By the way...\nprint(len(ANSIString(\"Hello, World!\").fg_4b(Foreground.MAGENTA)) == len(\"Hello, World!\"))\n# -> True\n\n# Why? Because I wanted it to behave this way. But at the same time:\nprint(len(ANSIString(\"Hello, World!\").fg_4b(Foreground.MAGENTA).styled) == len(\"Hello, World!\"))\n# -> False\nprint(ANSIString(\"Hello, World!\").fg_4b(Foreground.MAGENTA).actual_length == len(\"Hello, World!\"))\n# -> False\n\n# If you need the original string:\nprint(ANSIString(\"Hello, World!\").fg_4b(Foreground.MAGENTA).plain)\n```",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Volodymyr Horshenin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "A small library for fast color styling of the string using ANSI escape sequences.",
"version": "0.0.2",
"project_urls": {
"Issues": "https://github.com/l1asis/pyansistring/issues",
"Repository": "https://github.com/l1asis/pyansistring.git"
},
"split_keywords": [
"ansi escape sequences",
" colored string",
" colored text",
" colors",
" terminal"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3cc17711593d513604ed968ca2f255fc96f314bc5a92d04e7869565e03b76987",
"md5": "c5c596ba4c9d31b5c8f39001d3515b87",
"sha256": "1ba41de7259bc8b9ac06081e835161d69725785ead9ea3b19b3a0eabd1090b9b"
},
"downloads": -1,
"filename": "pyansistring-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c5c596ba4c9d31b5c8f39001d3515b87",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 16231,
"upload_time": "2024-09-13T22:19:45",
"upload_time_iso_8601": "2024-09-13T22:19:45.796296Z",
"url": "https://files.pythonhosted.org/packages/3c/c1/7711593d513604ed968ca2f255fc96f314bc5a92d04e7869565e03b76987/pyansistring-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ca08143af4d608c033474abfc76ee23faa8e4db42f62ec99f5eff5e9409ff87e",
"md5": "586a83b0efda4646eb906bfc29a43565",
"sha256": "f31c5ce32682b4249e2de2d1df4b6e97f6ba173c355dce08d796ab1c47f524f8"
},
"downloads": -1,
"filename": "pyansistring-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "586a83b0efda4646eb906bfc29a43565",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 49447,
"upload_time": "2024-09-13T22:19:47",
"upload_time_iso_8601": "2024-09-13T22:19:47.600974Z",
"url": "https://files.pythonhosted.org/packages/ca/08/143af4d608c033474abfc76ee23faa8e4db42f62ec99f5eff5e9409ff87e/pyansistring-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-13 22:19:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "l1asis",
"github_project": "pyansistring",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyansistring"
}