Repository navigation
feat: img element — public surface, validation, and test suite - #142
Draft
natemoo-re wants to merge 4 commits into
Draft
natemoo-re wants to merge 4 commits into
natemoo-re wants to merge 4 commits into
Conversation
Contributor
Changeset suggestionThe current changeset no longer matches this PR. This review contains a corrected replacement. Why: Changeset package scope does not match the affected packages confidently. View the proposed changeset---
'@bomb.sh/tty': minor
---
Adds the `img()` directive for declarative image rendering in terminal UIs.
The renderer walks a fidelity ladder — kitty graphics protocol, shape-aware ASCII character art, or alt text — resolved from `RuntimeCapabilities.kittyGraphics` evidence. Images are registered as caller-owned RGBA8 buffers via `setImage` / `removeImage`; transmission is lazy and re-transmission only occurs on data change, so steady-state renders are byte-silent.
```ts
term.setImage(1, { width: 128, height: 64, pixels: rgba8 });
term.removeImage(1); // returns deletion bytes to write immediately
term.render([img("cover", { image: 1, alt: "cover art" })]);
```
`createTerm` accepts an `imagePoolBytes` option (default 4 MiB) that sizes the fixed pixel pool. `update()` emits cleanup bytes immediately when a capability denial or resize invalidates live placements. Line mode caps the ladder at `ascii`. Errors surface as `IMAGE_NOT_FOUND`, `IMAGE_PLACEMENTS_EXCEEDED`, and `IMAGE_PLACEMENT_COLLISION`.
#### Migration
`@bomb.sh/tty` is pre-1.0; this minor bump is a breaking change to the `Term` interface — `setImage` and `removeImage` are new required methods. Code that constructs a `Term` directly (rather than via `createTerm` or `validated`) must add both methods:
```diff
const myTerm: Term = {
render(ops) { … },
update(events) { … },
+ setImage(id, data) { … },
+ removeImage(id) { … },
get capabilities() { … },
};
```Review this changeset manually If this draft is correct, react with 🚀 and Cooper will commit it to this branch. |
| @@ -0,0 +1,15 @@ | |||
| --- | |||
Contributor
There was a problem hiding this comment.
Changeset needs revision.
Changeset package scope does not match the affected packages confidently.
View the proposed replacement
---
'@bomb.sh/tty': minor
---
Adds the `img()` directive for declarative image rendering in terminal UIs.
The renderer walks a fidelity ladder — kitty graphics protocol, shape-aware ASCII character art, or alt text — resolved from `RuntimeCapabilities.kittyGraphics` evidence. Images are registered as caller-owned RGBA8 buffers via `setImage` / `removeImage`; transmission is lazy and re-transmission only occurs on data change, so steady-state renders are byte-silent.
```ts
term.setImage(1, { width: 128, height: 64, pixels: rgba8 });
term.removeImage(1); // returns deletion bytes to write immediately
term.render([img("cover", { image: 1, alt: "cover art" })]);
```
`createTerm` accepts an `imagePoolBytes` option (default 4 MiB) that sizes the fixed pixel pool. `update()` emits cleanup bytes immediately when a capability denial or resize invalidates live placements. Line mode caps the ladder at `ascii`. Errors surface as `IMAGE_NOT_FOUND`, `IMAGE_PLACEMENTS_EXCEEDED`, and `IMAGE_PLACEMENT_COLLISION`.
#### Migration
`@bomb.sh/tty` is pre-1.0; this minor bump is a breaking change to the `Term` interface — `setImage` and `removeImage` are new required methods. Code that constructs a `Term` directly (rather than via `createTerm` or `validated`) must add both methods:
```diff
const myTerm: Term = {
render(ops) { … },
update(events) { … },
+ setImage(id, data) { … },
+ removeImage(id) { … },
get capabilities() { … },
};
```
commit: |
|
Size Increased — +17.8 KB 161.5 KB unpacked |
natemoo-re
marked this pull request as draft
October 9, 2026 20:11
natemoo-re
force-pushed
the
feat/img-element
branch
from
October 9, 2026 20:17
6f5f074 to
843b5dd
Compare
natemoo-re
force-pushed
the
feat/img-element
branch
2 times, most recently
from
October 9, 2026 20:22
b18ced0 to
033ef6d
Compare
natemoo-re
force-pushed
the
feat/img-element
branch
from
December 4, 2026 03:06
5b99b5a to
c88b8e1
Compare
natemoo-re
force-pushed
the
feat/img-element
branch
from
December 4, 2026 03:09
c88b8e1 to
2e46b96
Compare
img() packs the void OP_IMG directive; term.setImage()/removeImage() manage the pixel-surface registry; validate() accepts img ops; the Graphics Specification's suite lands in test/graphics.test.ts. - removeImage() returns void like update(): the next render emits the data-freeing deletion first, once, and only when data was sent. - kitty-graphics capability changes reach the renderer from update(); denial and resize cleanup is asserted on the next render's output. - bg takes the full color value space; symbolic words travel with an IMG_BG_SYMBOLIC flag and resolve against the inherited color. - New coverage: queued deletions inside the BSU/ESU pair (including a deletions-only frame), color-tier redraws re-placing without re-transmission, img replay re-resolving its tier, CSS color bg. - The suite's helper opts into truecolor so art colors assert exactly; the 256-color baseline downmaps them per the color-encoding tier.
Adapted from spike/img-demo onto the shipped surface: the unicode tier, debug quiet level, and byte-returning update()/removeImage() are gone. One generated image renders through auto, forced kitty, forced ascii, and alt panels; a status line counts each frame's transmissions, placements, and deletions so the queued cleanup after a denial or removal is visible on the next frame. Colors use CSS strings, and exit removes every image and flushes the deletions with a final render.
natemoo-re
force-pushed
the
feat/img-element
branch
from
December 4, 2026 03:27
197b05f to
df5139d
Compare
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.
The Graphics Specification's public TypeScript API, stacked on the substrate PR (#141). Final PR of the stack: spec (#140) → implementation (#141) → img (this PR).
Public surface
ops.ts— the voidimg()directive: pixel-surface registry id, requiredalt(empty = decorative), sizing axes (fit resolves to the §8.3 intrinsic size), evidence-gatedvariantoverride, elementbg. The transfer encoding mirrors the C decode;imgops don't participate in open/close balance.term.ts—Term.setImage/Term.removeImageover the two-phase native surface (beginvalidates + reserves at an absolute address → the host copies pixels →commitbumps the version; video's same-size path allocates nothing). ClosedRangeErrors per §6.2's validation table.createTermtakesimagePoolBytes(default 4 MiB).update()bridges — thekitty-graphicsCapabilityEvent feeds the renderer's capability mirror (terminfo-spec §4.2's private renderer state); the engine's TINV-5 cleanup bytes (capability denial §11.2, resize §10.5) surface inupdate()'s return.validate.ts— theImgop shape: registry ids in the protocol's positive range, requiredalt, the variant union.Verification
test/graphics.test.ts): tier resolution incl. the variant fall-through and line-mode cap; kitty conformance (chunk boundaries m=1/m=0, replace cycle ordering delete→transmit→place, byte-silent steady state, move = same-placement-id re-place with no delete/re-transmit); cleanup (scopedd=i,p=on unmount,d=Iremoval + idempotence, deletion bytes without evidence); capability invalidation (immediate denial bytes, re-arm re-transmission); resize; ascii determinism + luminance ordering + alpha/transparent-bg; alt tier; registry validation; input-stream cleanliness.Review notes
img-as-root cannot move (its footprint is window-derived) — moves are exercised via a padded container.a=action key), so the renderer's own quiet emissions can't surface as capability events (INV-I5).