Fixes#5255
This adds support for the Kitty graphics animation frames
(https://sw.kovidgoyal.net/kitty/graphics-protocol/#animation),
completely (transmission, control, composition, rendering, etc.).
This does it in a somewhat naive way: we pre-compose all frames and
store the full RGBA in-memory. Animation is already rare enough, and I
wanted to focus on things working first, so I didn't optimize this very
well. I also wanted this PR to be relatively understandable up front. We
can add complexity later.
But, this adds very little overhead to a non-animation using Kitty
graphics user. The animation state is heap-allocated only when its
needed. So, it just costs a pointer sized field on every image. Plus a
little bit of overhead in the loading state (which itself is heap
allocated during image load only).
On the renderer side, this **unifies Kitty graphics animations and
custom shader animations into a single animation abstraction.** This
simplified our renderer thread and made the generic renderer more
complicated (slightly, its not much!).
**AI usage:** Test writing, validation against the spec/reference
implementation. I drove the main architecture and shaped out the
functions and params, animation storage, etc. I had AI fill in some of
the blanks that I spaced out. Commit messages, comments, and this PR
message are written by me.
## Demo
https://github.com/user-attachments/assets/91be3d66-a5ff-4cab-b3e9-e672f39861c9
Translate the remaining 181 untranslated strings in po/zh_TW.po,
bringing it to 100% coverage (252/252), including the strings added by
the recent template update.
All 72 existing translations are preserved unchanged.
This modifies our wuffs dependency so that it no longer requires libc.
This unblocks using wuffs from libghostty-vt on freestanding targets,
which we'll eventually want for some Kitty graphics stuff.
This modifies our wuffs dependency so that it no longer requires libc.
This unblocks using wuffs from libghostty-vt on freestanding targets,
which we'll eventually want for some Kitty graphics stuff.
The gaToRgba swizzle requested a YA_PREMUL source pixel format from the
wuffs pixel swizzler, but wuffs does not support YA_PREMUL as a swizzle
source. As a result, gaToRgba returned error.WuffsError for every input.
The path can't happen in Ghostty GUI today since our PNG decoding always
produces RGBA, but it is possible via libghostty that submit grey+alpha
directly.
The gaToRgba swizzle requested a YA_PREMUL source pixel format from
the wuffs pixel swizzler, but wuffs does not support YA_PREMUL as a
swizzle source. As a result, gaToRgba returned error.WuffsError for every input.
The path can't happen in Ghostty GUI today since our PNG decoding always
produces RGBA, but it is possible via libghostty that submit grey+alpha
directly.
This adds full support for relative placements:
https://sw.kovidgoyal.net/kitty/graphics-protocol/#relative-placements
(`R=` and `Q=`). The high-level description is that this allows images
to be placed relative to other images. For more details, the spec
explains it better than I can, or the demo video below.
The implementation here was pretty straightforward. It mainly revolved
around adding parent resolution logic to puts (and validation), and
proper unparented placement reaping in the right points, and then the
various tests around that. The renderer logic itself was also
straigthforward, I had to add some offset resolution to the core
graphics storage but we can reuse that. The main complexity -- as always
-- (MY OWN EMDASHES) is Unicode placeholders. But... also not too hard.
After this, the only feature we don't support from the protocol is
animation.
**AI usage:** Test writing, validation against spec/reference, judging,
and some "fill in the function/block". I setup the overall shape of the
implementation.
## Demo
Ghostty on the left, Kitty on the right
https://github.com/user-attachments/assets/dc2ec3ac-480a-4587-94e4-06a842f9b3f4
No issues in actual shipped code found.
- ci: valgrind runs now fail when Memcheck finds an unsuppressed error.
- fix real memory issues in unit tests
- add a suppression for Zig's flate compression which documents as
purposely using undefined memory
The TempDir tests saved directory descriptors before close and expected
`fcntl(F_GETFD)` to return `EBADF` afterward. A descriptor number
becomes available for reuse as soon as it is closed.
Unrelated I/O could reuse either number before the assertion, causing
the Valgrind job to report a leak even though TempDir closed both
handles correctly [1].
Remove the raw descriptor assertions and keep coverage of observable
delete and retain behavior. Explain at both close sites why descriptor
numbers cannot identify the original handles after close.
[1]:
https://github.com/ghostty-org/ghostty/actions/runs/32410237002/job/96561246487
- ci: valgrind runs now fail when Memcheck finds an unsuppressed error.
- fix real memory issues in unit tests
- add a suppression for Zig's flate compression which documents as
purposely using undefined memory
The TempDir tests saved directory descriptors before close and expected
`fcntl(F_GETFD)` to return `EBADF` afterward. A descriptor number
becomes available for reuse as soon as it is closed.
Unrelated I/O could reuse either number before the assertion, causing
the Valgrind job to report a leak even though TempDir closed both
handles correctly [1].
Remove the raw descriptor assertions and keep coverage of observable
delete and retain behavior. Explain at both close sites why descriptor
numbers cannot identify the original handles after close.
[1]: https://github.com/ghostty-org/ghostty/actions/runs/32410237002/job/96561246487
Fixes#4323
The Kitty graphics protocol requires that when margins are defined and
index commands are used, only images entirely within the scroll region
are scrolled, and that they are clipped when scrolling would cause them
to extend outside the region [1].
This implements that part of the spec.
Benchmarked pure `\n` terminal streams to ensure that the no-image case
is not regressed. Our branch hints plus checks on placements keep that
true. When images are present, things get a lot slower but thats
acceptable for now.
## Demo
https://github.com/user-attachments/assets/22e23c8b-ffd4-48fb-9e86-31e810d36ea0
[1]:
https://sw.kovidgoyal.net/kitty/graphics-protocol/#interaction-with-other-terminal-actions
Fixes#4323
The Kitty graphics protocol requires that when margins are defined
and index commands are used, only images entirely within the scroll
region are scrolled, and that they are clipped when scrolling would
cause them to extend outside the region [1].
This implements that part of the spec.
Benchmarked pure `\n` terminal streams to ensure that the no-image case
is not regressed. Our branch hints plus checks on placements keep that
true. When images are present, things get a lot slower but thats
acceptable for now.
[1]: https://sw.kovidgoyal.net/kitty/graphics-protocol/#interaction-with-other-terminal-actions
Fixes#2197
Image transmissions without an explicit ID (i=) were assigned IDs from a
wrapping counter starting with no collision check. The protocol allows
clients to choose IDs anywhere in the u32 range, so an auto-assigned ID
could collide.
Number-based transmissions (I= without i=) now receive the smallest ID
not currently in use. This probes the image map in an `O(N)` fashion but
performance issues here require a pathological client and this
implementation matches Kitty's performance as well.
Fixes#2197
Image transmissions without an explicit ID (i=) were assigned IDs from
a wrapping counter starting with no collision check. The protocol allows
clients to choose IDs anywhere in the u32 range, so an auto-assigned ID could
collide.
Number-based transmissions (I= without i=) now receive the smallest ID
not currently in use. This probes the image map in an `O(N)` fashion but
performance issues here require a pathological client and this implementation
matches Kitty's performance as well.
There are various validation behaviors we did that matched the spec but
didn't match Kitty, because Kitty is written in C (these parts) and does
a lot of C-ish things (like bool is any non-zero value, despite the spec
saying 1/0).
This also fixes a more major issue where invalid formats should be
deferred until transmission finishes so we send a proper response. Right
now we send no response which can cause a client to hang!
There are various validation behaviors we did that matched the spec but
didn't match Kitty, because Kitty is written in C (these parts) and does
a lot of C-ish things (like bool is any non-zero value, despite the spec
saying 1/0).
This also fixes a more major issue where invalid formats should be
deferred until transmission finishes so we send a proper response. Right
now we send no response which can cause a client to hang!
The `d=r`/`d=R` delete parser required a `y` key and enforced `x <= y`,
rejecting the entire command with `error.InvalidFormat` otherwise. Both
bounds now default to zero and neither is validated.
This matches upstream reference implementation.
The `d=r`/`d=R` delete parser required a `y` key and enforced `x <= y`,
rejecting the entire command with `error.InvalidFormat` otherwise. Both
bounds now default to zero and neither is validated.
This matches upstream reference implementation.
Emit a `progress_report` remove effect from the `full_reset` arm,
matching kitty and WezTerm which both clear progress on reset.
Previously, only the termio `StreamHandler` removed the progress bar on
RIS (#10178) - but the terminal stream handler used by `libghostty-vt`
did not, so an embedder's progress bar would outlive the reset.
Initial input files remained open and their fully read buffers remained
allocated after queueWrite copied their contents. Close these files on
both startup success and failure, free their contents after queueing,
and borrow raw values already owned by the arena.
**AI Usage:** This was spotted by GPT 5.6 Sol. I reworked the code a bit
and understand it all.
Glyf rasterization previously let z2d allocate its alpha surface, then
duplicated the completed pixels into caller-owned storage. Back the z2d
surface with the final bitmap instead, eliminating one allocation and a
full bitmap copy for each non-empty glyph.
Initial input files remained open and their fully read buffers remained
allocated after queueWrite copied their contents. Close these files on
both startup success and failure, free their contents after queueing, and
borrow raw values already owned by the arena.
Glyf rasterization previously let z2d allocate its alpha surface, then
duplicated the completed pixels into caller-owned storage. Back the z2d
surface with the final bitmap instead, eliminating one allocation and a
full bitmap copy for each non-empty glyph.