chromatic-python 0.8.0__tar.gz → 0.9.0__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.
Files changed (65) hide show
  1. chromatic_python-0.9.0/LICENSE +21 -0
  2. chromatic_python-0.9.0/PKG-INFO +179 -0
  3. chromatic_python-0.9.0/README.md +152 -0
  4. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/__main__.py +189 -71
  5. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/_typing.py +27 -11
  6. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/_version.py +3 -3
  7. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/color/colorconv.py +3 -3
  8. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/color/colorconv.pyi +3 -3
  9. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/color/core.py +11 -14
  10. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/color/core.pyi +10 -10
  11. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/color/palette.py +21 -26
  12. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/color/palette.pyi +2 -2
  13. chromatic_python-0.9.0/chromatic/data/__init__.py +14 -0
  14. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/data/userfont.py +40 -16
  15. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/image/_array.py +120 -128
  16. chromatic_python-0.9.0/chromatic_python.egg-info/PKG-INFO +179 -0
  17. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic_python.egg-info/SOURCES.txt +3 -7
  18. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic_python.egg-info/scm_file_list.json +3 -7
  19. chromatic_python-0.9.0/chromatic_python.egg-info/scm_version.json +8 -0
  20. chromatic_python-0.9.0/docs/cli/index.md +27 -0
  21. chromatic_python-0.9.0/docs/index.md +152 -0
  22. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/mkdocs.yml +6 -0
  23. chromatic_python-0.9.0/mkdocs_hooks.py +40 -0
  24. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/pyproject.toml +1 -1
  25. chromatic_python-0.8.0/PKG-INFO +0 -159
  26. chromatic_python-0.8.0/README.md +0 -134
  27. chromatic_python-0.8.0/chromatic/data/__init__.py +0 -40
  28. chromatic_python-0.8.0/chromatic/data/__init__.pyi +0 -18
  29. chromatic_python-0.8.0/chromatic/data/_fetchers.py +0 -69
  30. chromatic_python-0.8.0/chromatic/data/images/butterfly.jpg +0 -0
  31. chromatic_python-0.8.0/chromatic/data/images/escher.png +0 -0
  32. chromatic_python-0.8.0/chromatic/data/images/goblin_virus.png +0 -0
  33. chromatic_python-0.8.0/chromatic/data/images/registry.json +0 -5
  34. chromatic_python-0.8.0/chromatic/demo.py +0 -327
  35. chromatic_python-0.8.0/chromatic_python.egg-info/PKG-INFO +0 -159
  36. chromatic_python-0.8.0/chromatic_python.egg-info/scm_version.json +0 -8
  37. chromatic_python-0.8.0/docs/index.md +0 -134
  38. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/.gitattributes +0 -0
  39. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/.github/dependabot.yml +0 -0
  40. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/.github/workflows/docs.yml +0 -0
  41. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/.github/workflows/release.yml +0 -0
  42. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/.gitignore +0 -0
  43. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/banner.png +0 -0
  44. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/__init__.py +0 -0
  45. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/__init__.pyi +0 -0
  46. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/color/__init__.py +0 -0
  47. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/color/__init__.pyi +0 -0
  48. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/data/fonts/userfont.schema.json +0 -0
  49. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/data/fonts/vga437.ttf +0 -0
  50. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/data/userfont.pyi +0 -0
  51. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/image/__init__.py +0 -0
  52. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/image/__init__.pyi +0 -0
  53. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/image/_curses.py +0 -0
  54. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic/image/_glyph.py +0 -0
  55. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic_python.egg-info/dependency_links.txt +0 -0
  56. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic_python.egg-info/entry_points.txt +0 -0
  57. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic_python.egg-info/requires.txt +0 -0
  58. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/chromatic_python.egg-info/top_level.txt +0 -0
  59. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/docs/api/chromatic.md +0 -0
  60. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/docs/api/color.md +0 -0
  61. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/docs/api/data.md +0 -0
  62. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/docs/api/image.md +0 -0
  63. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/setup.cfg +0 -0
  64. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/tests/__init__.py +0 -0
  65. {chromatic_python-0.8.0 → chromatic_python-0.9.0}/tests/test_color_str.py +0 -0
