chromatic-python 0.3.4__tar.gz → 0.4.1__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.
- chromatic_python-0.4.1/.github/workflows/publish.yml +29 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/.gitignore +6 -11
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/LICENSE +20 -20
- {chromatic_python-0.3.4/chromatic_python.egg-info → chromatic_python-0.4.1}/PKG-INFO +149 -127
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/README.md +124 -102
- chromatic_python-0.4.1/banner.png +0 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/__init__.py +8 -8
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/__init__.pyi +90 -90
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/_typing.py +444 -443
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/_version.py +34 -34
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/color/__init__.py +3 -3
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/color/__init__.pyi +90 -90
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/color/colorconv.py +352 -350
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/color/core.py +1710 -1685
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/color/core.pyi +515 -506
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/color/iterators.py +172 -172
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/color/palette.py +591 -580
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/color/palette.pyi +300 -300
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/__init__.py +33 -33
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/__init__.pyi +16 -16
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/_fetchers.py +55 -55
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/registry.json +4 -4
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/userfont.py +153 -153
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/userfont.pyi +30 -30
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/userfont.schema.json +28 -28
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/demo.py +380 -380
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/image/__init__.py +5 -5
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/image/__init__.pyi +70 -70
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/image/_array.py +1358 -1324
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/image/_curses.py +148 -148
- chromatic_python-0.3.4/chromatic/image/_glyph_proc.py → chromatic_python-0.4.1/chromatic/image/_glyph.py +90 -90
- {chromatic_python-0.3.4 → chromatic_python-0.4.1/chromatic_python.egg-info}/PKG-INFO +149 -127
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic_python.egg-info/SOURCES.txt +3 -4
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/pyproject.toml +49 -49
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/requirements.txt +53 -53
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/setup.cfg +4 -4
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/tests/test_color_str.py +356 -356
- chromatic_python-0.3.4/chromatic/__main__.py +0 -105
- chromatic_python-0.3.4/logo/logo.ANS +0 -25
- chromatic_python-0.3.4/logo/logo.PNG +0 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/.gitattributes +0 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/butterfly.jpg +0 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/escher.png +0 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/fonts/consolas.ttf +0 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/fonts/vga437.ttf +0 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic/data/goblin_virus.png +0 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic_python.egg-info/dependency_links.txt +0 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic_python.egg-info/requires.txt +0 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/chromatic_python.egg-info/top_level.txt +0 -0
- {chromatic_python-0.3.4 → chromatic_python-0.4.1}/tests/__init__.py +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
on:
|
|
2
|
+
push:
|
|
3
|
+
tags:
|
|
4
|
+
- "v*.*.*"
|
|
5
|
+
permissions:
|
|
6
|
+
contents: write
|
|
7
|
+
id-token: write
|
|
8
|
+
jobs:
|
|
9
|
+
build-publish-release:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment: pypi
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-python@v5
|
|
15
|
+
with:
|
|
16
|
+
python-version: "3.x"
|
|
17
|
+
- run: python -m pip install --upgrade pip build
|
|
18
|
+
- run: python -m build
|
|
19
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
20
|
+
with:
|
|
21
|
+
print-hash: true
|
|
22
|
+
- uses: softprops/action-gh-release@v2
|
|
23
|
+
with:
|
|
24
|
+
tag_name: ${{ github.ref_name }}
|
|
25
|
+
name: ${{ github.ref_name }}
|
|
26
|
+
generate_release_notes: true
|
|
27
|
+
prerelease: ${{ contains(github.ref_name, '-') }}
|
|
28
|
+
files: |
|
|
29
|
+
dist/*
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
*.pyc
|
|
2
|
-
*.pyo
|
|
3
|
-
__pycache__/
|
|
4
|
-
|
|
5
|
-
/
|
|
6
|
-
/
|
|
7
|
-
/tests/_*
|
|
8
|
-
/chromatic/data/userfont.json
|
|
9
|
-
/chromatic/_version.py
|
|
10
|
-
/*.egg-info/
|
|
11
|
-
/build/
|
|
1
|
+
*.pyc
|
|
2
|
+
*.pyo
|
|
3
|
+
__pycache__/
|
|
4
|
+
/chromatic/_version.py
|
|
5
|
+
/chromatic/data/userfont.json
|
|
6
|
+
/tests/_*
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 crypt0lith
|
|
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
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 crypt0lith
|
|
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
21
|
SOFTWARE.
|
|
@@ -1,127 +1,149 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: chromatic-python
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: ANSI art image processing and colored terminal text
|
|
5
|
-
Author: crypt0lith
|
|
6
|
-
Project-URL: Homepage, https://github.com/crypt0lith/chromatic
|
|
7
|
-
Keywords: ansi,ascii,art,font,image,terminal,parser
|
|
8
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
11
|
-
Classifier: Typing :: Typed
|
|
12
|
-
Requires-Python: >=3.12
|
|
13
|
-
Description-Content-Type: text/markdown
|
|
14
|
-
License-File: LICENSE
|
|
15
|
-
Requires-Dist: numpy<2.6,>=1.25.2
|
|
16
|
-
Requires-Dist: pillow!=11.2.*,<12.0,>=10.1
|
|
17
|
-
Requires-Dist: networkx<4.0,>=3.0
|
|
18
|
-
Requires-Dist: scipy<2.0,>=1.11.4
|
|
19
|
-
Requires-Dist: opencv-python
|
|
20
|
-
Requires-Dist: scikit-image
|
|
21
|
-
Requires-Dist: scikit-learn
|
|
22
|
-
Requires-Dist: fonttools
|
|
23
|
-
Requires-Dist: lazy_loader
|
|
24
|
-
Dynamic: license-file
|
|
25
|
-
|
|
26
|
-
](https://pypi.org/project/chromatic-python/)
|
|
29
|
-

|
|
30
|
-
[](https://pepy.tech/projects/chromatic-python)
|
|
31
|
-
[](https://mypy-lang.org/)
|
|
32
|
-
|
|
33
|
-
Chromatic is a library for processing and transforming ANSI escape sequences (colored terminal text).
|
|
34
|
-
|
|
35
|
-
It offers a collection of algorithms and types for a variety of use cases:
|
|
36
|
-
- Image-to-ASCII / Image-to-ANSI conversions.
|
|
37
|
-
- ANSI art rendering, with support for user-defined fonts.
|
|
38
|
-
- A `ColorStr` type
|
|
39
|
-
- [colorama](https://github.com/tartley/colorama/)-style wrappers (`Fore`, `Back`, `Style`).
|
|
40
|
-
-
|
|
41
|
-
- Et Cetera 😲
|
|
42
|
-
|
|
43
|
-
### Usage
|
|
44
|
-
####
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
assert
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
from chromatic
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chromatic-python
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: ANSI art image processing and colored terminal text
|
|
5
|
+
Author: crypt0lith
|
|
6
|
+
Project-URL: Homepage, https://github.com/crypt0lith/chromatic
|
|
7
|
+
Keywords: ansi,ascii,art,font,image,terminal,parser
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
11
|
+
Classifier: Typing :: Typed
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy<2.6,>=1.25.2
|
|
16
|
+
Requires-Dist: pillow!=11.2.*,<12.0,>=10.1
|
|
17
|
+
Requires-Dist: networkx<4.0,>=3.0
|
|
18
|
+
Requires-Dist: scipy<2.0,>=1.11.4
|
|
19
|
+
Requires-Dist: opencv-python
|
|
20
|
+
Requires-Dist: scikit-image
|
|
21
|
+
Requires-Dist: scikit-learn
|
|
22
|
+
Requires-Dist: fonttools
|
|
23
|
+
Requires-Dist: lazy_loader
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
[](https://pypi.org/project/chromatic-python/)
|
|
29
|
+

|
|
30
|
+
[](https://pepy.tech/projects/chromatic-python)
|
|
31
|
+
[](https://mypy-lang.org/)
|
|
32
|
+
|
|
33
|
+
Chromatic is a library for processing and transforming ANSI escape sequences (colored terminal text).
|
|
34
|
+
|
|
35
|
+
It offers a collection of algorithms and types for a variety of use cases:
|
|
36
|
+
- Image-to-ASCII / Image-to-ANSI conversions.
|
|
37
|
+
- ANSI art rendering, with support for user-defined fonts.
|
|
38
|
+
- A `ColorStr` type for low-level control over ANSI SGR strings.
|
|
39
|
+
- [colorama](https://github.com/tartley/colorama/)-style wrappers (`Fore`, `Back`, `Style`).
|
|
40
|
+
- Conversion between 16-color, 256-color, and true-color (RGB) ANSI colorspace via the `colorbytes` type.
|
|
41
|
+
- Et Cetera 😲
|
|
42
|
+
|
|
43
|
+
### Usage
|
|
44
|
+
#### Image-to-ANSI conversion
|
|
45
|
+
|
|
46
|
+
Convert an image into a 2d ANSI string array, and render the ANSI array as image:
|
|
47
|
+
```python
|
|
48
|
+
from chromatic.color import ansicolor4Bit
|
|
49
|
+
from chromatic.image import ansi2img, img2ansi
|
|
50
|
+
from chromatic.data import userfont, butterfly
|
|
51
|
+
|
|
52
|
+
input_img = butterfly()
|
|
53
|
+
font = userfont['vga437']
|
|
54
|
+
|
|
55
|
+
# `char_set` is used to translate luminance to characters
|
|
56
|
+
# | <- index 0 is the 'darkest'
|
|
57
|
+
char_set = r"'·,•-_→+<>ⁿ*%⌂7√Iï∞πbz£9yîU{}1αHSw♥æ?GX╕╒éà⌡MF╝╩ΘûǃQ½☻Ŷ┤▄╪║▒█"
|
|
58
|
+
# index -1 is the 'brightest' -> |
|
|
59
|
+
|
|
60
|
+
# returns list[list[ColorStr]]
|
|
61
|
+
ansi_array = img2ansi(
|
|
62
|
+
input_img,
|
|
63
|
+
font,
|
|
64
|
+
sort_glyphs=False, # map `char_set` as-is
|
|
65
|
+
char_set=char_set,
|
|
66
|
+
ansi_type=ansicolor4Bit,
|
|
67
|
+
factor=200,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# print your image to stdout
|
|
71
|
+
print(*map(''.join, ansi_array), sep="\x1b[0m\n")
|
|
72
|
+
|
|
73
|
+
# returns a PIL.Image.Image object
|
|
74
|
+
ansi_img = ansi2img(ansi_array, font, font_size=16)
|
|
75
|
+
ansi_img.show()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### ColorStr
|
|
79
|
+
```python
|
|
80
|
+
from chromatic import ColorStr
|
|
81
|
+
|
|
82
|
+
base_str = 'hello world'
|
|
83
|
+
|
|
84
|
+
red_fg = ColorStr(base_str, 0xFF0000, ansi_type='8b')
|
|
85
|
+
|
|
86
|
+
assert red_fg.base_str == base_str
|
|
87
|
+
assert red_fg.rgb_dict == {'fg': (0xFF, 0, 0)}
|
|
88
|
+
assert red_fg.ansi == b'\x1b[38;5;196m'
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`ColorStr` will parse raw SGR sequences, and accepts different types for `fg` and `bg`:
|
|
92
|
+
```python
|
|
93
|
+
from chromatic import ColorStr
|
|
94
|
+
|
|
95
|
+
red_fg = ColorStr('[*]', 0xFF0000, ansi_type='8b')
|
|
96
|
+
|
|
97
|
+
assert red_fg == ColorStr(b"\x1b[38;5;196m[*]")
|
|
98
|
+
assert red_fg == ColorStr('[*]', fg=(0xFF, 0, 0), ansi_type='8b')
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
ANSI color format can be specified with `ColorStr(ansi_type=...)`, or as a new object via `ColorStr.as_ansi_type()`:
|
|
102
|
+
```python
|
|
103
|
+
from chromatic import ColorStr, ansicolor4Bit, ansicolor24Bit, ansicolor8Bit
|
|
104
|
+
|
|
105
|
+
# each colorbytes type has an alias that you can use
|
|
106
|
+
assert all(
|
|
107
|
+
ansi_type.alias == alias
|
|
108
|
+
for ansi_type, alias in [
|
|
109
|
+
(ansicolor4Bit, '4b'),
|
|
110
|
+
(ansicolor8Bit, '8b'),
|
|
111
|
+
(ansicolor24Bit, '24b'),
|
|
112
|
+
]
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
truecolor = ColorStr('*', 0xFF0000, ansi_type=ansicolor24Bit)
|
|
116
|
+
a_16color = truecolor.as_ansi_type(ansicolor4Bit)
|
|
117
|
+
|
|
118
|
+
assert a_16color == truecolor.as_ansi_type('4b')
|
|
119
|
+
assert truecolor.ansi_format is ansicolor24Bit and truecolor.ansi == b'\x1b[38;2;255;0;0m'
|
|
120
|
+
assert a_16color.ansi_format is ansicolor4Bit and a_16color.ansi == b'\x1b[31m'
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Adding and removing SGR parameters from a `ColorStr`:
|
|
124
|
+
```python
|
|
125
|
+
import chromatic as cm
|
|
126
|
+
|
|
127
|
+
regular_str = cm.ColorStr('hello world')
|
|
128
|
+
|
|
129
|
+
assert regular_str.ansi == b''
|
|
130
|
+
|
|
131
|
+
bold_str = regular_str.bold()
|
|
132
|
+
|
|
133
|
+
assert bold_str.ansi == b'\x1b[1m'
|
|
134
|
+
|
|
135
|
+
# use ColorStr.update_sgr() to remove and add SGR values
|
|
136
|
+
unbold_str = bold_str.update_sgr(cm.SgrParameter.BOLD)
|
|
137
|
+
|
|
138
|
+
assert unbold_str == regular_str
|
|
139
|
+
assert bold_str == unbold_str + cm.SgrParameter.BOLD # __add__ can also be used
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Installation
|
|
143
|
+
Install the package using `pip`:
|
|
144
|
+
```bash
|
|
145
|
+
pip install chromatic-python
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Credits
|
|
149
|
+
Banner artwork: [main rules by Crasher (2002)](https://16colo.rs/pack/galza-14/CRS-MAIN.ANS)
|
|
@@ -1,102 +1,124 @@
|
|
|
1
|
-
](https://pypi.org/project/chromatic-python/)
|
|
4
|
-

|
|
5
|
-
[](https://pepy.tech/projects/chromatic-python)
|
|
6
|
-
[](https://mypy-lang.org/)
|
|
7
|
-
|
|
8
|
-
Chromatic is a library for processing and transforming ANSI escape sequences (colored terminal text).
|
|
9
|
-
|
|
10
|
-
It offers a collection of algorithms and types for a variety of use cases:
|
|
11
|
-
- Image-to-ASCII / Image-to-ANSI conversions.
|
|
12
|
-
- ANSI art rendering, with support for user-defined fonts.
|
|
13
|
-
- A `ColorStr` type
|
|
14
|
-
- [colorama](https://github.com/tartley/colorama/)-style wrappers (`Fore`, `Back`, `Style`).
|
|
15
|
-
-
|
|
16
|
-
- Et Cetera 😲
|
|
17
|
-
|
|
18
|
-
### Usage
|
|
19
|
-
####
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
assert
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
from chromatic
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/chromatic-python/)
|
|
4
|
+

|
|
5
|
+
[](https://pepy.tech/projects/chromatic-python)
|
|
6
|
+
[](https://mypy-lang.org/)
|
|
7
|
+
|
|
8
|
+
Chromatic is a library for processing and transforming ANSI escape sequences (colored terminal text).
|
|
9
|
+
|
|
10
|
+
It offers a collection of algorithms and types for a variety of use cases:
|
|
11
|
+
- Image-to-ASCII / Image-to-ANSI conversions.
|
|
12
|
+
- ANSI art rendering, with support for user-defined fonts.
|
|
13
|
+
- A `ColorStr` type for low-level control over ANSI SGR strings.
|
|
14
|
+
- [colorama](https://github.com/tartley/colorama/)-style wrappers (`Fore`, `Back`, `Style`).
|
|
15
|
+
- Conversion between 16-color, 256-color, and true-color (RGB) ANSI colorspace via the `colorbytes` type.
|
|
16
|
+
- Et Cetera 😲
|
|
17
|
+
|
|
18
|
+
### Usage
|
|
19
|
+
#### Image-to-ANSI conversion
|
|
20
|
+
|
|
21
|
+
Convert an image into a 2d ANSI string array, and render the ANSI array as image:
|
|
22
|
+
```python
|
|
23
|
+
from chromatic.color import ansicolor4Bit
|
|
24
|
+
from chromatic.image import ansi2img, img2ansi
|
|
25
|
+
from chromatic.data import userfont, butterfly
|
|
26
|
+
|
|
27
|
+
input_img = butterfly()
|
|
28
|
+
font = userfont['vga437']
|
|
29
|
+
|
|
30
|
+
# `char_set` is used to translate luminance to characters
|
|
31
|
+
# | <- index 0 is the 'darkest'
|
|
32
|
+
char_set = r"'·,•-_→+<>ⁿ*%⌂7√Iï∞πbz£9yîU{}1αHSw♥æ?GX╕╒éà⌡MF╝╩ΘûǃQ½☻Ŷ┤▄╪║▒█"
|
|
33
|
+
# index -1 is the 'brightest' -> |
|
|
34
|
+
|
|
35
|
+
# returns list[list[ColorStr]]
|
|
36
|
+
ansi_array = img2ansi(
|
|
37
|
+
input_img,
|
|
38
|
+
font,
|
|
39
|
+
sort_glyphs=False, # map `char_set` as-is
|
|
40
|
+
char_set=char_set,
|
|
41
|
+
ansi_type=ansicolor4Bit,
|
|
42
|
+
factor=200,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# print your image to stdout
|
|
46
|
+
print(*map(''.join, ansi_array), sep="\x1b[0m\n")
|
|
47
|
+
|
|
48
|
+
# returns a PIL.Image.Image object
|
|
49
|
+
ansi_img = ansi2img(ansi_array, font, font_size=16)
|
|
50
|
+
ansi_img.show()
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### ColorStr
|
|
54
|
+
```python
|
|
55
|
+
from chromatic import ColorStr
|
|
56
|
+
|
|
57
|
+
base_str = 'hello world'
|
|
58
|
+
|
|
59
|
+
red_fg = ColorStr(base_str, 0xFF0000, ansi_type='8b')
|
|
60
|
+
|
|
61
|
+
assert red_fg.base_str == base_str
|
|
62
|
+
assert red_fg.rgb_dict == {'fg': (0xFF, 0, 0)}
|
|
63
|
+
assert red_fg.ansi == b'\x1b[38;5;196m'
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`ColorStr` will parse raw SGR sequences, and accepts different types for `fg` and `bg`:
|
|
67
|
+
```python
|
|
68
|
+
from chromatic import ColorStr
|
|
69
|
+
|
|
70
|
+
red_fg = ColorStr('[*]', 0xFF0000, ansi_type='8b')
|
|
71
|
+
|
|
72
|
+
assert red_fg == ColorStr(b"\x1b[38;5;196m[*]")
|
|
73
|
+
assert red_fg == ColorStr('[*]', fg=(0xFF, 0, 0), ansi_type='8b')
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
ANSI color format can be specified with `ColorStr(ansi_type=...)`, or as a new object via `ColorStr.as_ansi_type()`:
|
|
77
|
+
```python
|
|
78
|
+
from chromatic import ColorStr, ansicolor4Bit, ansicolor24Bit, ansicolor8Bit
|
|
79
|
+
|
|
80
|
+
# each colorbytes type has an alias that you can use
|
|
81
|
+
assert all(
|
|
82
|
+
ansi_type.alias == alias
|
|
83
|
+
for ansi_type, alias in [
|
|
84
|
+
(ansicolor4Bit, '4b'),
|
|
85
|
+
(ansicolor8Bit, '8b'),
|
|
86
|
+
(ansicolor24Bit, '24b'),
|
|
87
|
+
]
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
truecolor = ColorStr('*', 0xFF0000, ansi_type=ansicolor24Bit)
|
|
91
|
+
a_16color = truecolor.as_ansi_type(ansicolor4Bit)
|
|
92
|
+
|
|
93
|
+
assert a_16color == truecolor.as_ansi_type('4b')
|
|
94
|
+
assert truecolor.ansi_format is ansicolor24Bit and truecolor.ansi == b'\x1b[38;2;255;0;0m'
|
|
95
|
+
assert a_16color.ansi_format is ansicolor4Bit and a_16color.ansi == b'\x1b[31m'
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Adding and removing SGR parameters from a `ColorStr`:
|
|
99
|
+
```python
|
|
100
|
+
import chromatic as cm
|
|
101
|
+
|
|
102
|
+
regular_str = cm.ColorStr('hello world')
|
|
103
|
+
|
|
104
|
+
assert regular_str.ansi == b''
|
|
105
|
+
|
|
106
|
+
bold_str = regular_str.bold()
|
|
107
|
+
|
|
108
|
+
assert bold_str.ansi == b'\x1b[1m'
|
|
109
|
+
|
|
110
|
+
# use ColorStr.update_sgr() to remove and add SGR values
|
|
111
|
+
unbold_str = bold_str.update_sgr(cm.SgrParameter.BOLD)
|
|
112
|
+
|
|
113
|
+
assert unbold_str == regular_str
|
|
114
|
+
assert bold_str == unbold_str + cm.SgrParameter.BOLD # __add__ can also be used
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Installation
|
|
118
|
+
Install the package using `pip`:
|
|
119
|
+
```bash
|
|
120
|
+
pip install chromatic-python
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Credits
|
|
124
|
+
Banner artwork: [main rules by Crasher (2002)](https://16colo.rs/pack/galza-14/CRS-MAIN.ANS)
|
|
Binary file
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
try:
|
|
2
|
-
from ._version import version as __version__
|
|
3
|
-
except ImportError:
|
|
4
|
-
__version__ = "0.0.0"
|
|
5
|
-
|
|
6
|
-
import lazy_loader as _lazy
|
|
7
|
-
|
|
8
|
-
__getattr__, __dir__, __all__ = _lazy.attach_stub(__name__, __file__)
|
|
1
|
+
try:
|
|
2
|
+
from ._version import version as __version__
|
|
3
|
+
except ImportError:
|
|
4
|
+
__version__ = "0.0.0"
|
|
5
|
+
|
|
6
|
+
import lazy_loader as _lazy
|
|
7
|
+
|
|
8
|
+
__getattr__, __dir__, __all__ = _lazy.attach_stub(__name__, __file__)
|