rstui 0.1.0__py3-none-any.whl

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.
rstui/__init__.py ADDED
@@ -0,0 +1,50 @@
1
+ """Dependency-free Python child SDK for the rstui graphical terminal runtime."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import sys
7
+ from dataclasses import dataclass
8
+ from typing import Any, Callable, Literal
9
+
10
+ __all__ = ["Action", "Frame", "run"]
11
+ __version__ = "0.1.0"
12
+
13
+ Action = Literal["continue", "render", "exit"]
14
+
15
+
16
+ @dataclass
17
+ class Frame:
18
+ width: int
19
+ height: int
20
+ rgba: bytes
21
+ placement: dict[str, int] | None = None
22
+
23
+
24
+ def run(
25
+ on_event: Callable[[dict[str, Any], dict[str, Any]], Action | None],
26
+ render: Callable[[dict[str, Any]], Frame],
27
+ ) -> None:
28
+ """Run an rstui child application over stdin/stdout."""
29
+ stdin = sys.stdin.buffer
30
+ stdout = sys.stdout.buffer
31
+ while line := stdin.readline():
32
+ request = json.loads(line)
33
+ if request["type"] == "event":
34
+ action = on_event(request["event"], request["context"]) or "continue"
35
+ stdout.write(json.dumps({"action": action}, separators=(",", ":")).encode() + b"\n")
36
+ elif request["type"] == "render":
37
+ frame = render(request["context"])
38
+ expected = frame.width * frame.height * 4
39
+ if len(frame.rgba) != expected:
40
+ raise ValueError(f"RGBA frame needs {expected} bytes, got {len(frame.rgba)}")
41
+ header: dict[str, Any] = {
42
+ "width": frame.width,
43
+ "height": frame.height,
44
+ "bytes": len(frame.rgba),
45
+ }
46
+ if frame.placement is not None:
47
+ header["placement"] = frame.placement
48
+ stdout.write(json.dumps(header, separators=(",", ":")).encode() + b"\n")
49
+ stdout.write(frame.rgba)
50
+ stdout.flush()
rstui/py.typed ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: rstui
3
+ Version: 0.1.0
4
+ Summary: Python SDK for the rstui graphical terminal runtime
5
+ Project-URL: Homepage, https://github.com/maokangkun/Terminal/tree/main/rstui
6
+ Project-URL: Repository, https://github.com/maokangkun/Terminal
7
+ Project-URL: Issues, https://github.com/maokangkun/Terminal/issues
8
+ Author: maokangkun
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE-APACHE
11
+ Keywords: graphics,rgba,sixel,terminal,tui
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Topic :: Terminals
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+
22
+ # rstui
23
+
24
+ Python child SDK for the `rstui` graphical terminal runtime.
25
+
26
+ ```sh
27
+ python3 -m pip install rstui
28
+ cargo install rstui
29
+ ```
30
+
31
+ ```python
32
+ from rstui import Frame, run
33
+
34
+ def on_event(event, context):
35
+ return "render" if event["type"] == "start" else "continue"
36
+
37
+ def render(context):
38
+ width = context["geometry"]["pixel_width"]
39
+ height = context["geometry"]["pixel_height"]
40
+ return Frame(width, height, bytes(width * height * 4))
41
+
42
+ run(on_event, render)
43
+ ```
44
+
45
+ Run the application with:
46
+
47
+ ```sh
48
+ rstui run -- python3 app.py
49
+ ```
50
+
51
+ stdout is reserved for the framed protocol. Write diagnostics to stderr.
52
+
53
+ Project: https://github.com/maokangkun/Terminal/tree/main/rstui
@@ -0,0 +1,6 @@
1
+ rstui/__init__.py,sha256=pOQyeZS9Rromel6U_OEYyE1JQO86tg75ra8Tou2KbTc,1690
2
+ rstui/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
3
+ rstui-0.1.0.dist-info/METADATA,sha256=h5F6f7jTfaygMpUrb2OAkF1T5QnipkuhsYlgceVzmg0,1501
4
+ rstui-0.1.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
5
+ rstui-0.1.0.dist-info/licenses/LICENSE-APACHE,sha256=VkX3o7v8_wNnaWiTOpaeQBoTG3G4HLwz_hco9cSU0DQ,8913
6
+ rstui-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,158 @@
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, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of fifty percent
20
+ (50%) or more of the outstanding shares, or (iii) beneficial ownership of such
21
+ entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ 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 source, and
28
+ configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation or
31
+ translation of a Source form, including but not limited to compiled object
32
+ code, generated documentation, and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form,
35
+ made available under the License, as indicated by a copyright notice that is
36
+ included in or attached to the work.
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
39
+ is based on or derived from the Work and for which the editorial revisions,
40
+ annotations, elaborations, or other modifications represent, as a whole, an
41
+ original work of authorship. For the purposes of this License, Derivative Works
42
+ shall not include works that remain separable from, or merely link (or bind by
43
+ name) to the interfaces of, the Work and Derivative Works thereof.
44
+
45
+ "Contribution" shall mean any work of authorship, including the original
46
+ version of the Work and any modifications or additions to that Work or
47
+ Derivative Works thereof, that is intentionally submitted to Licensor for
48
+ inclusion in the Work by the copyright owner or by an individual or Legal
49
+ Entity authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal, or
51
+ written communication sent to the Licensor or its representatives, including
52
+ but not limited to communication on electronic mailing lists, source code
53
+ control systems, and issue tracking systems that are managed by, or on behalf
54
+ of, the Licensor for the purpose of discussing and improving the Work, but
55
+ excluding communication that is conspicuously marked or otherwise designated
56
+ in writing by the copyright owner as "Not a Contribution."
57
+
58
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
59
+ of whom a Contribution has been received by Licensor and subsequently
60
+ incorporated within the Work.
61
+
62
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
63
+ License, each Contributor hereby grants to You a perpetual, worldwide,
64
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
65
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
66
+ sublicense, and distribute the Work and such Derivative Works in Source or
67
+ Object form.
68
+
69
+ 3. Grant of Patent License. Subject to the terms and conditions of this
70
+ License, each Contributor hereby grants to You a perpetual, worldwide,
71
+ non-exclusive, no-charge, royalty-free, irrevocable patent license to make,
72
+ have made, use, offer to sell, sell, import, and otherwise transfer the Work,
73
+ where such license applies only to those patent claims licensable by such
74
+ Contributor that are necessarily infringed by their Contribution(s) alone or by
75
+ combination of their Contribution(s) with the Work to which such
76
+ Contribution(s) was submitted. If You institute patent litigation against any
77
+ entity (including a cross-claim or counterclaim in a lawsuit) alleging that the
78
+ Work or a Contribution incorporated within the Work constitutes direct or
79
+ contributory patent infringement, then any patent licenses granted to You
80
+ under this License for that Work shall terminate as of the date such litigation
81
+ is filed.
82
+
83
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
84
+ Derivative Works thereof in any medium, with or without modifications, and in
85
+ Source or Object form, provided that You meet the following conditions:
86
+
87
+ (a) You must give any other recipients of the Work or Derivative Works a copy
88
+ of this License; and
89
+
90
+ (b) You must cause any modified files to carry prominent notices stating that
91
+ You changed the files; and
92
+
93
+ (c) You must retain, in the Source form of any Derivative Works that You
94
+ distribute, all copyright, patent, trademark, and attribution notices from the
95
+ Source form of the Work, excluding those notices that do not pertain to any
96
+ part of the Derivative Works; and
97
+
98
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
99
+ any Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents
106
+ of the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+
112
+ You may add Your own copyright statement to Your modifications and may provide
113
+ additional or different license terms and conditions for use, reproduction, or
114
+ distribution of Your modifications, or for any such Derivative Works as a
115
+ whole, provided Your use, reproduction, and distribution of the Work otherwise
116
+ complies with the conditions stated in this License.
117
+
118
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
119
+ Contribution intentionally submitted for inclusion in the Work by You to the
120
+ Licensor shall be under the terms and conditions of this License, without any
121
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
122
+ supersede or modify the terms of any separate license agreement you may have
123
+ executed with Licensor regarding such Contributions.
124
+
125
+ 6. Trademarks. This License does not grant permission to use the trade names,
126
+ trademarks, service marks, or product names of the Licensor, except as required
127
+ for reasonable and customary use in describing the origin of the Work and
128
+ reproducing the content of the NOTICE file.
129
+
130
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
131
+ writing, Licensor provides the Work (and each Contributor provides its
132
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
133
+ KIND, either express or implied, including, without limitation, any warranties
134
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
135
+ PARTICULAR PURPOSE. You are solely responsible for determining the
136
+ appropriateness of using or redistributing the Work and assume any risks
137
+ associated with Your exercise of permissions under this License.
138
+
139
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
140
+ tort (including negligence), contract, or otherwise, unless required by
141
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
142
+ writing, shall any Contributor be liable to You for damages, including any
143
+ direct, indirect, special, incidental, or consequential damages of any
144
+ character arising as a result of this License or out of the use or inability to
145
+ use the Work, even if such Contributor has been advised of the possibility of
146
+ such damages.
147
+
148
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
149
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
150
+ acceptance of support, warranty, indemnity, or other liability obligations
151
+ and/or rights consistent with this License. However, in accepting such
152
+ obligations, You may act only on Your own behalf and on Your sole
153
+ responsibility, not on behalf of any other Contributor, and only if You agree
154
+ to indemnify, defend, and hold each Contributor harmless for any liability
155
+ incurred by, or claims asserted against, such Contributor by reason of your
156
+ accepting any such warranty or additional liability.
157
+
158
+ END OF TERMS AND CONDITIONS