chromatic-python 0.4.0__tar.gz → 0.4.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.
Files changed (52) hide show
  1. chromatic_python-0.4.2/.gitattributes +20 -0
  2. chromatic_python-0.4.2/.github/workflows/publish.yml +29 -0
  3. chromatic_python-0.4.2/.gitignore +28 -0
  4. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/PKG-INFO +148 -149
  5. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/README.md +124 -124
  6. chromatic_python-0.4.2/banner.png +0 -0
  7. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/__init__.py +8 -8
  8. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/__init__.pyi +90 -90
  9. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/_typing.py +444 -443
  10. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/_version.py +34 -34
  11. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/color/__init__.py +3 -3
  12. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/color/__init__.pyi +90 -90
  13. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/color/colorconv.py +352 -352
  14. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/color/core.py +1749 -1710
  15. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/color/core.pyi +501 -515
  16. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/color/iterators.py +172 -172
  17. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/color/palette.py +591 -591
  18. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/color/palette.pyi +300 -300
  19. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/__init__.py +35 -33
  20. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/__init__.pyi +18 -16
  21. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/_fetchers.py +55 -55
  22. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/registry.json +4 -4
  23. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/userfont.py +139 -153
  24. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/userfont.pyi +32 -30
  25. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/userfont.schema.json +28 -28
  26. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/demo.py +380 -380
  27. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/image/__init__.py +5 -5
  28. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/image/__init__.pyi +70 -70
  29. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/image/_array.py +1380 -1324
  30. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/image/_curses.py +146 -148
  31. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/image/_glyph.py +90 -90
  32. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic_python.egg-info/PKG-INFO +148 -149
  33. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic_python.egg-info/SOURCES.txt +0 -2
  34. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/pyproject.toml +49 -49
  35. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/requirements.txt +53 -53
  36. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/setup.cfg +4 -4
  37. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/tests/test_color_str.py +356 -356
  38. chromatic_python-0.4.0/.gitattributes +0 -1
  39. chromatic_python-0.4.0/.github/workflows/publish.yml +0 -22
  40. chromatic_python-0.4.0/.github/workflows/tag-to-release.yml +0 -17
  41. chromatic_python-0.4.0/.gitignore +0 -6
  42. chromatic_python-0.4.0/LICENSE +0 -21
  43. chromatic_python-0.4.0/banner.png +0 -0
  44. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/butterfly.jpg +0 -0
  45. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/escher.png +0 -0
  46. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/fonts/consolas.ttf +0 -0
  47. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/fonts/vga437.ttf +0 -0
  48. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic/data/goblin_virus.png +0 -0
  49. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic_python.egg-info/dependency_links.txt +0 -0
  50. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic_python.egg-info/requires.txt +0 -0
  51. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/chromatic_python.egg-info/top_level.txt +0 -0
  52. {chromatic_python-0.4.0 → chromatic_python-0.4.2}/tests/__init__.py +0 -0
