teleprint 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- teleprint-0.1.0/CHANGELOG.md +8 -0
- teleprint-0.1.0/LICENSE +202 -0
- teleprint-0.1.0/MANIFEST.in +3 -0
- teleprint-0.1.0/PKG-INFO +94 -0
- teleprint-0.1.0/README.md +73 -0
- teleprint-0.1.0/pyproject.toml +36 -0
- teleprint-0.1.0/setup.cfg +4 -0
- teleprint-0.1.0/teleprint/__init__.py +7 -0
- teleprint-0.1.0/teleprint/blocks.py +34 -0
- teleprint-0.1.0/teleprint/buffer.py +78 -0
- teleprint-0.1.0/teleprint/compositor.py +410 -0
- teleprint-0.1.0/teleprint/jobs.py +129 -0
- teleprint-0.1.0/teleprint/keys.py +160 -0
- teleprint-0.1.0/teleprint/testing.py +47 -0
- teleprint-0.1.0/teleprint/transcript.py +262 -0
- teleprint-0.1.0/teleprint/tty.py +54 -0
- teleprint-0.1.0/teleprint/widgets.py +71 -0
- teleprint-0.1.0/teleprint.egg-info/PKG-INFO +94 -0
- teleprint-0.1.0/teleprint.egg-info/SOURCES.txt +27 -0
- teleprint-0.1.0/teleprint.egg-info/dependency_links.txt +1 -0
- teleprint-0.1.0/teleprint.egg-info/requires.txt +8 -0
- teleprint-0.1.0/teleprint.egg-info/top_level.txt +1 -0
- teleprint-0.1.0/tests/test_buffer.py +64 -0
- teleprint-0.1.0/tests/test_compositor.py +548 -0
- teleprint-0.1.0/tests/test_jobs.py +88 -0
- teleprint-0.1.0/tests/test_keys.py +84 -0
- teleprint-0.1.0/tests/test_testing.py +20 -0
- teleprint-0.1.0/tests/test_transcript.py +132 -0
- teleprint-0.1.0/tests/test_widgets.py +41 -0
teleprint-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
teleprint-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: teleprint
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Transcript-first terminal UI: the scrollback is the document
|
|
5
|
+
Author: teleprint contributors
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/AnswerDotAI/teleprint
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: rich
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: fastship; extra == "dev"
|
|
16
|
+
Requires-Dist: build; extra == "dev"
|
|
17
|
+
Requires-Dist: twine; extra == "dev"
|
|
18
|
+
Requires-Dist: pytest; extra == "dev"
|
|
19
|
+
Requires-Dist: pyghostty; extra == "dev"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# teleprint
|
|
23
|
+
|
|
24
|
+
A terminal UI library for apps built around a transcript: blocks print through to the terminal's own scrollback, a status bar and line editor repaint at the bottom, and everything in between stays clickable until it scrolls away. Written for AI CLIs and REPLs; `ipyai` is the reference app.
|
|
25
|
+
|
|
26
|
+
The pieces:
|
|
27
|
+
|
|
28
|
+
- a compositor that prints Rich-renderable blocks and repaints the visible ones in place (collapse/expand on click)
|
|
29
|
+
- a line editor and a key/mouse/paste input parser
|
|
30
|
+
- transcript mode on the alt screen: browse, search, and copy the block history (copy via OSC 52)
|
|
31
|
+
- a jobs layer: foreground commands borrow the real tty; background jobs run against a headless mirror
|
|
32
|
+
- widgets (status bar, signature panel) and a pyghostty-backed terminal emulator, so the whole surface is testable headlessly
|
|
33
|
+
|
|
34
|
+
The design sections below are the founding notes, moved here verbatim; DEV.md keeps the development record.
|
|
35
|
+
|
|
36
|
+
## Thesis
|
|
37
|
+
|
|
38
|
+
Terminal UI libraries pick a center. Textual's center is the screen: a widget tree composited onto a canvas the app owns. prompt_toolkit's center is the prompt: a line editor that borrows the tty and gives it back. Our needs (ipyai: chat transcript, tool calls, status bar, input line) orbit neither — they orbit the transcript: an append-mostly document of blocks with a small mutable edge. Neither library models that, because each refuses half of it: Textual won't cede the screen to scrollback, pt won't model anything above the prompt. teleprint's center is the transcript, and the terminal's own scrollback is its durable rendering. The name records the model: a teleprinter prints every message onto durable paper as it arrives, printhead always at the live edge.
|
|
39
|
+
|
|
40
|
+
The invariant everything else derives from:
|
|
41
|
+
|
|
42
|
+
> There is one history — the printed transcript — and anything that scrolls is a view of it. Never a parallel world.
|
|
43
|
+
|
|
44
|
+
Contract form: the block model is the source of truth; the pane is its durable rendering; the pager is its live rendering; every gesture scrolls one of those two renderings and nothing else. This is the acceptance test for features: app-private scroll buffers, mutable history, and interaction paths that exist only in one rendering all fail it.
|
|
45
|
+
|
|
46
|
+
Prior art that validates the block concept without occupying this slot: Warp (blocks, but by being the terminal emulator), Ink's Static/dynamic split (same committed/live division, no interactivity in the committed region, React-centered), Textual's inline mode (the repaint mechanics, but everything stays inside the app region and clears on exit). The strongest demand evidence: Claude Code (Ink/React) and codex (ratatui/Rust) independently converged on this exact surface grammar — print-through transcript, gutter-marked block types, repainted input-plus-status tail — and Claude Code ships the zone model precisely: its visible blocks are clickable (tool calls toggle open), going inert once scrolled. Every AI CLI is currently hand-rolling a private version of this core.
|
|
47
|
+
|
|
48
|
+
## Surfaces
|
|
49
|
+
|
|
50
|
+
Three surfaces, one rule each:
|
|
51
|
+
|
|
52
|
+
- **Durable** (main screen): printed blocks, append-only. Owned by the terminal/tmux once printed: native scroll, search, copy-mode, detach survival.
|
|
53
|
+
- **Live tail** (bottom rows): status bar + input editor, diff-repainted in place every frame.
|
|
54
|
+
- **Ephemeral** (alt screen): pager, pickers, modals. Leave no residue; only an *outcome block* enters the transcript (the decision, printed — like shell history recording the command, not the completion menu). fzf is the exemplar: transient full-screen moments don't make a tool a TUI; identity is where the app rests.
|
|
55
|
+
|
|
56
|
+
Within the main screen, two zones by mutability: **inked** (scrolled off-screen into the terminal's buffer; written once, immutable) and **visible** (redrawn from the block model on any change, so everything on screen is clickable -- folding a block simply repaints the screen from the model, however long ago it printed). The tail is part of the visible region and never enters history. Interactivity map: everything visible interactive; inked history native and inert (the transcript view for live access); alt-screen surfaces interactive while up.
|
|
57
|
+
|
|
58
|
+
## Why not prompt_toolkit or Textual
|
|
59
|
+
|
|
60
|
+
Beyond the centering argument:
|
|
61
|
+
|
|
62
|
+
- **stdin has one owner.** CPR replies, keys, mouse, paste interleave unattributed on one fd. Our compositor needs CPR; pt's renderer also issues CPR and assumes it owns the read loop; the jobs relay and modals need the fd too. Embedding pt means demultiplexing stdin into someone else's framework assumptions (its `get_app()` application singleton, Application-owned loop) forever.
|
|
63
|
+
- **One rendering dialect.** Rich renders every block everywhere. pt's formatted-text model would be a second dialect; two renderers for one document drift (the pandoc lesson: one center dialect).
|
|
64
|
+
- The borrow contract — who owns stdin/stdout right now (tail at rest, job, modal, pager) — is the design's real center and exists in pt only implicitly (`in_terminal` chaining). Fresh code makes it a first-class object.
|
|
65
|
+
|
|
66
|
+
What we crib rather than reinvent: pt's vt100 parser tables and quirk comments, CPR-timeout discipline, raw/cooked mode management, the shape of Buffer (text+cursor+undo as pure data); Textual's XTermParser (compact modern input parser) and inline-mode mechanics (cursor-up repaint, `ESC[6n` origin tracking, `ESC[J`, render to stderr); clikernel base.py's termios lore (ONLCR off for bare LF, ICANON off because canonical mode drops bytes past MAX_CANON with BEL spam; IEXTEN off because on BSD/macOS ^O is VDISCARD and the driver eats it — found when the demo's ctrl-O binding went dead). pt's external-command philosophy (`run_system_command`: yield the real tty, don't virtualize) confirms the jobs layer sits below any UI library.
|
|
67
|
+
|
|
68
|
+
The pt lore harvest in detail (from `input/vt100.py` raw_mode, `application.py`, `renderer.py`, `output/flush_stdout.py` — read 2026-07-23, worth keeping even if pt itself isn't used):
|
|
69
|
+
|
|
70
|
+
- **Raw mode is a delta, not `setraw`.** pt patches only what it means to change ("On OS X, `pty.setraw()` fails" — their comment): lflag clears ECHO | ICANON | IEXTEN | **ISIG** (ctrl-C/Z arrive as bytes; the app owns interrupt semantics), iflag clears **IXON | IXOFF** (or ctrl-S silently freezes output — the classic "my terminal is stuck") and **ICRNL | INLCR | IGNCR** (Enter arrives as `\r`, distinguishable from ctrl-J). It never touches oflag, unlike clikernel's ONLCR handling. Set **VMIN=1 explicitly**: on Solaris-family systems the VMIN slot aliases VEOF and defaults to 4, so reads mysteriously buffer.
|
|
71
|
+
- **All tcgetattr/tcsetattr wrapped in try/except**: stdin may be /dev/null, an SSH pipe with no allocated tty, or closed mid-session ("Inappropriate ioctl for device").
|
|
72
|
+
- **Cooked mode for borrows must restore ICRNL specifically** — without it, `input()` inside a borrowed terminal shows `^M` instead of accepting Enter.
|
|
73
|
+
- **SIGWINCH belongs to the event loop** (`loop.add_signal_handler`, not `signal.signal`) and must be saved/restored around borrows, since the borrowed program may install its own. Backstop: **poll the size every 0.5s anyway** — SIGWINCH can't be delivered off the main thread or on Windows, and a resize during suspension is missed entirely.
|
|
74
|
+
- **Suspend (ctrl-Z) is a borrow too**: pt's `suspend_to_background` runs *through* `run_in_terminal` — restore cooked mode, `os.kill(0, SIGTSTP)` (the whole process *group*, for piped-input cases), and raw mode re-establishes on SIGCONT return.
|
|
75
|
+
- **SIGINT needs restoring at two levels**: the Python handler *and* the C-level one via `PyOS_getsig`/`PyOS_setsig` (stable ABI) — some embedders change the OS handler under Python.
|
|
76
|
+
- **Writes need armor**: EINTR from a resize mid-write is ignorable (the resize repaint re-renders); make stdout blocking around writes (uvloop makes it non-blocking → `BlockingIOError` on big flushes); encode with `errors='replace'` (ascii locales exist).
|
|
77
|
+
- **CPR discipline**: assume supported only after the first reply; probe with a 2s timer and mark NOT_SUPPORTED on silence (with a callback so the UI can adapt); track outstanding requests in a queue so replies pair with requests; skip CPR entirely for dumb terminals, non-tty stdout, or `$PROMPT_TOOLKIT_NO_CPR=1` (their pexpect escape hatch — we'll want the same for harness-driven runs); "it's nicer to draw bottom toolbars only once the height is known, to avoid flicker when the CPR response arrives."
|
|
78
|
+
|
|
79
|
+
Line editing is the honest cost of going fresh: readline-emacs subset first (arrows, ctrl-a/e/k/u/w/y, alt-b/f, ctrl-r) — what ~99% of fingers use; vi mode later at most, as a mechanical crib of pt's binding tables. `!vim` through the jobs layer covers real editing.
|
|
80
|
+
|
|
81
|
+
Multiline input scheme (decided 2026-07-23, replacing an earlier assumption that pt's checker behavior needed inventing): **Enter is smart, alt-enter is a newline, ctrl-O stays toggle.** Enter routes through IPython's `check_complete` (a `check` op on the stream protocol, answered worker-side -- which keeps IPython out of the UI process entirely, one step beyond today's ipyai, which needs a client-side TransformerManager because its kernel is remote): complete submits, incomplete inserts a continuation newline, invalid submits so execution shows the error. ipythonng's `check_complete` patch (single-line magic/alias commands count complete) rides into the worker shell. Alt-enter *always* inserts a newline, in both code and prompt mode -- the codex/Claude Code convention, and the first real typing path for multiline prompts (previously bracketed paste or F2-editor only; both remain). What stock IPython loses: meta-enter force-execute (double-Enter covers it) and ctrl-o insert-newline -- measured to be unknown even to a decades-long IPython user, so teleprint's toggle keeps the key. Findings for the record: ipyai has NO custom Enter handling today (it inherits jupyter_console's checker-driven behavior wholesale), and its multiline customization lives one layer over, in the transformer pipeline (`transform_prompt_mode`/`transform_dots`), which is routing, not completeness.
|
|
82
|
+
|
|
83
|
+
## Install
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install teleprint
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Development
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pip install -e .[dev]
|
|
93
|
+
pytest
|
|
94
|
+
```
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# teleprint
|
|
2
|
+
|
|
3
|
+
A terminal UI library for apps built around a transcript: blocks print through to the terminal's own scrollback, a status bar and line editor repaint at the bottom, and everything in between stays clickable until it scrolls away. Written for AI CLIs and REPLs; `ipyai` is the reference app.
|
|
4
|
+
|
|
5
|
+
The pieces:
|
|
6
|
+
|
|
7
|
+
- a compositor that prints Rich-renderable blocks and repaints the visible ones in place (collapse/expand on click)
|
|
8
|
+
- a line editor and a key/mouse/paste input parser
|
|
9
|
+
- transcript mode on the alt screen: browse, search, and copy the block history (copy via OSC 52)
|
|
10
|
+
- a jobs layer: foreground commands borrow the real tty; background jobs run against a headless mirror
|
|
11
|
+
- widgets (status bar, signature panel) and a pyghostty-backed terminal emulator, so the whole surface is testable headlessly
|
|
12
|
+
|
|
13
|
+
The design sections below are the founding notes, moved here verbatim; DEV.md keeps the development record.
|
|
14
|
+
|
|
15
|
+
## Thesis
|
|
16
|
+
|
|
17
|
+
Terminal UI libraries pick a center. Textual's center is the screen: a widget tree composited onto a canvas the app owns. prompt_toolkit's center is the prompt: a line editor that borrows the tty and gives it back. Our needs (ipyai: chat transcript, tool calls, status bar, input line) orbit neither — they orbit the transcript: an append-mostly document of blocks with a small mutable edge. Neither library models that, because each refuses half of it: Textual won't cede the screen to scrollback, pt won't model anything above the prompt. teleprint's center is the transcript, and the terminal's own scrollback is its durable rendering. The name records the model: a teleprinter prints every message onto durable paper as it arrives, printhead always at the live edge.
|
|
18
|
+
|
|
19
|
+
The invariant everything else derives from:
|
|
20
|
+
|
|
21
|
+
> There is one history — the printed transcript — and anything that scrolls is a view of it. Never a parallel world.
|
|
22
|
+
|
|
23
|
+
Contract form: the block model is the source of truth; the pane is its durable rendering; the pager is its live rendering; every gesture scrolls one of those two renderings and nothing else. This is the acceptance test for features: app-private scroll buffers, mutable history, and interaction paths that exist only in one rendering all fail it.
|
|
24
|
+
|
|
25
|
+
Prior art that validates the block concept without occupying this slot: Warp (blocks, but by being the terminal emulator), Ink's Static/dynamic split (same committed/live division, no interactivity in the committed region, React-centered), Textual's inline mode (the repaint mechanics, but everything stays inside the app region and clears on exit). The strongest demand evidence: Claude Code (Ink/React) and codex (ratatui/Rust) independently converged on this exact surface grammar — print-through transcript, gutter-marked block types, repainted input-plus-status tail — and Claude Code ships the zone model precisely: its visible blocks are clickable (tool calls toggle open), going inert once scrolled. Every AI CLI is currently hand-rolling a private version of this core.
|
|
26
|
+
|
|
27
|
+
## Surfaces
|
|
28
|
+
|
|
29
|
+
Three surfaces, one rule each:
|
|
30
|
+
|
|
31
|
+
- **Durable** (main screen): printed blocks, append-only. Owned by the terminal/tmux once printed: native scroll, search, copy-mode, detach survival.
|
|
32
|
+
- **Live tail** (bottom rows): status bar + input editor, diff-repainted in place every frame.
|
|
33
|
+
- **Ephemeral** (alt screen): pager, pickers, modals. Leave no residue; only an *outcome block* enters the transcript (the decision, printed — like shell history recording the command, not the completion menu). fzf is the exemplar: transient full-screen moments don't make a tool a TUI; identity is where the app rests.
|
|
34
|
+
|
|
35
|
+
Within the main screen, two zones by mutability: **inked** (scrolled off-screen into the terminal's buffer; written once, immutable) and **visible** (redrawn from the block model on any change, so everything on screen is clickable -- folding a block simply repaints the screen from the model, however long ago it printed). The tail is part of the visible region and never enters history. Interactivity map: everything visible interactive; inked history native and inert (the transcript view for live access); alt-screen surfaces interactive while up.
|
|
36
|
+
|
|
37
|
+
## Why not prompt_toolkit or Textual
|
|
38
|
+
|
|
39
|
+
Beyond the centering argument:
|
|
40
|
+
|
|
41
|
+
- **stdin has one owner.** CPR replies, keys, mouse, paste interleave unattributed on one fd. Our compositor needs CPR; pt's renderer also issues CPR and assumes it owns the read loop; the jobs relay and modals need the fd too. Embedding pt means demultiplexing stdin into someone else's framework assumptions (its `get_app()` application singleton, Application-owned loop) forever.
|
|
42
|
+
- **One rendering dialect.** Rich renders every block everywhere. pt's formatted-text model would be a second dialect; two renderers for one document drift (the pandoc lesson: one center dialect).
|
|
43
|
+
- The borrow contract — who owns stdin/stdout right now (tail at rest, job, modal, pager) — is the design's real center and exists in pt only implicitly (`in_terminal` chaining). Fresh code makes it a first-class object.
|
|
44
|
+
|
|
45
|
+
What we crib rather than reinvent: pt's vt100 parser tables and quirk comments, CPR-timeout discipline, raw/cooked mode management, the shape of Buffer (text+cursor+undo as pure data); Textual's XTermParser (compact modern input parser) and inline-mode mechanics (cursor-up repaint, `ESC[6n` origin tracking, `ESC[J`, render to stderr); clikernel base.py's termios lore (ONLCR off for bare LF, ICANON off because canonical mode drops bytes past MAX_CANON with BEL spam; IEXTEN off because on BSD/macOS ^O is VDISCARD and the driver eats it — found when the demo's ctrl-O binding went dead). pt's external-command philosophy (`run_system_command`: yield the real tty, don't virtualize) confirms the jobs layer sits below any UI library.
|
|
46
|
+
|
|
47
|
+
The pt lore harvest in detail (from `input/vt100.py` raw_mode, `application.py`, `renderer.py`, `output/flush_stdout.py` — read 2026-07-23, worth keeping even if pt itself isn't used):
|
|
48
|
+
|
|
49
|
+
- **Raw mode is a delta, not `setraw`.** pt patches only what it means to change ("On OS X, `pty.setraw()` fails" — their comment): lflag clears ECHO | ICANON | IEXTEN | **ISIG** (ctrl-C/Z arrive as bytes; the app owns interrupt semantics), iflag clears **IXON | IXOFF** (or ctrl-S silently freezes output — the classic "my terminal is stuck") and **ICRNL | INLCR | IGNCR** (Enter arrives as `\r`, distinguishable from ctrl-J). It never touches oflag, unlike clikernel's ONLCR handling. Set **VMIN=1 explicitly**: on Solaris-family systems the VMIN slot aliases VEOF and defaults to 4, so reads mysteriously buffer.
|
|
50
|
+
- **All tcgetattr/tcsetattr wrapped in try/except**: stdin may be /dev/null, an SSH pipe with no allocated tty, or closed mid-session ("Inappropriate ioctl for device").
|
|
51
|
+
- **Cooked mode for borrows must restore ICRNL specifically** — without it, `input()` inside a borrowed terminal shows `^M` instead of accepting Enter.
|
|
52
|
+
- **SIGWINCH belongs to the event loop** (`loop.add_signal_handler`, not `signal.signal`) and must be saved/restored around borrows, since the borrowed program may install its own. Backstop: **poll the size every 0.5s anyway** — SIGWINCH can't be delivered off the main thread or on Windows, and a resize during suspension is missed entirely.
|
|
53
|
+
- **Suspend (ctrl-Z) is a borrow too**: pt's `suspend_to_background` runs *through* `run_in_terminal` — restore cooked mode, `os.kill(0, SIGTSTP)` (the whole process *group*, for piped-input cases), and raw mode re-establishes on SIGCONT return.
|
|
54
|
+
- **SIGINT needs restoring at two levels**: the Python handler *and* the C-level one via `PyOS_getsig`/`PyOS_setsig` (stable ABI) — some embedders change the OS handler under Python.
|
|
55
|
+
- **Writes need armor**: EINTR from a resize mid-write is ignorable (the resize repaint re-renders); make stdout blocking around writes (uvloop makes it non-blocking → `BlockingIOError` on big flushes); encode with `errors='replace'` (ascii locales exist).
|
|
56
|
+
- **CPR discipline**: assume supported only after the first reply; probe with a 2s timer and mark NOT_SUPPORTED on silence (with a callback so the UI can adapt); track outstanding requests in a queue so replies pair with requests; skip CPR entirely for dumb terminals, non-tty stdout, or `$PROMPT_TOOLKIT_NO_CPR=1` (their pexpect escape hatch — we'll want the same for harness-driven runs); "it's nicer to draw bottom toolbars only once the height is known, to avoid flicker when the CPR response arrives."
|
|
57
|
+
|
|
58
|
+
Line editing is the honest cost of going fresh: readline-emacs subset first (arrows, ctrl-a/e/k/u/w/y, alt-b/f, ctrl-r) — what ~99% of fingers use; vi mode later at most, as a mechanical crib of pt's binding tables. `!vim` through the jobs layer covers real editing.
|
|
59
|
+
|
|
60
|
+
Multiline input scheme (decided 2026-07-23, replacing an earlier assumption that pt's checker behavior needed inventing): **Enter is smart, alt-enter is a newline, ctrl-O stays toggle.** Enter routes through IPython's `check_complete` (a `check` op on the stream protocol, answered worker-side -- which keeps IPython out of the UI process entirely, one step beyond today's ipyai, which needs a client-side TransformerManager because its kernel is remote): complete submits, incomplete inserts a continuation newline, invalid submits so execution shows the error. ipythonng's `check_complete` patch (single-line magic/alias commands count complete) rides into the worker shell. Alt-enter *always* inserts a newline, in both code and prompt mode -- the codex/Claude Code convention, and the first real typing path for multiline prompts (previously bracketed paste or F2-editor only; both remain). What stock IPython loses: meta-enter force-execute (double-Enter covers it) and ctrl-o insert-newline -- measured to be unknown even to a decades-long IPython user, so teleprint's toggle keeps the key. Findings for the record: ipyai has NO custom Enter handling today (it inherits jupyter_console's checker-driven behavior wholesale), and its multiline customization lives one layer over, in the transformer pipeline (`transform_prompt_mode`/`transform_dots`), which is routing, not completeness.
|
|
61
|
+
|
|
62
|
+
## Install
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install teleprint
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install -e .[dev]
|
|
72
|
+
pytest
|
|
73
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "teleprint"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Transcript-first terminal UI: the scrollback is the document"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "Apache-2.0" }
|
|
12
|
+
authors = [{ name = "teleprint contributors" }]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
dependencies = ["rich"]
|
|
19
|
+
|
|
20
|
+
[project.optional-dependencies]
|
|
21
|
+
dev = [
|
|
22
|
+
"fastship",
|
|
23
|
+
"build",
|
|
24
|
+
"twine",
|
|
25
|
+
"pytest",
|
|
26
|
+
"pyghostty",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/AnswerDotAI/teleprint"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.dynamic]
|
|
33
|
+
version = { attr = "teleprint.__version__" }
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.packages.find]
|
|
36
|
+
include = ["teleprint"]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"Minimal block model: identity, Rich-renderable forms, click targets. No app nouns live here."
|
|
2
|
+
from rich.text import Text
|
|
3
|
+
|
|
4
|
+
class Block:
|
|
5
|
+
"""One transcript block, presented content-first: no header line and no printed identity.
|
|
6
|
+
|
|
7
|
+
The first content line IS the chrome: `gutter` styles the left edge (a first-line
|
|
8
|
+
prefix and a continuation prefix) and carries the toggle click target. Collapsed
|
|
9
|
+
presentation is the first line plus a dim `… (+N lines)` tail. Everything visible
|
|
10
|
+
is clickable (write-once: the screen redraws from the model), so no bright-vs-dim
|
|
11
|
+
affordance state exists.
|
|
12
|
+
|
|
13
|
+
`body` is a list of Rich renderables (streams append parts). `tag` is a free-form
|
|
14
|
+
app label (never rendered). `collapse_at` auto-collapses the block when its
|
|
15
|
+
rendered height crosses the threshold (None: never). `source` is the model-level
|
|
16
|
+
text behind the rendering (a cell's code, a reply's markdown): what search matches
|
|
17
|
+
and copy yields; None falls back to plain-text extraction from the rendering."""
|
|
18
|
+
def __init__(self, bid, body=None, gutter=None, tag=None, collapse_at=None, source=None):
|
|
19
|
+
self.id, self.tag, self.collapse_at, self.source = bid, tag, collapse_at, source
|
|
20
|
+
self.body = [] if body is None else [body]
|
|
21
|
+
self.gutter = gutter or (Text(''), Text(''))
|
|
22
|
+
self.collapsed = False
|
|
23
|
+
self.dim = False # presentational mute (e.g. hidden-from-AI): both surfaces render the block dim
|
|
24
|
+
self.committed = False # outside the screen document (a borrow ended its epoch, or record_block): model-only now
|
|
25
|
+
self.height = 0
|
|
26
|
+
self._first = None # cached first-line content segments, for cheap collapsed summaries
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def dim(self): return self._dim
|
|
30
|
+
@dim.setter
|
|
31
|
+
def dim(self, v):
|
|
32
|
+
"Setting dim invalidates the block's cached presentation rows, so the next frame renders the new state."
|
|
33
|
+
self._dim = v
|
|
34
|
+
self._rows = None
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"The line editor: text and cursor as pure data, with the readline-emacs subset."
|
|
2
|
+
from rich.cells import cell_len
|
|
3
|
+
|
|
4
|
+
class Buffer:
|
|
5
|
+
"An editable line: `handle` consumes editing keys, returning True when it did."
|
|
6
|
+
def __init__(self, text=''):
|
|
7
|
+
self.text, self.cursor, self.cut = text, len(text), ''
|
|
8
|
+
self.suggestion = '' # ghost-text tail: shown dim after the cursor, accepted by right/ctrl+e at end
|
|
9
|
+
|
|
10
|
+
def insert(self, s):
|
|
11
|
+
self.text = self.text[:self.cursor] + s + self.text[self.cursor:]
|
|
12
|
+
self.cursor += len(s)
|
|
13
|
+
|
|
14
|
+
def clear(self):
|
|
15
|
+
self.text, self.cursor = '', 0
|
|
16
|
+
|
|
17
|
+
def _back_word(self):
|
|
18
|
+
i = self.cursor
|
|
19
|
+
while i and not self.text[i-1].isalnum(): i -= 1
|
|
20
|
+
while i and self.text[i-1].isalnum(): i -= 1
|
|
21
|
+
return i
|
|
22
|
+
|
|
23
|
+
def _fwd_word(self):
|
|
24
|
+
i, n = self.cursor, len(self.text)
|
|
25
|
+
while i < n and not self.text[i].isalnum(): i += 1
|
|
26
|
+
while i < n and self.text[i].isalnum(): i += 1
|
|
27
|
+
return i
|
|
28
|
+
|
|
29
|
+
def _cut(self, start, end):
|
|
30
|
+
self.cut = self.text[start:end]
|
|
31
|
+
self.text = self.text[:start] + self.text[end:]
|
|
32
|
+
self.cursor = start
|
|
33
|
+
|
|
34
|
+
def handle(self, key):
|
|
35
|
+
"Apply `key` (a `keys.Key`), returning True when it edited or moved."
|
|
36
|
+
k, n = key.name, len(self.text)
|
|
37
|
+
if key.char is not None: self.insert(key.char); return True
|
|
38
|
+
if k in ('right', 'ctrl+f', 'ctrl+e', 'end') and self.cursor == n and self.suggestion:
|
|
39
|
+
self.insert(self.suggestion)
|
|
40
|
+
self.suggestion = ''
|
|
41
|
+
return True
|
|
42
|
+
if k == 'up':
|
|
43
|
+
b = self.text.rfind('\n', 0, self.cursor)
|
|
44
|
+
if b < 0: return False # top line: the host may treat this as history-back
|
|
45
|
+
col = self.cursor - (b + 1)
|
|
46
|
+
prev_start = self.text.rfind('\n', 0, b) + 1
|
|
47
|
+
self.cursor = min(prev_start + col, b)
|
|
48
|
+
return True
|
|
49
|
+
if k == 'down':
|
|
50
|
+
e = self.text.find('\n', self.cursor)
|
|
51
|
+
if e < 0: return False # last line: the host may treat this as history-forward
|
|
52
|
+
col = self.cursor - (self.text.rfind('\n', 0, self.cursor) + 1)
|
|
53
|
+
nxt_end = self.text.find('\n', e + 1)
|
|
54
|
+
if nxt_end < 0: nxt_end = len(self.text)
|
|
55
|
+
self.cursor = min(e + 1 + col, nxt_end)
|
|
56
|
+
return True
|
|
57
|
+
if k in ('left','ctrl+b'): self.cursor = max(self.cursor-1, 0)
|
|
58
|
+
elif k in ('right','ctrl+f'): self.cursor = min(self.cursor+1, n)
|
|
59
|
+
elif k in ('home','ctrl+a'): self.cursor = 0
|
|
60
|
+
elif k in ('end','ctrl+e'): self.cursor = n
|
|
61
|
+
elif k == 'alt+b': self.cursor = self._back_word()
|
|
62
|
+
elif k == 'alt+f': self.cursor = self._fwd_word()
|
|
63
|
+
elif k == 'backspace':
|
|
64
|
+
if self.cursor:
|
|
65
|
+
self.text = self.text[:self.cursor-1] + self.text[self.cursor:]
|
|
66
|
+
self.cursor -= 1
|
|
67
|
+
elif k in ('delete','ctrl+d'):
|
|
68
|
+
if self.cursor < n: self.text = self.text[:self.cursor] + self.text[self.cursor+1:]
|
|
69
|
+
elif k == 'ctrl+k': self._cut(self.cursor, n)
|
|
70
|
+
elif k == 'ctrl+u': self._cut(0, self.cursor)
|
|
71
|
+
elif k in ('ctrl+w','alt+backspace'): self._cut(self._back_word(), self.cursor)
|
|
72
|
+
elif k == 'ctrl+y': self.insert(self.cut)
|
|
73
|
+
else: return False
|
|
74
|
+
return True
|
|
75
|
+
|
|
76
|
+
def cell_cursor(self, prefix=''):
|
|
77
|
+
"Cell column of the cursor when the text renders after `prefix` (wide chars counted honestly)."
|
|
78
|
+
return cell_len(prefix + self.text[:self.cursor])
|