pyansistring 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,165 @@
1
+ # Local tests
2
+ tests/untracked
3
+
4
+ # Byte-compiled / optimized / DLL files
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+
9
+ # C extensions
10
+ *.so
11
+
12
+ # Distribution / packaging
13
+ .Python
14
+ build/
15
+ develop-eggs/
16
+ dist/
17
+ downloads/
18
+ eggs/
19
+ .eggs/
20
+ lib/
21
+ lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ wheels/
26
+ share/python-wheels/
27
+ *.egg-info/
28
+ .installed.cfg
29
+ *.egg
30
+ MANIFEST
31
+
32
+ # PyInstaller
33
+ # Usually these files are written by a python script from a template
34
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
35
+ *.manifest
36
+ *.spec
37
+
38
+ # Installer logs
39
+ pip-log.txt
40
+ pip-delete-this-directory.txt
41
+
42
+ # Unit test / coverage reports
43
+ htmlcov/
44
+ .tox/
45
+ .nox/
46
+ .coverage
47
+ .coverage.*
48
+ .cache
49
+ nosetests.xml
50
+ coverage.xml
51
+ *.cover
52
+ *.py,cover
53
+ .hypothesis/
54
+ .pytest_cache/
55
+ cover/
56
+
57
+ # Translations
58
+ *.mo
59
+ *.pot
60
+
61
+ # Django stuff:
62
+ *.log
63
+ local_settings.py
64
+ db.sqlite3
65
+ db.sqlite3-journal
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ .pybuilder/
79
+ target/
80
+
81
+ # Jupyter Notebook
82
+ .ipynb_checkpoints
83
+
84
+ # IPython
85
+ profile_default/
86
+ ipython_config.py
87
+
88
+ # pyenv
89
+ # For a library or package, you might want to ignore these files since the code is
90
+ # intended to run in multiple environments; otherwise, check them in:
91
+ # .python-version
92
+
93
+ # pipenv
94
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
96
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
97
+ # install all needed dependencies.
98
+ #Pipfile.lock
99
+
100
+ # poetry
101
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
103
+ # commonly ignored for libraries.
104
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105
+ #poetry.lock
106
+
107
+ # pdm
108
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109
+ #pdm.lock
110
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111
+ # in version control.
112
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
113
+ .pdm.toml
114
+ .pdm-python
115
+ .pdm-build/
116
+
117
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
118
+ __pypackages__/
119
+
120
+ # Celery stuff
121
+ celerybeat-schedule
122
+ celerybeat.pid
123
+
124
+ # SageMath parsed files
125
+ *.sage.py
126
+
127
+ # Environments
128
+ .env
129
+ .venv
130
+ env/
131
+ venv/
132
+ ENV/
133
+ env.bak/
134
+ venv.bak/
135
+
136
+ # Spyder project settings
137
+ .spyderproject
138
+ .spyproject
139
+
140
+ # Rope project settings
141
+ .ropeproject
142
+
143
+ # mkdocs documentation
144
+ /site
145
+
146
+ # mypy
147
+ .mypy_cache/
148
+ .dmypy.json
149
+ dmypy.json
150
+
151
+ # Pyre type checker
152
+ .pyre/
153
+
154
+ # pytype static type analyzer
155
+ .pytype/
156
+
157
+ # Cython debug symbols
158
+ cython_debug/
159
+
160
+ # PyCharm
161
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
162
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
163
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
164
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
165
+ #.idea/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Volodymyr Horshenin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.3
2
+ Name: pyansistring
3
+ Version: 0.0.2
4
+ Summary: A small library for fast color styling of the string using ANSI escape sequences.
5
+ Project-URL: Repository, https://github.com/l1asis/pyansistring.git
6
+ Project-URL: Issues, https://github.com/l1asis/pyansistring/issues
7
+ Author: Volodymyr Horshenin
8
+ License: MIT License
9
+
10
+ Copyright (c) 2024 Volodymyr Horshenin
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Keywords: ANSI escape sequences,colored string,colored text,colors,terminal
31
+ Classifier: Development Status :: 3 - Alpha
32
+ Classifier: Intended Audience :: Other Audience
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Operating System :: OS Independent
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Topic :: Terminals
37
+ Classifier: Topic :: Text Processing
38
+ Requires-Python: >=3.10
39
+ Description-Content-Type: text/markdown
40
+
41
+ # pyansistring
42
+
43
+ ![pyansistring Banner](./images/banner.png)
44
+
45
+ [***`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.
46
+
47
+ Inspired by [***`rich`***](https://github.com/Textualize/rich) Python library.
48
+
49
+ ## **Features**
50
+ - Preservation of the `str` methods.
51
+ - RGB foreground and background coloring.
52
+ - Per-word coloring.
53
+ - Align left, right and center without the problems caused by the length of the string.
54
+
55
+ #### For a more comprehensive list of what's been done so far, see the [***TODO***](./TODO.md) section.
56
+
57
+ ## **Install**
58
+ Since the library is published on [PyPI](https://pypi.org/), it can be installed using pip:
59
+ ```
60
+ pip install pyansistring
61
+ ```
62
+ Or locally, by cloning the project:
63
+ ```
64
+ git clone https://github.com/l1asis/pyansistring
65
+ cd ./pyansistring/
66
+ pip install .
67
+ ```
68
+
69
+ ## **Contributing**
70
+ Any ideas (vectors) for improvements, actual help with implementations, bug fixes
71
+ and anything else is highly appreciated. You can also contribute by adding your
72
+ own art to the `arts.py` file in the `.\src\pyansistring` directory if you like.
73
+
74
+ ## **Usage**
75
+ ```python
76
+ from pyansistring import ANSIString
77
+ from pyansistring.constants import SGR, Foreground, Background
78
+
79
+ # Does what it should: prints all text in bold, with magenta foreground and white background.
80
+ print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).bg_4b(Background.WHITE).fm(SGR.BOLD))
81
+
82
+ # But you can do the same on a specific slice:
83
+ print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA, (0, 4)).bg_4b(Background.WHITE, (2, 4)).fm(SGR.BOLD, (4, 6)))
84
+
85
+ # Or if you want to apply styles to a specific word
86
+ print(ANSIString("Hello, World!").fg_4b_w(Foreground.MAGENTA, "Hello", "World").bg_4b_w(Background.WHITE, "World").fm_w(SGR.BOLD, ","))
87
+
88
+ # You may find predefined colors boring, let's do it with RGB:
89
+ print(ANSIString("Hello, World!").fg_24b(255, 0, 255).bg_24b(255, 255, 255))
90
+
91
+ # And of course you can do the same tricks with words:
92
+ print(ANSIString("Hello, World!").fg_24b_w(255, 0, 255, "Hello").bg_24b_w(255, 255, 255, "World"))
93
+
94
+ # By the way...
95
+ print(len(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA)) == len("Hello, World!"))
96
+ # -> True
97
+
98
+ # Why? Because I wanted it to behave this way. But at the same time:
99
+ print(len(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).styled) == len("Hello, World!"))
100
+ # -> False
101
+ print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).actual_length == len("Hello, World!"))
102
+ # -> False
103
+
104
+ # If you need the original string:
105
+ print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).plain)
106
+ ```
@@ -0,0 +1,66 @@
1
+ # pyansistring
2
+
3
+ ![pyansistring Banner](./images/banner.png)
4
+
5
+ [***`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.
6
+
7
+ Inspired by [***`rich`***](https://github.com/Textualize/rich) Python library.
8
+
9
+ ## **Features**
10
+ - Preservation of the `str` methods.
11
+ - RGB foreground and background coloring.
12
+ - Per-word coloring.
13
+ - Align left, right and center without the problems caused by the length of the string.
14
+
15
+ #### For a more comprehensive list of what's been done so far, see the [***TODO***](./TODO.md) section.
16
+
17
+ ## **Install**
18
+ Since the library is published on [PyPI](https://pypi.org/), it can be installed using pip:
19
+ ```
20
+ pip install pyansistring
21
+ ```
22
+ Or locally, by cloning the project:
23
+ ```
24
+ git clone https://github.com/l1asis/pyansistring
25
+ cd ./pyansistring/
26
+ pip install .
27
+ ```
28
+
29
+ ## **Contributing**
30
+ Any ideas (vectors) for improvements, actual help with implementations, bug fixes
31
+ and anything else is highly appreciated. You can also contribute by adding your
32
+ own art to the `arts.py` file in the `.\src\pyansistring` directory if you like.
33
+
34
+ ## **Usage**
35
+ ```python
36
+ from pyansistring import ANSIString
37
+ from pyansistring.constants import SGR, Foreground, Background
38
+
39
+ # Does what it should: prints all text in bold, with magenta foreground and white background.
40
+ print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).bg_4b(Background.WHITE).fm(SGR.BOLD))
41
+
42
+ # But you can do the same on a specific slice:
43
+ print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA, (0, 4)).bg_4b(Background.WHITE, (2, 4)).fm(SGR.BOLD, (4, 6)))
44
+
45
+ # Or if you want to apply styles to a specific word
46
+ print(ANSIString("Hello, World!").fg_4b_w(Foreground.MAGENTA, "Hello", "World").bg_4b_w(Background.WHITE, "World").fm_w(SGR.BOLD, ","))
47
+
48
+ # You may find predefined colors boring, let's do it with RGB:
49
+ print(ANSIString("Hello, World!").fg_24b(255, 0, 255).bg_24b(255, 255, 255))
50
+
51
+ # And of course you can do the same tricks with words:
52
+ print(ANSIString("Hello, World!").fg_24b_w(255, 0, 255, "Hello").bg_24b_w(255, 255, 255, "World"))
53
+
54
+ # By the way...
55
+ print(len(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA)) == len("Hello, World!"))
56
+ # -> True
57
+
58
+ # Why? Because I wanted it to behave this way. But at the same time:
59
+ print(len(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).styled) == len("Hello, World!"))
60
+ # -> False
61
+ print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).actual_length == len("Hello, World!"))
62
+ # -> False
63
+
64
+ # If you need the original string:
65
+ print(ANSIString("Hello, World!").fg_4b(Foreground.MAGENTA).plain)
66
+ ```
@@ -0,0 +1,137 @@
1
+ ### `str` magic or dunder methods
2
+ - [X] `__add__`
3
+ - [ ] `__class__`
4
+ - [ ] `__contains__`
5
+ - [ ] `__delattr__`
6
+ - [X] `__dir__`
7
+ - [X] `__doc__`
8
+ - [X] `__eq__`
9
+ - [ ] `__format__`
10
+ - [ ] `__ge__`
11
+ - [ ] `__getattribute__`
12
+ - [X] `__getitem__`
13
+ - [ ] `__getnewargs__`
14
+ - [ ] `__getstate__`
15
+ - [ ] `__gt__`
16
+ - [ ] `__hash__`
17
+ - [X] `__init__`
18
+ - [ ] `__init_subclass__`
19
+ - [ ] `__iter__`
20
+ - [ ] `__le__`
21
+ - [X] `__len__`
22
+ - [ ] `__lt__`
23
+ - [ ] `__mod__`
24
+ - [ ] `__mul__`
25
+ - [X] `__ne__`
26
+ - [ ] `__new__`
27
+ - [ ] `__reduce__`
28
+ - [ ] `__reduce_ex__`
29
+ - [X] `__repr__`
30
+ - [ ] `__rmod__`
31
+ - [ ] `__rmul__`
32
+ - [ ] `__setattr__`
33
+ - [ ] `__sizeof__`
34
+ - [X] `__str__`
35
+ - [ ] `__subclasshook__`
36
+
37
+ ### `str` public methods
38
+ - [X] `capitalize`
39
+ - [ ] `casefold`
40
+ - [X] `center`
41
+ - [X] `count`
42
+ - [ ] `encode`
43
+ - [X] `endswith`
44
+ - [ ] `expandtabs`
45
+ - [X] `find`
46
+ - [ ] `format`
47
+ - [ ] `format_map`
48
+ - [X] `index`
49
+ - [X] `isalnum`
50
+ - [X] `isalpha`
51
+ - [X] `isascii`
52
+ - [X] `isdecimal`
53
+ - [X] `isdigit`
54
+ - [X] `isidentifier`
55
+ - [X] `islower`
56
+ - [X] `isnumeric`
57
+ - [X] `isprintable`
58
+ - [X] `isspace`
59
+ - [X] `istitle`
60
+ - [X] `isupper`
61
+ - [X] `join`
62
+ - [X] `ljust`
63
+ - [X] `lower`
64
+ - [ ] `lstrip`
65
+ - [ ] `maketrans`
66
+ - [ ] `partition`
67
+ - [ ] `removeprefix`
68
+ - [ ] `removesuffix`
69
+ - [ ] `replace`
70
+ - [X] `rfind`
71
+ - [X] `rindex`
72
+ - [X] `rjust`
73
+ - [ ] `rpartition`
74
+ - [X] `rsplit`
75
+ - [X] whitespace
76
+ - [X] one char
77
+ - [X] two or more chars
78
+ - [ ] `rstrip`
79
+ - [X] `split`
80
+ - [X] whitespace
81
+ - [X] one char
82
+ - [X] two or more chars
83
+ - [X] `splitlines`
84
+ - [X] `startswith`
85
+ - [ ] `strip`
86
+ - [X] `swapcase`
87
+ - [X] `title`
88
+ - [ ] `translate`
89
+ - [X] `upper`
90
+ - [ ] `zfill`
91
+
92
+ ### `ANSIString` featured methods (magic, private and public)
93
+ - [X] `__radd__`
94
+ - [ ] `__copy__`
95
+ - [ ] `__deepcopy__`
96
+
97
+ - [X] `_render` (apply current styles to the plain string)
98
+ - [X] `_get_indices` (...)
99
+ - [X] `_search_spans` (...)
100
+
101
+ - [X] `fm` (set SGR styling parameters)
102
+ - [X] `fm_w` (`fm` per word)
103
+ - [X] `unfm` (remove styles from the string)
104
+ - [X] `unfm_w` (`unfm` per word)
105
+
106
+ - [ ] ~~`fg` (shortcut to `fg_24b`)~~
107
+ - [ ] ~~`fg_w` (shortcut to `fg_24b_w`)~~
108
+
109
+ - [X] `fg_4b` (set foreground color using 4-bit color code)
110
+ - [X] `fg_4b_w` (`fg_4b` per word)
111
+ - [X] `fg_8b` (set foreground color using a pre-defined set of 256 colors)
112
+ - [X] `fg_8b_w` (`fg_8b` per word)
113
+ - [X] `fg_24b` (set foreground color using RGB color model, a.k.a. true color)
114
+ - [X] `fg_24b_w` (`fg_24b` per word)
115
+
116
+ - [ ] ~~`bg` (shortcut to `bg_24b`)~~
117
+ - [ ] ~~`bg_w` (shortcut to `bg_24b_w`)~~
118
+
119
+ - [X] `bg_4b` (set background color using 4-bit color code)
120
+ - [X] `bg_4b_w` (`bg_4b` per word)
121
+ - [X] `bg_8b` (set background color using a pre-defined set of 256 colors)
122
+ - [X] `bg_8b_w` (`bg_8b` per word)
123
+ - [X] `bg_24b` (set background color using RGB color model, a.k.a. true color)
124
+ - [X] `bg_24b_w` (`bg_24b` per word)
125
+
126
+ - [ ] `ul_8b` (set underline color using a pre-defined set of 256 colors)
127
+ - [ ] `ul_8b_w` (`ul_8b` per word)
128
+ - [ ] `ul_24b` (set underline color using RGB color model, a.k.a. true color)
129
+ - [ ] `ul_24b_w` (`ul_24b` per word)
130
+
131
+
132
+ - [X] `multicolor` (apply a specific custom coloring using the provided coloring system)
133
+ - [X] `multicolor_c` (`multicolor` using coordinates, it's useful for multiline strings)
134
+ - [ ] `colormap` (apply a specific predefined coloring)
135
+ - [X] `rainbow` (apply rainbow coloring (using a separate algorithm))
136
+ - [ ] `random_art` (return random color art)
137
+ - [X] `from_ansi` (create `ANSIString` from plain `str` with ANSI escape sequences)
Binary file
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pyansistring"
7
+ version = "0.0.2"
8
+ requires-python = ">=3.10"
9
+ authors = [
10
+ {name="Volodymyr Horshenin"},
11
+ ]
12
+ description = "A small library for fast color styling of the string using ANSI escape sequences."
13
+ readme = "README.md"
14
+ license = {file = "LICENSE"}
15
+ keywords = ["colored string", "colored text", "colors", "ANSI escape sequences", "terminal"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Other Audience",
19
+ "Topic :: Terminals",
20
+ "Topic :: Text Processing",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Programming Language :: Python :: 3",
23
+ "Operating System :: OS Independent",
24
+ ]
25
+
26
+ [project.urls]
27
+ Repository = "https://github.com/l1asis/pyansistring.git"
28
+ Issues = "https://github.com/l1asis/pyansistring/issues"
@@ -0,0 +1,16 @@
1
+ """
2
+ pyansistring
3
+ """
4
+
5
+ __all__ = [
6
+ "pyansistring",
7
+ "constants",
8
+ "helpers",
9
+ "arts",
10
+ "ANSIString",
11
+ "StyleDict",
12
+ ]
13
+ __title__ = "pyansistring"
14
+ __license__ = "MIT"
15
+
16
+ from pyansistring.pyansistring import *