@@ -0,0 +1,20 @@
1
+ # python sources
2
+ *.py text diff=python
3
+ *.pyi text diff=python
4
+
5
+ # documents
6
+ *.md text diff=markdown
7
+ *.txt text
8
+
9
+ # graphics
10
+ *.png binary
11
+ *.jpg binary
12
+ *.jpeg binary
13
+ *.ttf binary
14
+ *.ttc binary
15
+
16
+ # serialization
17
+ *.json text
18
+ *.toml text
19
+ *.yaml text
20
+ *.yml text
@@ -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/*
@@ -0,0 +1,28 @@
1
+ # editor temp/backup files
2
+ *.bak
3
+ *.diff
4
+ .idea/
5
+ *.tmp
6
+ .vscode
7
+
8
+ # compiled source
9
+ *.dll
10
+ *.exe
11
+ *.o
12
+ *.o.d
13
+ *.py[ocd]
14
+ *.so
15
+ *.mod
16
+
17
+ # python files
18
+ build
19
+ build-*
20
+ dist
21
+ _version.py
22
+ doc/build
23
+ *.egg-info
24
+ venv/
25
+
26
+ # this project
27
+ userfont.json
28
+ tests/_*
@@ -1,149 +1,148 @@
1
- Metadata-Version: 2.4
2
- Name: chromatic-python
3
- Version: 0.4.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
- ![image](https://raw.githubusercontent.com/crypt0lith/chromatic/master/banner.png)
27
-
28
- [![image](https://img.shields.io/pypi/v/chromatic-python)](https://pypi.org/project/chromatic-python/)
29
- ![image](https://img.shields.io/pypi/pyversions/chromatic-python)
30
- [![image](https://static.pepy.tech/badge/chromatic-python)](https://pepy.tech/projects/chromatic-python)
31
- [![image](https://mypy-lang.org/static/mypy_badge.svg)](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
+ Metadata-Version: 2.4
2
+ Name: chromatic-python
3
+ Version: 0.4.2
4
+ Summary: ANSI art image processing and colored terminal text
5
+ Author: crypt0lith
6
+ License-Expression: MIT
7
+ Project-URL: repository, https://github.com/crypt0lith/chromatic.git
8
+ Keywords: ansi,ascii,art,font,image,terminal,parser
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.12
14
+ Description-Content-Type: text/markdown
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
+
25
+ ![image](https://raw.githubusercontent.com/crypt0lith/chromatic/master/banner.png)
26
+
27
+ [![image](https://img.shields.io/pypi/v/chromatic-python)](https://pypi.org/project/chromatic-python/)
28
+ ![image](https://img.shields.io/pypi/pyversions/chromatic-python)
29
+ [![image](https://static.pepy.tech/badge/chromatic-python)](https://pepy.tech/projects/chromatic-python)
30
+ [![image](https://mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
31
+
32
+ Chromatic is a library for processing and transforming ANSI escape sequences (colored terminal text).
33
+
34
+ It offers a collection of algorithms and types for a variety of use cases:
35
+ - Image-to-ASCII / Image-to-ANSI conversions.
36
+ - ANSI art rendering, with support for user-defined fonts.
37
+ - A `ColorStr` type for low-level control over ANSI SGR strings.
38
+ - [colorama](https://github.com/tartley/colorama/)-style wrappers (`Fore`, `Back`, `Style`).
39
+ - Conversion between 16-color, 256-color, and true-color (RGB) ANSI colorspace via the `colorbytes` type.
40
+ - Et Cetera 😲
41
+
42
+ ### Usage
43
+ #### Image-to-ANSI conversion
44
+
45
+ Convert an image into a 2d ANSI string array, and render the ANSI array as image:
46
+ ```python
47
+ from chromatic.color import ansicolor4Bit
48
+ from chromatic.image import ansi2img, img2ansi
49
+ from chromatic.data import userfont, butterfly
50
+
51
+ input_img = butterfly()
52
+ font = userfont['vga437']
53
+
54
+ # `char_set` is used to translate luminance to characters
55
+ # | <- index 0 is the 'darkest'
56
+ char_set = r"'·,•-_→+<>ⁿ*%⌂7√Iï∞πbz£9yîU{}1αHSw♥æ?GX╕╒éà⌡MF╝╩ΘûǃQ½☻Ŷ┤▄╪║▒█"
57
+ # index -1 is the 'brightest' -> |
58
+
59
+ # returns list[list[ColorStr]]
60
+ ansi_array = img2ansi(
61
+ input_img,
62
+ font,
63
+ sort_glyphs=False, # map `char_set` as-is
64
+ char_set=char_set,
65
+ ansi_type=ansicolor4Bit,
66
+ factor=200,
67
+ )
68
+
69
+ # print your image to stdout
70
+ print(*map(''.join, ansi_array), sep="\x1b[0m\n")
71
+
72
+ # returns a PIL.Image.Image object
73
+ ansi_img = ansi2img(ansi_array, font, font_size=16)
74
+ ansi_img.show()
75
+ ```
76
+
77
+ #### ColorStr
78
+ ```python
79
+ from chromatic import ColorStr
80
+
81
+ base_str = 'hello world'
82
+
83
+ red_fg = ColorStr(base_str, 0xFF0000, ansi_type='8b')
84
+
85
+ assert red_fg.base_str == base_str
86
+ assert red_fg.rgb_dict == {'fg': (0xFF, 0, 0)}
87
+ assert red_fg.ansi == b'\x1b[38;5;196m'
88
+ ```
89
+
90
+ `ColorStr` will parse raw SGR sequences, and accepts different types for `fg` and `bg`:
91
+ ```python
92
+ from chromatic import ColorStr
93
+
94
+ red_fg = ColorStr('[*]', 0xFF0000, ansi_type='8b')
95
+
96
+ assert red_fg == ColorStr(b"\x1b[38;5;196m[*]")
97
+ assert red_fg == ColorStr('[*]', fg=(0xFF, 0, 0), ansi_type='8b')
98
+ ```
99
+
100
+ ANSI color format can be specified with `ColorStr(ansi_type=...)`, or as a new object via `ColorStr.as_ansi_type()`:
101
+ ```python
102
+ from chromatic import ColorStr, ansicolor4Bit, ansicolor24Bit, ansicolor8Bit
103
+
104
+ # each colorbytes type has an alias that you can use
105
+ assert all(
106
+ ansi_type.alias == alias
107
+ for ansi_type, alias in [
108
+ (ansicolor4Bit, '4b'),
109
+ (ansicolor8Bit, '8b'),
110
+ (ansicolor24Bit, '24b'),
111
+ ]
112
+ )
113
+
114
+ truecolor = ColorStr('*', 0xFF0000, ansi_type=ansicolor24Bit)
115
+ a_16color = truecolor.as_ansi_type(ansicolor4Bit)
116
+
117
+ assert a_16color == truecolor.as_ansi_type('4b')
118
+ assert truecolor.ansi_format is ansicolor24Bit and truecolor.ansi == b'\x1b[38;2;255;0;0m'
119
+ assert a_16color.ansi_format is ansicolor4Bit and a_16color.ansi == b'\x1b[31m'
120
+ ```
121
+
122
+ Adding and removing SGR parameters from a `ColorStr`:
123
+ ```python
124
+ import chromatic as cm
125
+
126
+ regular_str = cm.ColorStr('hello world')
127
+
128
+ assert regular_str.ansi == b''
129
+
130
+ bold_str = regular_str.bold()
131
+
132
+ assert bold_str.ansi == b'\x1b[1m'
133
+
134
+ # use ColorStr.update_sgr() to remove and add SGR values
135
+ unbold_str = bold_str.update_sgr(cm.SgrParameter.BOLD)
136
+
137
+ assert unbold_str == regular_str
138
+ assert bold_str == unbold_str + cm.SgrParameter.BOLD # __add__ can also be used
139
+ ```
140
+
141
+ ### Installation
142
+ Install the package using `pip`:
143
+ ```bash
144
+ pip install chromatic-python
145
+ ```
146
+
147
+ ### Credits
148
+ Banner artwork: [main rules by Crasher (2002)](https://16colo.rs/pack/galza-14/CRS-MAIN.ANS)
@@ -1,124 +1,124 @@
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 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)
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 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__)