kittytgp 0.0.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.
kittytgp-0.0.1/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,91 @@
1
+ Metadata-Version: 2.4
2
+ Name: kittytgp
3
+ Version: 0.0.1
4
+ Summary: Tiny kitty graphics protocol PNG renderer using Unicode placeholders
5
+ Author: Jeremy Howard
6
+ License: Apache-2.0
7
+ Project-URL: Source, https://github.com/answerdotai/kittytgp
8
+ Keywords: kitty,terminal,graphics,tmux,png
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: POSIX
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Topic :: Terminals
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Dynamic: license-file
22
+
23
+ # kittytgp
24
+
25
+ `kittytgp` is a small pure-Python package that renders a PNG with kitty's graphics protocol using Unicode placeholders (`U+10EEEE`).
26
+
27
+ It follows kitty's tmux/editor-friendly placeholder flow:
28
+
29
+ 1. transmit PNG data with kitty graphics protocol
30
+ 2. create a **virtual** placement with `U=1`
31
+ 3. print `U+10EEEE` placeholder text colored with the image ID
32
+
33
+ Because the visible part is ordinary Unicode text, the image moves with the text buffer and works inside hosts such as tmux.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pip install kittytgp
39
+ ```
40
+
41
+ ## CLI
42
+
43
+ ```bash
44
+ kittytgp plot.png
45
+ ```
46
+
47
+ Useful options:
48
+
49
+ ```bash
50
+ kittytgp plot.png --cols 40
51
+ kittytgp plot.png --rows 20
52
+ kittytgp plot.png --cell-size 10x20
53
+ kittytgp plot.png --passthrough tmux
54
+ kittytgp plot.png --image-id 0x123456
55
+ kittytgp plot.png --no-newline
56
+ ```
57
+
58
+ Inside tmux, enable passthrough:
59
+
60
+ ```tmux
61
+ set -g allow-passthrough on
62
+ ```
63
+
64
+ ## Python API
65
+
66
+ ```python
67
+ from kittytgp import render_png
68
+
69
+ render_png("plot.png")
70
+ ```
71
+
72
+ Or build the bytes yourself:
73
+
74
+ ```python
75
+ from kittytgp import build_render_bytes
76
+
77
+ payload = build_render_bytes("plot.png")
78
+ ```
79
+
80
+ ## Design notes
81
+
82
+ This package intentionally stays small:
83
+
84
+ - PNG input only
85
+ - direct transfer (`f=100` PNG payload in APC chunks)
86
+ - Unicode placeholders only
87
+ - 24-bit image IDs encoded in truecolor foreground color
88
+ - tmux passthrough only when needed
89
+
90
+ By default it fits the image into the current terminal while preserving aspect ratio. If the terminal cannot report cell pixel size, pass `--cell-size`, `--cols`, or `--rows`.
91
+
@@ -0,0 +1,69 @@
1
+ # kittytgp
2
+
3
+ `kittytgp` is a small pure-Python package that renders a PNG with kitty's graphics protocol using Unicode placeholders (`U+10EEEE`).
4
+
5
+ It follows kitty's tmux/editor-friendly placeholder flow:
6
+
7
+ 1. transmit PNG data with kitty graphics protocol
8
+ 2. create a **virtual** placement with `U=1`
9
+ 3. print `U+10EEEE` placeholder text colored with the image ID
10
+
11
+ Because the visible part is ordinary Unicode text, the image moves with the text buffer and works inside hosts such as tmux.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pip install kittytgp
17
+ ```
18
+
19
+ ## CLI
20
+
21
+ ```bash
22
+ kittytgp plot.png
23
+ ```
24
+
25
+ Useful options:
26
+
27
+ ```bash
28
+ kittytgp plot.png --cols 40
29
+ kittytgp plot.png --rows 20
30
+ kittytgp plot.png --cell-size 10x20
31
+ kittytgp plot.png --passthrough tmux
32
+ kittytgp plot.png --image-id 0x123456
33
+ kittytgp plot.png --no-newline
34
+ ```
35
+
36
+ Inside tmux, enable passthrough:
37
+
38
+ ```tmux
39
+ set -g allow-passthrough on
40
+ ```
41
+
42
+ ## Python API
43
+
44
+ ```python
45
+ from kittytgp import render_png
46
+
47
+ render_png("plot.png")
48
+ ```
49
+
50
+ Or build the bytes yourself:
51
+
52
+ ```python
53
+ from kittytgp import build_render_bytes
54
+
55
+ payload = build_render_bytes("plot.png")
56
+ ```
57
+
58
+ ## Design notes
59
+
60
+ This package intentionally stays small:
61
+
62
+ - PNG input only
63
+ - direct transfer (`f=100` PNG payload in APC chunks)
64
+ - Unicode placeholders only
65
+ - 24-bit image IDs encoded in truecolor foreground color
66
+ - tmux passthrough only when needed
67
+
68
+ By default it fits the image into the current terminal while preserving aspect ratio. If the terminal cannot report cell pixel size, pass `--cell-size`, `--cols`, or `--rows`.
69
+
@@ -0,0 +1,2 @@
1
+ from .core import build_render_bytes, render_png
2
+ __version__ = "0.0.1"
@@ -0,0 +1,3 @@
1
+ from .core import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,403 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import base64
5
+ import math
6
+ import os
7
+ import secrets
8
+ import shutil
9
+ import struct
10
+ import subprocess
11
+ import sys
12
+ from dataclasses import dataclass
13
+ from importlib import resources
14
+ from pathlib import Path
15
+ from typing import BinaryIO
16
+
17
+ try:
18
+ import fcntl
19
+ import termios
20
+ except ImportError: # pragma: no cover
21
+ fcntl = None
22
+ termios = None
23
+
24
+ PLACEHOLDER = "\U0010EEEE"
25
+ PNG_SIGNATURE = b"\x89PNG\r\n\x1a\n"
26
+ DEFAULT_CHUNK_SIZE = 4096
27
+
28
+
29
+ @dataclass(frozen=True)
30
+ class TerminalGeometry:
31
+ cols: int
32
+ rows: int
33
+ cell_width_px: int
34
+ cell_height_px: int
35
+
36
+
37
+ def _load_diacritics() -> tuple[str, ...]:
38
+ text = resources.files("kittytgp").joinpath("rowcolumn_diacritics.txt").read_text(encoding="utf-8")
39
+ out: list[str] = []
40
+ for line in text.splitlines():
41
+ line = line.strip()
42
+ if not line or line.startswith("#"):
43
+ continue
44
+ out.append(chr(int(line.split(";", 1)[0], 16)))
45
+ if not out:
46
+ raise RuntimeError("Could not load kitty row/column diacritics")
47
+ return tuple(out)
48
+
49
+
50
+ DIACRITICS = _load_diacritics()
51
+
52
+
53
+ def _parse_png_size(data: bytes) -> tuple[int, int]:
54
+ if not data.startswith(PNG_SIGNATURE):
55
+ raise ValueError("input is not a PNG file")
56
+ if len(data) < 24:
57
+ raise ValueError("PNG is too short")
58
+ ihdr_len = struct.unpack(">I", data[8:12])[0]
59
+ if ihdr_len != 13 or data[12:16] != b"IHDR":
60
+ raise ValueError("PNG does not start with an IHDR chunk")
61
+ width, height = struct.unpack(">II", data[16:24])
62
+ if width <= 0 or height <= 0:
63
+ raise ValueError("PNG has invalid dimensions")
64
+ return width, height
65
+
66
+
67
+ def _read_png(path_or_bytes: str | os.PathLike[str] | bytes) -> tuple[bytes, int, int]:
68
+ if isinstance(path_or_bytes, bytes):
69
+ data = path_or_bytes
70
+ else:
71
+ data = Path(path_or_bytes).read_bytes()
72
+ width, height = _parse_png_size(data)
73
+ return data, width, height
74
+
75
+
76
+ def _ioctl_winsize(fileno: int) -> tuple[int, int, int, int] | None:
77
+ if fcntl is None or termios is None:
78
+ return None
79
+ try:
80
+ packed = fcntl.ioctl(fileno, termios.TIOCGWINSZ, struct.pack("HHHH", 0, 0, 0, 0))
81
+ rows, cols, xpixel, ypixel = struct.unpack("HHHH", packed)
82
+ except OSError:
83
+ return None
84
+ return rows, cols, xpixel, ypixel
85
+
86
+
87
+ def _tmux_cell_size() -> tuple[int, int] | None:
88
+ if not os.environ.get("TMUX"):
89
+ return None
90
+ try:
91
+ proc = subprocess.run(
92
+ ["tmux", "display-message", "-p", "#{client_cell_width} #{client_cell_height}"],
93
+ check=True,
94
+ stdout=subprocess.PIPE,
95
+ stderr=subprocess.DEVNULL,
96
+ text=True,
97
+ )
98
+ except Exception:
99
+ return None
100
+ parts = proc.stdout.strip().split()
101
+ if len(parts) != 2:
102
+ return None
103
+ try:
104
+ width, height = (int(parts[0]), int(parts[1]))
105
+ except ValueError:
106
+ return None
107
+ if width <= 0 or height <= 0:
108
+ return None
109
+ return width, height
110
+
111
+
112
+ def _geometry_from_fileno(
113
+ fileno: int,
114
+ *,
115
+ cell_width_px: int | None,
116
+ cell_height_px: int | None,
117
+ ) -> TerminalGeometry | None:
118
+ winsize = _ioctl_winsize(fileno)
119
+ if winsize is None:
120
+ return None
121
+ rows, cols, xpixel, ypixel = winsize
122
+ if cols <= 0 or rows <= 0:
123
+ return None
124
+ if cell_width_px is not None and cell_height_px is not None:
125
+ return TerminalGeometry(cols=cols, rows=rows, cell_width_px=cell_width_px, cell_height_px=cell_height_px)
126
+ if xpixel > 0 and ypixel > 0:
127
+ return TerminalGeometry(
128
+ cols=cols,
129
+ rows=rows,
130
+ cell_width_px=max(1, xpixel // cols),
131
+ cell_height_px=max(1, ypixel // rows),
132
+ )
133
+ tmux_cell = _tmux_cell_size()
134
+ if tmux_cell is not None:
135
+ return TerminalGeometry(cols=cols, rows=rows, cell_width_px=tmux_cell[0], cell_height_px=tmux_cell[1])
136
+ return None
137
+
138
+
139
+ def get_terminal_geometry(
140
+ fileno: int,
141
+ *,
142
+ cell_width_px: int | None = None,
143
+ cell_height_px: int | None = None,
144
+ ) -> TerminalGeometry:
145
+ geom = _geometry_from_fileno(fileno, cell_width_px=cell_width_px, cell_height_px=cell_height_px)
146
+ if geom is not None:
147
+ return geom
148
+ try:
149
+ with open("/dev/tty", "rb", buffering=0) as tty:
150
+ geom = _geometry_from_fileno(tty.fileno(), cell_width_px=cell_width_px, cell_height_px=cell_height_px)
151
+ except OSError:
152
+ geom = None
153
+ if geom is not None:
154
+ return geom
155
+ size = shutil.get_terminal_size(fallback=(80, 24))
156
+ if cell_width_px is not None and cell_height_px is not None:
157
+ return TerminalGeometry(
158
+ cols=size.columns,
159
+ rows=size.lines,
160
+ cell_width_px=cell_width_px,
161
+ cell_height_px=cell_height_px,
162
+ )
163
+ raise RuntimeError("unable to determine terminal cell size; pass --cell-size, --cols, or --rows")
164
+
165
+
166
+ def _fit_cells(
167
+ image_width_px: int,
168
+ image_height_px: int,
169
+ geometry: TerminalGeometry,
170
+ *,
171
+ cols: int | None,
172
+ rows: int | None,
173
+ newline: bool,
174
+ ) -> tuple[int, int]:
175
+ if cols is not None and cols <= 0:
176
+ raise ValueError("cols must be positive")
177
+ if rows is not None and rows <= 0:
178
+ raise ValueError("rows must be positive")
179
+
180
+ cw = geometry.cell_width_px
181
+ ch = geometry.cell_height_px
182
+
183
+ if cols is not None and rows is not None:
184
+ return cols, rows
185
+ if cols is not None:
186
+ rows = math.ceil((image_height_px * cols * cw) / (image_width_px * ch))
187
+ return max(1, cols), max(1, rows)
188
+ if rows is not None:
189
+ cols = math.ceil((image_width_px * rows * ch) / (image_height_px * cw))
190
+ return max(1, cols), max(1, rows)
191
+
192
+ avail_cols = max(1, geometry.cols)
193
+ avail_rows = max(1, geometry.rows - (1 if newline else 0))
194
+ scale = min(
195
+ (avail_cols * cw) / image_width_px,
196
+ (avail_rows * ch) / image_height_px,
197
+ 1.0,
198
+ )
199
+ width_px = max(1, math.ceil(image_width_px * scale))
200
+ height_px = max(1, math.ceil(image_height_px * scale))
201
+ return max(1, math.ceil(width_px / cw)), max(1, math.ceil(height_px / ch))
202
+
203
+
204
+ def _resolve_passthrough(mode: str) -> str:
205
+ if mode not in {"auto", "none", "tmux"}:
206
+ raise ValueError("passthrough must be 'auto', 'none', or 'tmux'")
207
+ if mode == "auto":
208
+ return "tmux" if os.environ.get("TMUX") else "none"
209
+ return mode
210
+
211
+
212
+ def _wrap_tmux_passthrough(seq: bytes) -> bytes:
213
+ return b"\x1bPtmux;" + seq.replace(b"\x1b", b"\x1b\x1b") + b"\x1b\\"
214
+
215
+
216
+ def _graphics_apc(control: str, payload: bytes, *, passthrough: str) -> bytes:
217
+ seq = b"\x1b_G" + control.encode("ascii") + b";" + payload + b"\x1b\\"
218
+ return _wrap_tmux_passthrough(seq) if passthrough == "tmux" else seq
219
+
220
+
221
+ def _iter_transmit_chunks(
222
+ png_data: bytes,
223
+ *,
224
+ cols: int,
225
+ rows: int,
226
+ image_id: int,
227
+ chunk_size: int,
228
+ passthrough: str,
229
+ ) -> list[bytes]:
230
+ encoded = base64.standard_b64encode(png_data)
231
+ chunks = [encoded[i : i + chunk_size] for i in range(0, len(encoded), chunk_size)] or [b""]
232
+ out: list[bytes] = []
233
+ for i, chunk in enumerate(chunks):
234
+ more = 1 if i < len(chunks) - 1 else 0
235
+ meta = f"a=T,f=100,q=2,U=1,i={image_id},c={cols},r={rows}," if i == 0 else ""
236
+ out.append(_graphics_apc(f"{meta}m={more}", chunk, passthrough=passthrough))
237
+ return out
238
+
239
+
240
+ def _placeholder_grid(cols: int, rows: int, image_id: int) -> str:
241
+ if rows > len(DIACRITICS):
242
+ raise ValueError(f"too many rows for kitty Unicode placeholders: {rows} > {len(DIACRITICS)}")
243
+ if cols <= 0 or rows <= 0:
244
+ raise ValueError("cols and rows must be positive")
245
+ r = (image_id >> 16) & 255
246
+ g = (image_id >> 8) & 255
247
+ b = image_id & 255
248
+ prefix = f"\x1b[38;2;{r};{g};{b}m"
249
+ line_fill = PLACEHOLDER * max(0, cols - 1)
250
+ lines = [PLACEHOLDER + DIACRITICS[row] + line_fill for row in range(rows)]
251
+ return prefix + "\n".join(lines) + "\x1b[39m"
252
+
253
+
254
+ def normalize_image_id(image_id: int | None) -> int:
255
+ if image_id is None:
256
+ return secrets.randbelow((1 << 24) - 1) + 1
257
+ image_id &= 0xFFFFFFFF
258
+ if image_id == 0:
259
+ raise ValueError("image_id must be non-zero")
260
+ if image_id >= (1 << 24):
261
+ raise ValueError("image_id must fit in 24 bits for this minimal renderer")
262
+ return image_id
263
+
264
+
265
+ def build_render_bytes(
266
+ png: str | os.PathLike[str] | bytes,
267
+ *,
268
+ cols: int | None = None,
269
+ rows: int | None = None,
270
+ image_id: int | None = None,
271
+ passthrough: str = "auto",
272
+ cell_width_px: int | None = None,
273
+ cell_height_px: int | None = None,
274
+ chunk_size: int = DEFAULT_CHUNK_SIZE,
275
+ newline: bool = True,
276
+ out: BinaryIO | None = None,
277
+ ) -> bytes:
278
+ if chunk_size <= 0:
279
+ raise ValueError("chunk_size must be positive")
280
+
281
+ png_data, image_width_px, image_height_px = _read_png(png)
282
+ image_id = normalize_image_id(image_id)
283
+ passthrough = _resolve_passthrough(passthrough)
284
+
285
+ if cols is None or rows is None:
286
+ stream = out or sys.stdout.buffer
287
+ geometry = get_terminal_geometry(
288
+ stream.fileno(),
289
+ cell_width_px=cell_width_px,
290
+ cell_height_px=cell_height_px,
291
+ )
292
+ cols, rows = _fit_cells(
293
+ image_width_px,
294
+ image_height_px,
295
+ geometry,
296
+ cols=cols,
297
+ rows=rows,
298
+ newline=newline,
299
+ )
300
+
301
+ pieces = _iter_transmit_chunks(
302
+ png_data,
303
+ cols=cols,
304
+ rows=rows,
305
+ image_id=image_id,
306
+ chunk_size=chunk_size,
307
+ passthrough=passthrough,
308
+ )
309
+ pieces.append(_placeholder_grid(cols, rows, image_id).encode("utf-8"))
310
+ if newline:
311
+ pieces.append(b"\n")
312
+ return b"".join(pieces)
313
+
314
+
315
+ def render_png(
316
+ png: str | os.PathLike[str] | bytes,
317
+ *,
318
+ cols: int | None = None,
319
+ rows: int | None = None,
320
+ image_id: int | None = None,
321
+ passthrough: str = "auto",
322
+ cell_width_px: int | None = None,
323
+ cell_height_px: int | None = None,
324
+ chunk_size: int = DEFAULT_CHUNK_SIZE,
325
+ newline: bool = True,
326
+ out: BinaryIO | None = None,
327
+ ) -> int:
328
+ image_id = normalize_image_id(image_id)
329
+ payload = build_render_bytes(
330
+ png,
331
+ cols=cols,
332
+ rows=rows,
333
+ image_id=image_id,
334
+ passthrough=passthrough,
335
+ cell_width_px=cell_width_px,
336
+ cell_height_px=cell_height_px,
337
+ chunk_size=chunk_size,
338
+ newline=newline,
339
+ out=out,
340
+ )
341
+ stream = out or sys.stdout.buffer
342
+ stream.write(payload)
343
+ stream.flush()
344
+ return image_id
345
+
346
+
347
+ def _parse_cell_size(value: str) -> tuple[int, int]:
348
+ value = value.lower()
349
+ if "x" not in value:
350
+ raise argparse.ArgumentTypeError("cell size must be WIDTHxHEIGHT")
351
+ left, right = value.split("x", 1)
352
+ try:
353
+ width, height = int(left), int(right)
354
+ except ValueError as exc:
355
+ raise argparse.ArgumentTypeError("cell size must be WIDTHxHEIGHT") from exc
356
+ if width <= 0 or height <= 0:
357
+ raise argparse.ArgumentTypeError("cell size must use positive integers")
358
+ return width, height
359
+
360
+
361
+ def build_arg_parser() -> argparse.ArgumentParser:
362
+ parser = argparse.ArgumentParser(description="Render a PNG with kitty Unicode placeholders")
363
+ parser.add_argument("png", help="Path to a PNG file, or - to read PNG bytes from stdin")
364
+ parser.add_argument("--cols", type=int, help="target width in terminal cells")
365
+ parser.add_argument("--rows", type=int, help="target height in terminal cells")
366
+ parser.add_argument("--cell-size", type=_parse_cell_size, help="manual terminal cell size in pixels, e.g. 10x20")
367
+ parser.add_argument("--image-id", type=lambda s: int(s, 0), help="24-bit image id (decimal or 0x-prefixed hex)")
368
+ parser.add_argument(
369
+ "--passthrough",
370
+ choices=("auto", "none", "tmux"),
371
+ default="auto",
372
+ help="wrap kitty APC commands for tmux passthrough",
373
+ )
374
+ parser.add_argument("--chunk-size", type=int, default=DEFAULT_CHUNK_SIZE, help="base64 bytes per graphics chunk")
375
+ parser.add_argument("--no-newline", action="store_true", help="do not print a trailing newline after the image")
376
+ return parser
377
+
378
+
379
+ def _load_cli_png(arg: str) -> bytes | str:
380
+ return sys.stdin.buffer.read() if arg == "-" else arg
381
+
382
+
383
+ def main(argv: list[str] | None = None) -> int:
384
+ parser = build_arg_parser()
385
+ args = parser.parse_args(argv)
386
+ cell_width_px = cell_height_px = None
387
+ if args.cell_size is not None:
388
+ cell_width_px, cell_height_px = args.cell_size
389
+ try:
390
+ render_png(
391
+ _load_cli_png(args.png),
392
+ cols=args.cols,
393
+ rows=args.rows,
394
+ image_id=args.image_id,
395
+ passthrough=args.passthrough,
396
+ cell_width_px=cell_width_px,
397
+ cell_height_px=cell_height_px,
398
+ chunk_size=args.chunk_size,
399
+ newline=not args.no_newline,
400
+ )
401
+ except Exception as exc:
402
+ parser.exit(1, f"kittytgp: {exc}\n")
403
+ return 0
@@ -0,0 +1,310 @@
1
+ # This file lists the diacritics used to indicate row/column numbers for
2
+ # Unicode terminal image placeholders. It is derived from UnicodeData.txt for
3
+ # Unicode 6.0.0 (chosen somewhat arbitrarily: it's old enough, but still
4
+ # contains more than 255 suitable combining chars) using the following
5
+ # command:
6
+ #
7
+ # cat UnicodeData.txt | grep "Mn;230;NSM;;" | grep -v "0300\|0301\|0302\|0303\|0304\|0306\|0307\|0308\|0309\|030A\|030B\|030C\|030F\|0311\|0313\|0314\|0342\|0653\|0654"
8
+ #
9
+ # That is, we use combining chars of the same combining class 230 (above the
10
+ # base character) that do not have decomposition mappings, and we also remove
11
+ # some characters that may be fused with other characters during normalization,
12
+ # like 0041 0300 -> 00C0 which is À (A with grave).
13
+ #
14
+ 0305;COMBINING OVERLINE;Mn;230;NSM;;;;;N;NON-SPACING OVERSCORE;;;;
15
+ 030D;COMBINING VERTICAL LINE ABOVE;Mn;230;NSM;;;;;N;NON-SPACING VERTICAL LINE ABOVE;;;;
16
+ 030E;COMBINING DOUBLE VERTICAL LINE ABOVE;Mn;230;NSM;;;;;N;NON-SPACING DOUBLE VERTICAL LINE ABOVE;;;;
17
+ 0310;COMBINING CANDRABINDU;Mn;230;NSM;;;;;N;NON-SPACING CANDRABINDU;;;;
18
+ 0312;COMBINING TURNED COMMA ABOVE;Mn;230;NSM;;;;;N;NON-SPACING TURNED COMMA ABOVE;;;;
19
+ 033D;COMBINING X ABOVE;Mn;230;NSM;;;;;N;NON-SPACING X ABOVE;;;;
20
+ 033E;COMBINING VERTICAL TILDE;Mn;230;NSM;;;;;N;NON-SPACING VERTICAL TILDE;;;;
21
+ 033F;COMBINING DOUBLE OVERLINE;Mn;230;NSM;;;;;N;NON-SPACING DOUBLE OVERSCORE;;;;
22
+ 0346;COMBINING BRIDGE ABOVE;Mn;230;NSM;;;;;N;;;;;
23
+ 034A;COMBINING NOT TILDE ABOVE;Mn;230;NSM;;;;;N;;;;;
24
+ 034B;COMBINING HOMOTHETIC ABOVE;Mn;230;NSM;;;;;N;;;;;
25
+ 034C;COMBINING ALMOST EQUAL TO ABOVE;Mn;230;NSM;;;;;N;;;;;
26
+ 0350;COMBINING RIGHT ARROWHEAD ABOVE;Mn;230;NSM;;;;;N;;;;;
27
+ 0351;COMBINING LEFT HALF RING ABOVE;Mn;230;NSM;;;;;N;;;;;
28
+ 0352;COMBINING FERMATA;Mn;230;NSM;;;;;N;;;;;
29
+ 0357;COMBINING RIGHT HALF RING ABOVE;Mn;230;NSM;;;;;N;;;;;
30
+ 035B;COMBINING ZIGZAG ABOVE;Mn;230;NSM;;;;;N;;;;;
31
+ 0363;COMBINING LATIN SMALL LETTER A;Mn;230;NSM;;;;;N;;;;;
32
+ 0364;COMBINING LATIN SMALL LETTER E;Mn;230;NSM;;;;;N;;;;;
33
+ 0365;COMBINING LATIN SMALL LETTER I;Mn;230;NSM;;;;;N;;;;;
34
+ 0366;COMBINING LATIN SMALL LETTER O;Mn;230;NSM;;;;;N;;;;;
35
+ 0367;COMBINING LATIN SMALL LETTER U;Mn;230;NSM;;;;;N;;;;;
36
+ 0368;COMBINING LATIN SMALL LETTER C;Mn;230;NSM;;;;;N;;;;;
37
+ 0369;COMBINING LATIN SMALL LETTER D;Mn;230;NSM;;;;;N;;;;;
38
+ 036A;COMBINING LATIN SMALL LETTER H;Mn;230;NSM;;;;;N;;;;;
39
+ 036B;COMBINING LATIN SMALL LETTER M;Mn;230;NSM;;;;;N;;;;;
40
+ 036C;COMBINING LATIN SMALL LETTER R;Mn;230;NSM;;;;;N;;;;;
41
+ 036D;COMBINING LATIN SMALL LETTER T;Mn;230;NSM;;;;;N;;;;;
42
+ 036E;COMBINING LATIN SMALL LETTER V;Mn;230;NSM;;;;;N;;;;;
43
+ 036F;COMBINING LATIN SMALL LETTER X;Mn;230;NSM;;;;;N;;;;;
44
+ 0483;COMBINING CYRILLIC TITLO;Mn;230;NSM;;;;;N;CYRILLIC NON-SPACING TITLO;;;;
45
+ 0484;COMBINING CYRILLIC PALATALIZATION;Mn;230;NSM;;;;;N;CYRILLIC NON-SPACING PALATALIZATION;;;;
46
+ 0485;COMBINING CYRILLIC DASIA PNEUMATA;Mn;230;NSM;;;;;N;CYRILLIC NON-SPACING DASIA PNEUMATA;;;;
47
+ 0486;COMBINING CYRILLIC PSILI PNEUMATA;Mn;230;NSM;;;;;N;CYRILLIC NON-SPACING PSILI PNEUMATA;;;;
48
+ 0487;COMBINING CYRILLIC POKRYTIE;Mn;230;NSM;;;;;N;;;;;
49
+ 0592;HEBREW ACCENT SEGOL;Mn;230;NSM;;;;;N;;;;;
50
+ 0593;HEBREW ACCENT SHALSHELET;Mn;230;NSM;;;;;N;;;;;
51
+ 0594;HEBREW ACCENT ZAQEF QATAN;Mn;230;NSM;;;;;N;;;;;
52
+ 0595;HEBREW ACCENT ZAQEF GADOL;Mn;230;NSM;;;;;N;;;;;
53
+ 0597;HEBREW ACCENT REVIA;Mn;230;NSM;;;;;N;;;;;
54
+ 0598;HEBREW ACCENT ZARQA;Mn;230;NSM;;;;;N;;;;;
55
+ 0599;HEBREW ACCENT PASHTA;Mn;230;NSM;;;;;N;;;;;
56
+ 059C;HEBREW ACCENT GERESH;Mn;230;NSM;;;;;N;;;;;
57
+ 059D;HEBREW ACCENT GERESH MUQDAM;Mn;230;NSM;;;;;N;;;;;
58
+ 059E;HEBREW ACCENT GERSHAYIM;Mn;230;NSM;;;;;N;;;;;
59
+ 059F;HEBREW ACCENT QARNEY PARA;Mn;230;NSM;;;;;N;;;;;
60
+ 05A0;HEBREW ACCENT TELISHA GEDOLA;Mn;230;NSM;;;;;N;;;;;
61
+ 05A1;HEBREW ACCENT PAZER;Mn;230;NSM;;;;;N;;;;;
62
+ 05A8;HEBREW ACCENT QADMA;Mn;230;NSM;;;;;N;;;;;
63
+ 05A9;HEBREW ACCENT TELISHA QETANA;Mn;230;NSM;;;;;N;;;;;
64
+ 05AB;HEBREW ACCENT OLE;Mn;230;NSM;;;;;N;;;;;
65
+ 05AC;HEBREW ACCENT ILUY;Mn;230;NSM;;;;;N;;;;;
66
+ 05AF;HEBREW MARK MASORA CIRCLE;Mn;230;NSM;;;;;N;;;;;
67
+ 05C4;HEBREW MARK UPPER DOT;Mn;230;NSM;;;;;N;;;;;
68
+ 0610;ARABIC SIGN SALLALLAHOU ALAYHE WASSALLAM;Mn;230;NSM;;;;;N;;;;;
69
+ 0611;ARABIC SIGN ALAYHE ASSALLAM;Mn;230;NSM;;;;;N;;;;;
70
+ 0612;ARABIC SIGN RAHMATULLAH ALAYHE;Mn;230;NSM;;;;;N;;;;;
71
+ 0613;ARABIC SIGN RADI ALLAHOU ANHU;Mn;230;NSM;;;;;N;;;;;
72
+ 0614;ARABIC SIGN TAKHALLUS;Mn;230;NSM;;;;;N;;;;;
73
+ 0615;ARABIC SMALL HIGH TAH;Mn;230;NSM;;;;;N;;;;;
74
+ 0616;ARABIC SMALL HIGH LIGATURE ALEF WITH LAM WITH YEH;Mn;230;NSM;;;;;N;;;;;
75
+ 0617;ARABIC SMALL HIGH ZAIN;Mn;230;NSM;;;;;N;;;;;
76
+ 0657;ARABIC INVERTED DAMMA;Mn;230;NSM;;;;;N;;;;;
77
+ 0658;ARABIC MARK NOON GHUNNA;Mn;230;NSM;;;;;N;;;;;
78
+ 0659;ARABIC ZWARAKAY;Mn;230;NSM;;;;;N;;;;;
79
+ 065A;ARABIC VOWEL SIGN SMALL V ABOVE;Mn;230;NSM;;;;;N;;;;;
80
+ 065B;ARABIC VOWEL SIGN INVERTED SMALL V ABOVE;Mn;230;NSM;;;;;N;;;;;
81
+ 065D;ARABIC REVERSED DAMMA;Mn;230;NSM;;;;;N;;;;;
82
+ 065E;ARABIC FATHA WITH TWO DOTS;Mn;230;NSM;;;;;N;;;;;
83
+ 06D6;ARABIC SMALL HIGH LIGATURE SAD WITH LAM WITH ALEF MAKSURA;Mn;230;NSM;;;;;N;;;;;
84
+ 06D7;ARABIC SMALL HIGH LIGATURE QAF WITH LAM WITH ALEF MAKSURA;Mn;230;NSM;;;;;N;;;;;
85
+ 06D8;ARABIC SMALL HIGH MEEM INITIAL FORM;Mn;230;NSM;;;;;N;;;;;
86
+ 06D9;ARABIC SMALL HIGH LAM ALEF;Mn;230;NSM;;;;;N;;;;;
87
+ 06DA;ARABIC SMALL HIGH JEEM;Mn;230;NSM;;;;;N;;;;;
88
+ 06DB;ARABIC SMALL HIGH THREE DOTS;Mn;230;NSM;;;;;N;;;;;
89
+ 06DC;ARABIC SMALL HIGH SEEN;Mn;230;NSM;;;;;N;;;;;
90
+ 06DF;ARABIC SMALL HIGH ROUNDED ZERO;Mn;230;NSM;;;;;N;;;;;
91
+ 06E0;ARABIC SMALL HIGH UPRIGHT RECTANGULAR ZERO;Mn;230;NSM;;;;;N;;;;;
92
+ 06E1;ARABIC SMALL HIGH DOTLESS HEAD OF KHAH;Mn;230;NSM;;;;;N;;;;;
93
+ 06E2;ARABIC SMALL HIGH MEEM ISOLATED FORM;Mn;230;NSM;;;;;N;;;;;
94
+ 06E4;ARABIC SMALL HIGH MADDA;Mn;230;NSM;;;;;N;;;;;
95
+ 06E7;ARABIC SMALL HIGH YEH;Mn;230;NSM;;;;;N;;;;;
96
+ 06E8;ARABIC SMALL HIGH NOON;Mn;230;NSM;;;;;N;;;;;
97
+ 06EB;ARABIC EMPTY CENTRE HIGH STOP;Mn;230;NSM;;;;;N;;;;;
98
+ 06EC;ARABIC ROUNDED HIGH STOP WITH FILLED CENTRE;Mn;230;NSM;;;;;N;;;;;
99
+ 0730;SYRIAC PTHAHA ABOVE;Mn;230;NSM;;;;;N;;;;;
100
+ 0732;SYRIAC PTHAHA DOTTED;Mn;230;NSM;;;;;N;;;;;
101
+ 0733;SYRIAC ZQAPHA ABOVE;Mn;230;NSM;;;;;N;;;;;
102
+ 0735;SYRIAC ZQAPHA DOTTED;Mn;230;NSM;;;;;N;;;;;
103
+ 0736;SYRIAC RBASA ABOVE;Mn;230;NSM;;;;;N;;;;;
104
+ 073A;SYRIAC HBASA ABOVE;Mn;230;NSM;;;;;N;;;;;
105
+ 073D;SYRIAC ESASA ABOVE;Mn;230;NSM;;;;;N;;;;;
106
+ 073F;SYRIAC RWAHA;Mn;230;NSM;;;;;N;;;;;
107
+ 0740;SYRIAC FEMININE DOT;Mn;230;NSM;;;;;N;;;;;
108
+ 0741;SYRIAC QUSHSHAYA;Mn;230;NSM;;;;;N;;;;;
109
+ 0743;SYRIAC TWO VERTICAL DOTS ABOVE;Mn;230;NSM;;;;;N;;;;;
110
+ 0745;SYRIAC THREE DOTS ABOVE;Mn;230;NSM;;;;;N;;;;;
111
+ 0747;SYRIAC OBLIQUE LINE ABOVE;Mn;230;NSM;;;;;N;;;;;
112
+ 0749;SYRIAC MUSIC;Mn;230;NSM;;;;;N;;;;;
113
+ 074A;SYRIAC BARREKH;Mn;230;NSM;;;;;N;;;;;
114
+ 07EB;NKO COMBINING SHORT HIGH TONE;Mn;230;NSM;;;;;N;;;;;
115
+ 07EC;NKO COMBINING SHORT LOW TONE;Mn;230;NSM;;;;;N;;;;;
116
+ 07ED;NKO COMBINING SHORT RISING TONE;Mn;230;NSM;;;;;N;;;;;
117
+ 07EE;NKO COMBINING LONG DESCENDING TONE;Mn;230;NSM;;;;;N;;;;;
118
+ 07EF;NKO COMBINING LONG HIGH TONE;Mn;230;NSM;;;;;N;;;;;
119
+ 07F0;NKO COMBINING LONG LOW TONE;Mn;230;NSM;;;;;N;;;;;
120
+ 07F1;NKO COMBINING LONG RISING TONE;Mn;230;NSM;;;;;N;;;;;
121
+ 07F3;NKO COMBINING DOUBLE DOT ABOVE;Mn;230;NSM;;;;;N;;;;;
122
+ 0816;SAMARITAN MARK IN;Mn;230;NSM;;;;;N;;;;;
123
+ 0817;SAMARITAN MARK IN-ALAF;Mn;230;NSM;;;;;N;;;;;
124
+ 0818;SAMARITAN MARK OCCLUSION;Mn;230;NSM;;;;;N;;;;;
125
+ 0819;SAMARITAN MARK DAGESH;Mn;230;NSM;;;;;N;;;;;
126
+ 081B;SAMARITAN MARK EPENTHETIC YUT;Mn;230;NSM;;;;;N;;;;;
127
+ 081C;SAMARITAN VOWEL SIGN LONG E;Mn;230;NSM;;;;;N;;;;;
128
+ 081D;SAMARITAN VOWEL SIGN E;Mn;230;NSM;;;;;N;;;;;
129
+ 081E;SAMARITAN VOWEL SIGN OVERLONG AA;Mn;230;NSM;;;;;N;;;;;
130
+ 081F;SAMARITAN VOWEL SIGN LONG AA;Mn;230;NSM;;;;;N;;;;;
131
+ 0820;SAMARITAN VOWEL SIGN AA;Mn;230;NSM;;;;;N;;;;;
132
+ 0821;SAMARITAN VOWEL SIGN OVERLONG A;Mn;230;NSM;;;;;N;;;;;
133
+ 0822;SAMARITAN VOWEL SIGN LONG A;Mn;230;NSM;;;;;N;;;;;
134
+ 0823;SAMARITAN VOWEL SIGN A;Mn;230;NSM;;;;;N;;;;;
135
+ 0825;SAMARITAN VOWEL SIGN SHORT A;Mn;230;NSM;;;;;N;;;;;
136
+ 0826;SAMARITAN VOWEL SIGN LONG U;Mn;230;NSM;;;;;N;;;;;
137
+ 0827;SAMARITAN VOWEL SIGN U;Mn;230;NSM;;;;;N;;;;;
138
+ 0829;SAMARITAN VOWEL SIGN LONG I;Mn;230;NSM;;;;;N;;;;;
139
+ 082A;SAMARITAN VOWEL SIGN I;Mn;230;NSM;;;;;N;;;;;
140
+ 082B;SAMARITAN VOWEL SIGN O;Mn;230;NSM;;;;;N;;;;;
141
+ 082C;SAMARITAN VOWEL SIGN SUKUN;Mn;230;NSM;;;;;N;;;;;
142
+ 082D;SAMARITAN MARK NEQUDAA;Mn;230;NSM;;;;;N;;;;;
143
+ 0951;DEVANAGARI STRESS SIGN UDATTA;Mn;230;NSM;;;;;N;;;;;
144
+ 0953;DEVANAGARI GRAVE ACCENT;Mn;230;NSM;;;;;N;;;;;
145
+ 0954;DEVANAGARI ACUTE ACCENT;Mn;230;NSM;;;;;N;;;;;
146
+ 0F82;TIBETAN SIGN NYI ZLA NAA DA;Mn;230;NSM;;;;;N;TIBETAN CANDRABINDU WITH ORNAMENT;;;;
147
+ 0F83;TIBETAN SIGN SNA LDAN;Mn;230;NSM;;;;;N;TIBETAN CANDRABINDU;;;;
148
+ 0F86;TIBETAN SIGN LCI RTAGS;Mn;230;NSM;;;;;N;;;;;
149
+ 0F87;TIBETAN SIGN YANG RTAGS;Mn;230;NSM;;;;;N;;;;;
150
+ 135D;ETHIOPIC COMBINING GEMINATION AND VOWEL LENGTH MARK;Mn;230;NSM;;;;;N;;;;;
151
+ 135E;ETHIOPIC COMBINING VOWEL LENGTH MARK;Mn;230;NSM;;;;;N;;;;;
152
+ 135F;ETHIOPIC COMBINING GEMINATION MARK;Mn;230;NSM;;;;;N;;;;;
153
+ 17DD;KHMER SIGN ATTHACAN;Mn;230;NSM;;;;;N;;;;;
154
+ 193A;LIMBU SIGN KEMPHRENG;Mn;230;NSM;;;;;N;;;;;
155
+ 1A17;BUGINESE VOWEL SIGN I;Mn;230;NSM;;;;;N;;;;;
156
+ 1A75;TAI THAM SIGN TONE-1;Mn;230;NSM;;;;;N;;;;;
157
+ 1A76;TAI THAM SIGN TONE-2;Mn;230;NSM;;;;;N;;;;;
158
+ 1A77;TAI THAM SIGN KHUEN TONE-3;Mn;230;NSM;;;;;N;;;;;
159
+ 1A78;TAI THAM SIGN KHUEN TONE-4;Mn;230;NSM;;;;;N;;;;;
160
+ 1A79;TAI THAM SIGN KHUEN TONE-5;Mn;230;NSM;;;;;N;;;;;
161
+ 1A7A;TAI THAM SIGN RA HAAM;Mn;230;NSM;;;;;N;;;;;
162
+ 1A7B;TAI THAM SIGN MAI SAM;Mn;230;NSM;;;;;N;;;;;
163
+ 1A7C;TAI THAM SIGN KHUEN-LUE KARAN;Mn;230;NSM;;;;;N;;;;;
164
+ 1B6B;BALINESE MUSICAL SYMBOL COMBINING TEGEH;Mn;230;NSM;;;;;N;;;;;
165
+ 1B6D;BALINESE MUSICAL SYMBOL COMBINING KEMPUL;Mn;230;NSM;;;;;N;;;;;
166
+ 1B6E;BALINESE MUSICAL SYMBOL COMBINING KEMPLI;Mn;230;NSM;;;;;N;;;;;
167
+ 1B6F;BALINESE MUSICAL SYMBOL COMBINING JEGOGAN;Mn;230;NSM;;;;;N;;;;;
168
+ 1B70;BALINESE MUSICAL SYMBOL COMBINING KEMPUL WITH JEGOGAN;Mn;230;NSM;;;;;N;;;;;
169
+ 1B71;BALINESE MUSICAL SYMBOL COMBINING KEMPLI WITH JEGOGAN;Mn;230;NSM;;;;;N;;;;;
170
+ 1B72;BALINESE MUSICAL SYMBOL COMBINING BENDE;Mn;230;NSM;;;;;N;;;;;
171
+ 1B73;BALINESE MUSICAL SYMBOL COMBINING GONG;Mn;230;NSM;;;;;N;;;;;
172
+ 1CD0;VEDIC TONE KARSHANA;Mn;230;NSM;;;;;N;;;;;
173
+ 1CD1;VEDIC TONE SHARA;Mn;230;NSM;;;;;N;;;;;
174
+ 1CD2;VEDIC TONE PRENKHA;Mn;230;NSM;;;;;N;;;;;
175
+ 1CDA;VEDIC TONE DOUBLE SVARITA;Mn;230;NSM;;;;;N;;;;;
176
+ 1CDB;VEDIC TONE TRIPLE SVARITA;Mn;230;NSM;;;;;N;;;;;
177
+ 1CE0;VEDIC TONE RIGVEDIC KASHMIRI INDEPENDENT SVARITA;Mn;230;NSM;;;;;N;;;;;
178
+ 1DC0;COMBINING DOTTED GRAVE ACCENT;Mn;230;NSM;;;;;N;;;;;
179
+ 1DC1;COMBINING DOTTED ACUTE ACCENT;Mn;230;NSM;;;;;N;;;;;
180
+ 1DC3;COMBINING SUSPENSION MARK;Mn;230;NSM;;;;;N;;;;;
181
+ 1DC4;COMBINING MACRON-ACUTE;Mn;230;NSM;;;;;N;;;;;
182
+ 1DC5;COMBINING GRAVE-MACRON;Mn;230;NSM;;;;;N;;;;;
183
+ 1DC6;COMBINING MACRON-GRAVE;Mn;230;NSM;;;;;N;;;;;
184
+ 1DC7;COMBINING ACUTE-MACRON;Mn;230;NSM;;;;;N;;;;;
185
+ 1DC8;COMBINING GRAVE-ACUTE-GRAVE;Mn;230;NSM;;;;;N;;;;;
186
+ 1DC9;COMBINING ACUTE-GRAVE-ACUTE;Mn;230;NSM;;;;;N;;;;;
187
+ 1DCB;COMBINING BREVE-MACRON;Mn;230;NSM;;;;;N;;;;;
188
+ 1DCC;COMBINING MACRON-BREVE;Mn;230;NSM;;;;;N;;;;;
189
+ 1DD1;COMBINING UR ABOVE;Mn;230;NSM;;;;;N;;;;;
190
+ 1DD2;COMBINING US ABOVE;Mn;230;NSM;;;;;N;;;;;
191
+ 1DD3;COMBINING LATIN SMALL LETTER FLATTENED OPEN A ABOVE;Mn;230;NSM;;;;;N;;;;;
192
+ 1DD4;COMBINING LATIN SMALL LETTER AE;Mn;230;NSM;;;;;N;;;;;
193
+ 1DD5;COMBINING LATIN SMALL LETTER AO;Mn;230;NSM;;;;;N;;;;;
194
+ 1DD6;COMBINING LATIN SMALL LETTER AV;Mn;230;NSM;;;;;N;;;;;
195
+ 1DD7;COMBINING LATIN SMALL LETTER C CEDILLA;Mn;230;NSM;;;;;N;;;;;
196
+ 1DD8;COMBINING LATIN SMALL LETTER INSULAR D;Mn;230;NSM;;;;;N;;;;;
197
+ 1DD9;COMBINING LATIN SMALL LETTER ETH;Mn;230;NSM;;;;;N;;;;;
198
+ 1DDA;COMBINING LATIN SMALL LETTER G;Mn;230;NSM;;;;;N;;;;;
199
+ 1DDB;COMBINING LATIN LETTER SMALL CAPITAL G;Mn;230;NSM;;;;;N;;;;;
200
+ 1DDC;COMBINING LATIN SMALL LETTER K;Mn;230;NSM;;;;;N;;;;;
201
+ 1DDD;COMBINING LATIN SMALL LETTER L;Mn;230;NSM;;;;;N;;;;;
202
+ 1DDE;COMBINING LATIN LETTER SMALL CAPITAL L;Mn;230;NSM;;;;;N;;;;;
203
+ 1DDF;COMBINING LATIN LETTER SMALL CAPITAL M;Mn;230;NSM;;;;;N;;;;;
204
+ 1DE0;COMBINING LATIN SMALL LETTER N;Mn;230;NSM;;;;;N;;;;;
205
+ 1DE1;COMBINING LATIN LETTER SMALL CAPITAL N;Mn;230;NSM;;;;;N;;;;;
206
+ 1DE2;COMBINING LATIN LETTER SMALL CAPITAL R;Mn;230;NSM;;;;;N;;;;;
207
+ 1DE3;COMBINING LATIN SMALL LETTER R ROTUNDA;Mn;230;NSM;;;;;N;;;;;
208
+ 1DE4;COMBINING LATIN SMALL LETTER S;Mn;230;NSM;;;;;N;;;;;
209
+ 1DE5;COMBINING LATIN SMALL LETTER LONG S;Mn;230;NSM;;;;;N;;;;;
210
+ 1DE6;COMBINING LATIN SMALL LETTER Z;Mn;230;NSM;;;;;N;;;;;
211
+ 1DFE;COMBINING LEFT ARROWHEAD ABOVE;Mn;230;NSM;;;;;N;;;;;
212
+ 20D0;COMBINING LEFT HARPOON ABOVE;Mn;230;NSM;;;;;N;NON-SPACING LEFT HARPOON ABOVE;;;;
213
+ 20D1;COMBINING RIGHT HARPOON ABOVE;Mn;230;NSM;;;;;N;NON-SPACING RIGHT HARPOON ABOVE;;;;
214
+ 20D4;COMBINING ANTICLOCKWISE ARROW ABOVE;Mn;230;NSM;;;;;N;NON-SPACING ANTICLOCKWISE ARROW ABOVE;;;;
215
+ 20D5;COMBINING CLOCKWISE ARROW ABOVE;Mn;230;NSM;;;;;N;NON-SPACING CLOCKWISE ARROW ABOVE;;;;
216
+ 20D6;COMBINING LEFT ARROW ABOVE;Mn;230;NSM;;;;;N;NON-SPACING LEFT ARROW ABOVE;;;;
217
+ 20D7;COMBINING RIGHT ARROW ABOVE;Mn;230;NSM;;;;;N;NON-SPACING RIGHT ARROW ABOVE;;;;
218
+ 20DB;COMBINING THREE DOTS ABOVE;Mn;230;NSM;;;;;N;NON-SPACING THREE DOTS ABOVE;;;;
219
+ 20DC;COMBINING FOUR DOTS ABOVE;Mn;230;NSM;;;;;N;NON-SPACING FOUR DOTS ABOVE;;;;
220
+ 20E1;COMBINING LEFT RIGHT ARROW ABOVE;Mn;230;NSM;;;;;N;NON-SPACING LEFT RIGHT ARROW ABOVE;;;;
221
+ 20E7;COMBINING ANNUITY SYMBOL;Mn;230;NSM;;;;;N;;;;;
222
+ 20E9;COMBINING WIDE BRIDGE ABOVE;Mn;230;NSM;;;;;N;;;;;
223
+ 20F0;COMBINING ASTERISK ABOVE;Mn;230;NSM;;;;;N;;;;;
224
+ 2CEF;COPTIC COMBINING NI ABOVE;Mn;230;NSM;;;;;N;;;;;
225
+ 2CF0;COPTIC COMBINING SPIRITUS ASPER;Mn;230;NSM;;;;;N;;;;;
226
+ 2CF1;COPTIC COMBINING SPIRITUS LENIS;Mn;230;NSM;;;;;N;;;;;
227
+ 2DE0;COMBINING CYRILLIC LETTER BE;Mn;230;NSM;;;;;N;;;;;
228
+ 2DE1;COMBINING CYRILLIC LETTER VE;Mn;230;NSM;;;;;N;;;;;
229
+ 2DE2;COMBINING CYRILLIC LETTER GHE;Mn;230;NSM;;;;;N;;;;;
230
+ 2DE3;COMBINING CYRILLIC LETTER DE;Mn;230;NSM;;;;;N;;;;;
231
+ 2DE4;COMBINING CYRILLIC LETTER ZHE;Mn;230;NSM;;;;;N;;;;;
232
+ 2DE5;COMBINING CYRILLIC LETTER ZE;Mn;230;NSM;;;;;N;;;;;
233
+ 2DE6;COMBINING CYRILLIC LETTER KA;Mn;230;NSM;;;;;N;;;;;
234
+ 2DE7;COMBINING CYRILLIC LETTER EL;Mn;230;NSM;;;;;N;;;;;
235
+ 2DE8;COMBINING CYRILLIC LETTER EM;Mn;230;NSM;;;;;N;;;;;
236
+ 2DE9;COMBINING CYRILLIC LETTER EN;Mn;230;NSM;;;;;N;;;;;
237
+ 2DEA;COMBINING CYRILLIC LETTER O;Mn;230;NSM;;;;;N;;;;;
238
+ 2DEB;COMBINING CYRILLIC LETTER PE;Mn;230;NSM;;;;;N;;;;;
239
+ 2DEC;COMBINING CYRILLIC LETTER ER;Mn;230;NSM;;;;;N;;;;;
240
+ 2DED;COMBINING CYRILLIC LETTER ES;Mn;230;NSM;;;;;N;;;;;
241
+ 2DEE;COMBINING CYRILLIC LETTER TE;Mn;230;NSM;;;;;N;;;;;
242
+ 2DEF;COMBINING CYRILLIC LETTER HA;Mn;230;NSM;;;;;N;;;;;
243
+ 2DF0;COMBINING CYRILLIC LETTER TSE;Mn;230;NSM;;;;;N;;;;;
244
+ 2DF1;COMBINING CYRILLIC LETTER CHE;Mn;230;NSM;;;;;N;;;;;
245
+ 2DF2;COMBINING CYRILLIC LETTER SHA;Mn;230;NSM;;;;;N;;;;;
246
+ 2DF3;COMBINING CYRILLIC LETTER SHCHA;Mn;230;NSM;;;;;N;;;;;
247
+ 2DF4;COMBINING CYRILLIC LETTER FITA;Mn;230;NSM;;;;;N;;;;;
248
+ 2DF5;COMBINING CYRILLIC LETTER ES-TE;Mn;230;NSM;;;;;N;;;;;
249
+ 2DF6;COMBINING CYRILLIC LETTER A;Mn;230;NSM;;;;;N;;;;;
250
+ 2DF7;COMBINING CYRILLIC LETTER IE;Mn;230;NSM;;;;;N;;;;;
251
+ 2DF8;COMBINING CYRILLIC LETTER DJERV;Mn;230;NSM;;;;;N;;;;;
252
+ 2DF9;COMBINING CYRILLIC LETTER MONOGRAPH UK;Mn;230;NSM;;;;;N;;;;;
253
+ 2DFA;COMBINING CYRILLIC LETTER YAT;Mn;230;NSM;;;;;N;;;;;
254
+ 2DFB;COMBINING CYRILLIC LETTER YU;Mn;230;NSM;;;;;N;;;;;
255
+ 2DFC;COMBINING CYRILLIC LETTER IOTIFIED A;Mn;230;NSM;;;;;N;;;;;
256
+ 2DFD;COMBINING CYRILLIC LETTER LITTLE YUS;Mn;230;NSM;;;;;N;;;;;
257
+ 2DFE;COMBINING CYRILLIC LETTER BIG YUS;Mn;230;NSM;;;;;N;;;;;
258
+ 2DFF;COMBINING CYRILLIC LETTER IOTIFIED BIG YUS;Mn;230;NSM;;;;;N;;;;;
259
+ A66F;COMBINING CYRILLIC VZMET;Mn;230;NSM;;;;;N;;;;;
260
+ A67C;COMBINING CYRILLIC KAVYKA;Mn;230;NSM;;;;;N;;;;;
261
+ A67D;COMBINING CYRILLIC PAYEROK;Mn;230;NSM;;;;;N;;;;;
262
+ A6F0;BAMUM COMBINING MARK KOQNDON;Mn;230;NSM;;;;;N;;;;;
263
+ A6F1;BAMUM COMBINING MARK TUKWENTIS;Mn;230;NSM;;;;;N;;;;;
264
+ A8E0;COMBINING DEVANAGARI DIGIT ZERO;Mn;230;NSM;;;;;N;;;;;
265
+ A8E1;COMBINING DEVANAGARI DIGIT ONE;Mn;230;NSM;;;;;N;;;;;
266
+ A8E2;COMBINING DEVANAGARI DIGIT TWO;Mn;230;NSM;;;;;N;;;;;
267
+ A8E3;COMBINING DEVANAGARI DIGIT THREE;Mn;230;NSM;;;;;N;;;;;
268
+ A8E4;COMBINING DEVANAGARI DIGIT FOUR;Mn;230;NSM;;;;;N;;;;;
269
+ A8E5;COMBINING DEVANAGARI DIGIT FIVE;Mn;230;NSM;;;;;N;;;;;
270
+ A8E6;COMBINING DEVANAGARI DIGIT SIX;Mn;230;NSM;;;;;N;;;;;
271
+ A8E7;COMBINING DEVANAGARI DIGIT SEVEN;Mn;230;NSM;;;;;N;;;;;
272
+ A8E8;COMBINING DEVANAGARI DIGIT EIGHT;Mn;230;NSM;;;;;N;;;;;
273
+ A8E9;COMBINING DEVANAGARI DIGIT NINE;Mn;230;NSM;;;;;N;;;;;
274
+ A8EA;COMBINING DEVANAGARI LETTER A;Mn;230;NSM;;;;;N;;;;;
275
+ A8EB;COMBINING DEVANAGARI LETTER U;Mn;230;NSM;;;;;N;;;;;
276
+ A8EC;COMBINING DEVANAGARI LETTER KA;Mn;230;NSM;;;;;N;;;;;
277
+ A8ED;COMBINING DEVANAGARI LETTER NA;Mn;230;NSM;;;;;N;;;;;
278
+ A8EE;COMBINING DEVANAGARI LETTER PA;Mn;230;NSM;;;;;N;;;;;
279
+ A8EF;COMBINING DEVANAGARI LETTER RA;Mn;230;NSM;;;;;N;;;;;
280
+ A8F0;COMBINING DEVANAGARI LETTER VI;Mn;230;NSM;;;;;N;;;;;
281
+ A8F1;COMBINING DEVANAGARI SIGN AVAGRAHA;Mn;230;NSM;;;;;N;;;;;
282
+ AAB0;TAI VIET MAI KANG;Mn;230;NSM;;;;;N;;;;;
283
+ AAB2;TAI VIET VOWEL I;Mn;230;NSM;;;;;N;;;;;
284
+ AAB3;TAI VIET VOWEL UE;Mn;230;NSM;;;;;N;;;;;
285
+ AAB7;TAI VIET MAI KHIT;Mn;230;NSM;;;;;N;;;;;
286
+ AAB8;TAI VIET VOWEL IA;Mn;230;NSM;;;;;N;;;;;
287
+ AABE;TAI VIET VOWEL AM;Mn;230;NSM;;;;;N;;;;;
288
+ AABF;TAI VIET TONE MAI EK;Mn;230;NSM;;;;;N;;;;;
289
+ AAC1;TAI VIET TONE MAI THO;Mn;230;NSM;;;;;N;;;;;
290
+ FE20;COMBINING LIGATURE LEFT HALF;Mn;230;NSM;;;;;N;;;;;
291
+ FE21;COMBINING LIGATURE RIGHT HALF;Mn;230;NSM;;;;;N;;;;;
292
+ FE22;COMBINING DOUBLE TILDE LEFT HALF;Mn;230;NSM;;;;;N;;;;;
293
+ FE23;COMBINING DOUBLE TILDE RIGHT HALF;Mn;230;NSM;;;;;N;;;;;
294
+ FE24;COMBINING MACRON LEFT HALF;Mn;230;NSM;;;;;N;;;;;
295
+ FE25;COMBINING MACRON RIGHT HALF;Mn;230;NSM;;;;;N;;;;;
296
+ FE26;COMBINING CONJOINING MACRON;Mn;230;NSM;;;;;N;;;;;
297
+ 10A0F;KHAROSHTHI SIGN VISARGA;Mn;230;NSM;;;;;N;;;;;
298
+ 10A38;KHAROSHTHI SIGN BAR ABOVE;Mn;230;NSM;;;;;N;;;;;
299
+ 1D185;MUSICAL SYMBOL COMBINING DOIT;Mn;230;NSM;;;;;N;;;;;
300
+ 1D186;MUSICAL SYMBOL COMBINING RIP;Mn;230;NSM;;;;;N;;;;;
301
+ 1D187;MUSICAL SYMBOL COMBINING FLIP;Mn;230;NSM;;;;;N;;;;;
302
+ 1D188;MUSICAL SYMBOL COMBINING SMEAR;Mn;230;NSM;;;;;N;;;;;
303
+ 1D189;MUSICAL SYMBOL COMBINING BEND;Mn;230;NSM;;;;;N;;;;;
304
+ 1D1AA;MUSICAL SYMBOL COMBINING DOWN BOW;Mn;230;NSM;;;;;N;;;;;
305
+ 1D1AB;MUSICAL SYMBOL COMBINING UP BOW;Mn;230;NSM;;;;;N;;;;;
306
+ 1D1AC;MUSICAL SYMBOL COMBINING HARMONIC;Mn;230;NSM;;;;;N;;;;;
307
+ 1D1AD;MUSICAL SYMBOL COMBINING SNAP PIZZICATO;Mn;230;NSM;;;;;N;;;;;
308
+ 1D242;COMBINING GREEK MUSICAL TRISEME;Mn;230;NSM;;;;;N;;;;;
309
+ 1D243;COMBINING GREEK MUSICAL TETRASEME;Mn;230;NSM;;;;;N;;;;;
310
+ 1D244;COMBINING GREEK MUSICAL PENTASEME;Mn;230;NSM;;;;;N;;;;;
@@ -0,0 +1,91 @@
1
+ Metadata-Version: 2.4
2
+ Name: kittytgp
3
+ Version: 0.0.1
4
+ Summary: Tiny kitty graphics protocol PNG renderer using Unicode placeholders
5
+ Author: Jeremy Howard
6
+ License: Apache-2.0
7
+ Project-URL: Source, https://github.com/answerdotai/kittytgp
8
+ Keywords: kitty,terminal,graphics,tmux,png
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: POSIX
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Topic :: Terminals
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Dynamic: license-file
22
+
23
+ # kittytgp
24
+
25
+ `kittytgp` is a small pure-Python package that renders a PNG with kitty's graphics protocol using Unicode placeholders (`U+10EEEE`).
26
+
27
+ It follows kitty's tmux/editor-friendly placeholder flow:
28
+
29
+ 1. transmit PNG data with kitty graphics protocol
30
+ 2. create a **virtual** placement with `U=1`
31
+ 3. print `U+10EEEE` placeholder text colored with the image ID
32
+
33
+ Because the visible part is ordinary Unicode text, the image moves with the text buffer and works inside hosts such as tmux.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pip install kittytgp
39
+ ```
40
+
41
+ ## CLI
42
+
43
+ ```bash
44
+ kittytgp plot.png
45
+ ```
46
+
47
+ Useful options:
48
+
49
+ ```bash
50
+ kittytgp plot.png --cols 40
51
+ kittytgp plot.png --rows 20
52
+ kittytgp plot.png --cell-size 10x20
53
+ kittytgp plot.png --passthrough tmux
54
+ kittytgp plot.png --image-id 0x123456
55
+ kittytgp plot.png --no-newline
56
+ ```
57
+
58
+ Inside tmux, enable passthrough:
59
+
60
+ ```tmux
61
+ set -g allow-passthrough on
62
+ ```
63
+
64
+ ## Python API
65
+
66
+ ```python
67
+ from kittytgp import render_png
68
+
69
+ render_png("plot.png")
70
+ ```
71
+
72
+ Or build the bytes yourself:
73
+
74
+ ```python
75
+ from kittytgp import build_render_bytes
76
+
77
+ payload = build_render_bytes("plot.png")
78
+ ```
79
+
80
+ ## Design notes
81
+
82
+ This package intentionally stays small:
83
+
84
+ - PNG input only
85
+ - direct transfer (`f=100` PNG payload in APC chunks)
86
+ - Unicode placeholders only
87
+ - 24-bit image IDs encoded in truecolor foreground color
88
+ - tmux passthrough only when needed
89
+
90
+ By default it fits the image into the current terminal while preserving aspect ratio. If the terminal cannot report cell pixel size, pass `--cell-size`, `--cols`, or `--rows`.
91
+
@@ -0,0 +1,18 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ ./kittytgp/__init__.py
6
+ ./kittytgp/__main__.py
7
+ ./kittytgp/core.py
8
+ ./kittytgp/rowcolumn_diacritics.txt
9
+ kittytgp/__init__.py
10
+ kittytgp/__main__.py
11
+ kittytgp/core.py
12
+ kittytgp/rowcolumn_diacritics.txt
13
+ kittytgp.egg-info/PKG-INFO
14
+ kittytgp.egg-info/SOURCES.txt
15
+ kittytgp.egg-info/dependency_links.txt
16
+ kittytgp.egg-info/entry_points.txt
17
+ kittytgp.egg-info/top_level.txt
18
+ tests/test_core.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ kittytgp = kittytgp.__main__:main
@@ -0,0 +1 @@
1
+ kittytgp
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "kittytgp"
7
+ dynamic = ["version"]
8
+ description = "Tiny kitty graphics protocol PNG renderer using Unicode placeholders"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [ {name = "Jeremy Howard"} ]
13
+ keywords = ["kitty", "terminal", "graphics", "tmux", "png"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Environment :: Console",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: POSIX",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
23
+ "Topic :: Terminals",
24
+ ]
25
+
26
+ dependencies = [
27
+ ]
28
+
29
+ [project.urls]
30
+ Source = "https://github.com/answerdotai/kittytgp"
31
+
32
+ [project.scripts]
33
+ kittytgp = "kittytgp.__main__:main"
34
+
35
+ [tool.setuptools]
36
+ package-dir = {"" = "."}
37
+ include-package-data = true
38
+
39
+ [tool.setuptools.dynamic]
40
+ version = { attr = "kittytgp.__version__" }
41
+
42
+ [tool.setuptools.package-data]
43
+ kittytgp = ["rowcolumn_diacritics.txt"]
44
+
45
+ [tool.setuptools.packages.find]
46
+ include = ["kittytgp*"]
47
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from setuptools import setup
2
+
3
+ setup()
@@ -0,0 +1,59 @@
1
+ import base64
2
+
3
+ from kittytgp.core import (
4
+ DIACRITICS,
5
+ PLACEHOLDER,
6
+ _parse_png_size,
7
+ _placeholder_grid,
8
+ _wrap_tmux_passthrough,
9
+ build_render_bytes,
10
+ normalize_image_id,
11
+ )
12
+
13
+ PNG_1X1 = base64.b64decode(
14
+ b"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO2pF6kAAAAASUVORK5CYII="
15
+ )
16
+
17
+
18
+ def test_parse_png_size():
19
+ assert _parse_png_size(PNG_1X1) == (1, 1)
20
+
21
+
22
+ def test_tmux_wrap_doubles_escapes():
23
+ wrapped = _wrap_tmux_passthrough(b"\x1b_Gm=0;abc\x1b\\")
24
+ assert wrapped.startswith(b"\x1bPtmux;")
25
+ assert wrapped.endswith(b"\x1b\\")
26
+ assert b"\x1b\x1b_G" in wrapped
27
+
28
+
29
+ def test_placeholder_grid_uses_row_inheritance_form():
30
+ grid = _placeholder_grid(3, 2, 0x123456)
31
+ assert grid.startswith("\x1b[38;2;18;52;86m")
32
+ assert PLACEHOLDER in grid
33
+ assert DIACRITICS[0] in grid
34
+ assert DIACRITICS[1] in grid
35
+ assert DIACRITICS[2] not in grid
36
+ assert grid.count(PLACEHOLDER) == 6
37
+
38
+
39
+ def test_build_render_bytes_contains_protocol_and_placeholder():
40
+ payload = build_render_bytes(
41
+ PNG_1X1,
42
+ cols=1,
43
+ rows=1,
44
+ image_id=0x123456,
45
+ passthrough="none",
46
+ newline=False,
47
+ )
48
+ assert payload.startswith(b"\x1b_Ga=T,f=100,q=2,U=1,i=1193046,c=1,r=1,m=0;")
49
+ assert PLACEHOLDER.encode("utf-8") in payload
50
+ assert payload.endswith(b"\x1b[39m")
51
+
52
+
53
+ def test_image_id_is_limited_to_24_bits():
54
+ try:
55
+ normalize_image_id(1 << 24)
56
+ except ValueError as exc:
57
+ assert "24 bits" in str(exc)
58
+ else: # pragma: no cover
59
+ raise AssertionError("expected ValueError")