@@ -0,0 +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
21
+ SOFTWARE.
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.4
2
+ Name: chromatic-python
3
+ Version: 0.9.0
4
+ Summary: ANSI art image processing and colored terminal text
5
+ Author: crypt0lith
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/crypt0lith/chromatic
8
+ Project-URL: Documentation, https://crypt0lith.github.io/chromatic
9
+ Keywords: ansi,ascii,art,font,image,terminal,parser
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Classifier: Typing :: Typed
17
+ Requires-Python: <4.0,>=3.12
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: numpy<2.8,>=2.1
21
+ Requires-Dist: pillow>=12.2.0
22
+ Requires-Dist: scipy>=1.11.4
23
+ Requires-Dist: opencv-python
24
+ Requires-Dist: fonttools>=4.60.2
25
+ Requires-Dist: lazy_loader
26
+ Dynamic: license-file
27
+
28
+ ![image](https://raw.githubusercontent.com/crypt0lith/chromatic/master/banner.png)
29
+
30
+ [![image](https://img.shields.io/pypi/v/chromatic-python)](https://pypi.org/project/chromatic-python/)
31
+ ![image](https://img.shields.io/pypi/pyversions/chromatic-python)
32
+ [![image](https://static.pepy.tech/badge/chromatic-python)](https://pepy.tech/projects/chromatic-python)
33
+ [![image](https://mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
34
+
35
+ Chromatic is a library for ANSI art image processing and colored terminal text.
36
+
37
+ It offers a collection of algorithms and types for a variety of use cases:
38
+
39
+ - Image-to-ASCII / Image-to-ANSI conversions.
40
+ - ANSI art rendering, with support for user-defined fonts.
41
+ - A `ColorStr` type for low-level control over ANSI SGR strings.
42
+ - [colorama](https://github.com/tartley/colorama/)-style wrappers (`Fore`, `Back`, `Style`).
43
+ - Conversion between 16-color, 256-color, and true-color (RGB) ANSI colorspace via the `colorbytes` type.
44
+ - Et Cetera 😲
45
+
46
+ ### Usage
47
+
48
+ #### `color_chain`
49
+
50
+ A `color_chain` is a printable sequence of colored text that round-trips with a NumPy array:
51
+
52
+ ```python
53
+ from chromatic import color_chain, ColorStr
54
+
55
+ cc = color_chain(
56
+ [ColorStr("hello", fg=0xFF0000), ColorStr(" world", fg=0x00FF00)], ansi_type="8b"
57
+ )
58
+
59
+ # parsed from a raw SGR string — no ansi_type needed
60
+ cc2 = color_chain("\x1b[38;5;196mhello\x1b[38;5;46m world")
61
+
62
+ assert cc == cc2
63
+
64
+ # red "hello", green " world"
65
+ print(cc)
66
+
67
+ # a structured ndarray of dtype [('char', '<U1'), ('sgr', '<u8'), ('rgb', 'u1', (2, 4))]
68
+ arr = cc.term_array()
69
+
70
+ assert str(color_chain.fromarray(arr)) == str(cc)
71
+ ```
72
+
73
+ #### `img2ansi`
74
+
75
+ `img2ansi` reads an image and returns a `color_chain`:
76
+
77
+ ```python
78
+ from chromatic import img2ansi
79
+ from chromatic.data import userfonts
80
+
81
+ font = userfonts["vga437"]
82
+
83
+ # the image, as ANSI art
84
+ cc = img2ansi("input.png", font, factor=200)
85
+ print(cc)
86
+
87
+ # or the raw ndarray
88
+ arr = img2ansi("input.png", font, factor=200, outarray=True)
89
+ ```
90
+
91
+ #### `ansi2img`
92
+
93
+ `ansi2img` renders a `color_chain` (or array) back to an image:
94
+
95
+ ```python
96
+ from chromatic import img2ansi, ansi2img
97
+ from chromatic.data import userfonts
98
+
99
+ font = userfonts["vga437"]
100
+
101
+ cc = img2ansi("input.png", font, factor=200)
102
+
103
+ # a PIL.Image.Image
104
+ img = ansi2img(cc, font, font_size=16)
105
+ img.show()
106
+ ```
107
+
108
+ #### `ansify`
109
+
110
+ `ansify` runs both steps at once, returning the rendered image with its array on `Image.info`:
111
+
112
+ ```python
113
+ from chromatic import ansify
114
+ from chromatic.data import userfonts
115
+
116
+ font = userfonts["vga437"]
117
+
118
+ img = ansify("input.png", font, font_size=16, factor=200)
119
+ img.show()
120
+
121
+ # the ndarray it rendered from
122
+ arr = img.info["ansi_array"]
123
+ ```
124
+
125
+ #### Animated images
126
+
127
+ An animated image becomes a list of `color_chain` frames, one per frame — so a GIF plays straight to the terminal:
128
+
129
+ ```python
130
+ import sys
131
+ import time
132
+
133
+ from chromatic import img2ansi
134
+ from chromatic.data import userfonts
135
+
136
+ font = userfonts["vga437"]
137
+
138
+ # list[color_chain], one per frame
139
+ frames = img2ansi("input.gif", font, factor=200)
140
+
141
+ for cc in frames:
142
+ # redraw each frame in place
143
+ sys.stdout.write(f"\x1b[H{cc}")
144
+ time.sleep(0.1)
145
+ ```
146
+
147
+ `ansify` renders the same GIF back to an animated image, and `chromatic image ansify input.gif --stdout` plays it in the terminal for you.
148
+
149
+ #### `ColorStr`
150
+
151
+ `ColorStr` is a `str` subclass that carries its SGR color as metadata; the escape codes only surface when you render it:
152
+
153
+ ```python
154
+ from chromatic import ColorStr
155
+
156
+ cs = ColorStr("hello world", fg=0xFF0000, ansi_type="8b")
157
+
158
+ assert isinstance(cs, str)
159
+
160
+ # the codes aren't part of the string itself
161
+ assert cs.base_str == "hello world"
162
+ assert len(cs) == len("hello world")
163
+
164
+ # they surface when you print / str() it
165
+ assert str(cs) == "\x1b[38;5;196mhello world\x1b[0m"
166
+ assert cs.ansi == b"\x1b[38;5;196m"
167
+ ```
168
+
169
+ ### Installation
170
+
171
+ Install the package using `pip`:
172
+
173
+ ```shell
174
+ pip install chromatic-python
175
+ ```
176
+
177
+ ### Credits
178
+
179
+ Banner artwork: [main rules by Crasher (2002)](https://16colo.rs/pack/galza-14/CRS-MAIN.ANS)
@@ -0,0 +1,152 @@
1
+ ![image](https://raw.githubusercontent.com/crypt0lith/chromatic/master/banner.png)
2
+
3
+ [![image](https://img.shields.io/pypi/v/chromatic-python)](https://pypi.org/project/chromatic-python/)
4
+ ![image](https://img.shields.io/pypi/pyversions/chromatic-python)
5
+ [![image](https://static.pepy.tech/badge/chromatic-python)](https://pepy.tech/projects/chromatic-python)
6
+ [![image](https://mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
7
+
8
+ Chromatic is a library for ANSI art image processing and colored terminal text.
9
+
10
+ It offers a collection of algorithms and types for a variety of use cases:
11
+
12
+ - Image-to-ASCII / Image-to-ANSI conversions.
13
+ - ANSI art rendering, with support for user-defined fonts.
14
+ - A `ColorStr` type for low-level control over ANSI SGR strings.
15
+ - [colorama](https://github.com/tartley/colorama/)-style wrappers (`Fore`, `Back`, `Style`).
16
+ - Conversion between 16-color, 256-color, and true-color (RGB) ANSI colorspace via the `colorbytes` type.
17
+ - Et Cetera 😲
18
+
19
+ ### Usage
20
+
21
+ #### `color_chain`
22
+
23
+ A `color_chain` is a printable sequence of colored text that round-trips with a NumPy array:
24
+
25
+ ```python
26
+ from chromatic import color_chain, ColorStr
27
+
28
+ cc = color_chain(
29
+ [ColorStr("hello", fg=0xFF0000), ColorStr(" world", fg=0x00FF00)], ansi_type="8b"
30
+ )
31
+
32
+ # parsed from a raw SGR string — no ansi_type needed
33
+ cc2 = color_chain("\x1b[38;5;196mhello\x1b[38;5;46m world")
34
+
35
+ assert cc == cc2
36
+
37
+ # red "hello", green " world"
38
+ print(cc)
39
+
40
+ # a structured ndarray of dtype [('char', '<U1'), ('sgr', '<u8'), ('rgb', 'u1', (2, 4))]
41
+ arr = cc.term_array()
42
+
43
+ assert str(color_chain.fromarray(arr)) == str(cc)
44
+ ```
45
+
46
+ #### `img2ansi`
47
+
48
+ `img2ansi` reads an image and returns a `color_chain`:
49
+
50
+ ```python
51
+ from chromatic import img2ansi
52
+ from chromatic.data import userfonts
53
+
54
+ font = userfonts["vga437"]
55
+
56
+ # the image, as ANSI art
57
+ cc = img2ansi("input.png", font, factor=200)
58
+ print(cc)
59
+
60
+ # or the raw ndarray
61
+ arr = img2ansi("input.png", font, factor=200, outarray=True)
62
+ ```
63
+
64
+ #### `ansi2img`
65
+
66
+ `ansi2img` renders a `color_chain` (or array) back to an image:
67
+
68
+ ```python
69
+ from chromatic import img2ansi, ansi2img
70
+ from chromatic.data import userfonts
71
+
72
+ font = userfonts["vga437"]
73
+
74
+ cc = img2ansi("input.png", font, factor=200)
75
+
76
+ # a PIL.Image.Image
77
+ img = ansi2img(cc, font, font_size=16)
78
+ img.show()
79
+ ```
80
+
81
+ #### `ansify`
82
+
83
+ `ansify` runs both steps at once, returning the rendered image with its array on `Image.info`:
84
+
85
+ ```python
86
+ from chromatic import ansify
87
+ from chromatic.data import userfonts
88
+
89
+ font = userfonts["vga437"]
90
+
91
+ img = ansify("input.png", font, font_size=16, factor=200)
92
+ img.show()
93
+
94
+ # the ndarray it rendered from
95
+ arr = img.info["ansi_array"]
96
+ ```
97
+
98
+ #### Animated images
99
+
100
+ An animated image becomes a list of `color_chain` frames, one per frame — so a GIF plays straight to the terminal:
101
+
102
+ ```python
103
+ import sys
104
+ import time
105
+
106
+ from chromatic import img2ansi
107
+ from chromatic.data import userfonts
108
+
109
+ font = userfonts["vga437"]
110
+
111
+ # list[color_chain], one per frame
112
+ frames = img2ansi("input.gif", font, factor=200)
113
+
114
+ for cc in frames:
115
+ # redraw each frame in place
116
+ sys.stdout.write(f"\x1b[H{cc}")
117
+ time.sleep(0.1)
118
+ ```
119
+
120
+ `ansify` renders the same GIF back to an animated image, and `chromatic image ansify input.gif --stdout` plays it in the terminal for you.
121
+
122
+ #### `ColorStr`
123
+
124
+ `ColorStr` is a `str` subclass that carries its SGR color as metadata; the escape codes only surface when you render it:
125
+
126
+ ```python
127
+ from chromatic import ColorStr
128
+
129
+ cs = ColorStr("hello world", fg=0xFF0000, ansi_type="8b")
130
+
131
+ assert isinstance(cs, str)
132
+
133
+ # the codes aren't part of the string itself
134
+ assert cs.base_str == "hello world"
135
+ assert len(cs) == len("hello world")
136
+
137
+ # they surface when you print / str() it
138
+ assert str(cs) == "\x1b[38;5;196mhello world\x1b[0m"
139
+ assert cs.ansi == b"\x1b[38;5;196m"
140
+ ```
141
+
142
+ ### Installation
143
+
144
+ Install the package using `pip`:
145
+
146
+ ```shell
147
+ pip install chromatic-python
148
+ ```
149
+
150
+ ### Credits
151
+
152
+ Banner artwork: [main rules by Crasher (2002)](https://16colo.rs/pack/galza-14/CRS-MAIN.ANS)