Repository navigation
feat: graphics substrate (registry, tier engine, cell integration) - #141
Draft
natemoo-re wants to merge 3 commits into
Draft
natemoo-re wants to merge 3 commits into
natemoo-re wants to merge 3 commits into
Conversation
Contributor
No changeset neededThis pull request is classified as no_release_impact: @bomb.sh/tty |
|
Size Increased — +12.5 KB 156.2 KB unpacked |
commit: |
natemoo-re
force-pushed
the
feat/graphics-substrate
branch
from
October 9, 2026 20:17
8813820 to
30aa8fa
Compare
natemoo-re
force-pushed
the
feat/graphics-substrate
branch
from
December 4, 2026 03:06
d7ab323 to
3d0eef2
Compare
The pixel-surface registry, tier engine (kitty, shape-aware ascii, alt), placements record, and cell-buffer integration of the Graphics Specification, ported onto the retained frame pair. - Graphics state lives in its own dimension-independent carve at the heap base; clayterm_init takes it, resize leaves it in place. - OP_IMG decodes in execute_current_runlist like any element: it is recorded for ElementInfo, so its replay range covers the packed op and re-resolves registry liveness and tier each render. - The declared bg accepts symbolic color words and resolves against the inherited color; alt text inherits the foreground like text(). - Image error text is composed into per-frame storage alongside the frame's errors, so it stays readable while that frame is previous. - Graphics bytes are emitted inside present_cups' synchronized-update wrap: queued and stale deletions plus transmissions before the cell diff, placements after it and before the caret step. - Cleanup never produces bytes outside render(). Removal, kitty-graphics denial, and resize enqueue wire ids in the pending-deletion queue; the next cursor-mode render drains it first. Overflow collapses to one delete-all with transmission resets and deletion damage. - The coverage pass runs after the color-tier check, so a tier change's complete redraw re-places live placements without re-transmitting. - input.c ignores APC frames carrying an a= action key, so relayed quiet commands never surface as kitty-graphics capability events.
The output buffer only carried the per-cell text budget, and buf_put drops writes that do not fit, so a large transmission reached the terminal as a truncated APC stream: a 200x200 image on a 40x12 Term emitted 59 KB of a ~213 KB encoding with no error. - The output capacity adds graphics_output_bytes(pool) per Graphics Specification §5.6, fixed at init from the pool size and kept across resize. clayterm_size takes the pool size so the host carves for it. - Buffer records an overflow flag that the next render clears. reduce() reports CLAYTERM_REDUCE_OUTPUT instead of returning partial bytes, and the host throws a RangeError. The sizing makes this unreachable; graphics retained state is not rolled back on that path.
natemoo-re
force-pushed
the
feat/graphics-substrate
branch
from
December 4, 2026 03:09
3d0eef2 to
beb3bca
Compare
Two bugs that left the img demo's panels black (both first found on spike/img-demo, c6ab8ee and a42e2df, and never carried over): - Continuation chunks began their keys with a comma (_G,m=1,q=2;...). Strict parsers such as ghostty's reject the empty key and drop the whole transmission; q=2 hides the failure, so every placement then points at an image the terminal never stored. Continuations now emit only m and q, per §9.2.2. - Clay emits an element's background rect after its custom command, so a declared bg painted over the ascii art drawn in the custom handler. Pixel-tier img elements now mark their rect to be skipped, and the handler paints the background itself before the art or placement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the Graphics Specification engine in C (stacked on the spec PR; the public TypeScript surface + test suite land in the img PR after this).
What lands here
Memory (§5). The engine gains a second, dimension-independent carve beside the per-dimension clayterm carve:
[gfx: entry table (256) | pixel pool (4 MiB default) | placements tables (64×2 double-buffered)]. Because the region never moves or re-initializes, the registry survives resize untouched (§10.5) — and this is exactly the property §4.5 calls out for the future zero-copy canvas surface views.setImage/removeImageMUST NOT grow linear memory (INV-I8); capacity failures are closedRangeErrorcodes, compaction is the only reclamation.Registry surface (§7.2). Two-phase native calls:
image_beginvalidates and reserves (returning the absolute address the host writes pixels at — video's same-size-per-frame path allocates nothing),image_commitbumps the data version.image_removeemits the protocol's data-freeingd=Ideletion block into the output buffer and reconciles covered cells to their blank state (INV-I6) so the next diff emits nothing redundant.Tier engine (§9). Pre-layout resolution (variant, omission, liveness, evidence mirror, line-mode cap) expands the void
imgop into a Clay element: the alt tier is a wrapped, vertically-clipped text child (so alt's fit sizing and wrap come from the layout engine's own text machinery); pixel tiers attach the op's wire address ascustomData. The render-command walk then applies the four footprint-preserving demotions (clip containment §8.5, placement-id collision §9.2.1, pixel-overlap §10.3, table capacity §5.4) — kitty→ascii only, same painted footprint, no re-measurement — then records the placement or paints the art.Frame phases (§9.2.6). Coverage pass (pixel coverage asserts blanks over the back buffer, later element wins shared cells) → repair precheck (a placement whose covered cells will receive writes re-places; runs before any dirty-marking) → scoped stale deletions (lowercase
d=i,i=…,p=…, data retained) → delete-before-re-transmit chunked transmission (4096-char base64 chunks,m=1/m=0,q=2on every block) → cell writes (the ordinary diff) → placements after, with the §7.6 cursor-restore carve-out. Steady state is byte-silent.Ascii art (§9.3). Per-cell circle sampling (6 internal + 10 external, geometry in the source and mirrored in the generator), directional-then-global contrast with power-of-two exponents (γd=4, γg=2 — exact repeated squaring, no libm, bit-identical everywhere), 95-character nearest-match against shape vectors generated at build time from the public-domain font8x8 bitmap font (
deno task gen-shape, golden-lockable).Capability mirror.
graphics_capability(ct, kitty)— the renderer's private capability state (terminfo-spec §4.2); the true→false transition emits the §11.2 denial bytes immediately (TINV-5). Wired to theupdate()capability fold in the img PR.Verification
makebuilds clean; the full existing suite passes (27 tests / 328 steps — post-feat: term.update() folds CapabilityEvents into runtime capabilities #133 main, this branch is rebased onto it).d=Iremoval bytes.