Skip to content

libghostty(formatter): enable kitty gfx for vt#12182

Open
neurosnap wants to merge 3 commits intoghostty-org:mainfrom
neurosnap:libghostty-formatter-kitty-gfx-vt
Open

libghostty(formatter): enable kitty gfx for vt#12182
neurosnap wants to merge 3 commits intoghostty-org:mainfrom
neurosnap:libghostty-formatter-kitty-gfx-vt

Conversation

@neurosnap
Copy link
Copy Markdown
Contributor

@neurosnap neurosnap commented Apr 8, 2026

This adds support for printing kitty graphics using the terminal.Formatter through a new terminal.ScreenFormatter.Extra option kitty_graphics.

This only implements kitty gfx for the vt format option.

This enables kitty gfx support for zmx when we restore terminal scrollback on re-attach: neurosnap/zmx#14

References: https://discord.com/channels/1005603569187160125/1420009803173859449/1446588699952287849

The tricky part was getting the spacing correct when mixing images and content which I made sure to lock down inside a test.

To get the spacing correct I needed to thread the Terminal object through the formatters so I could run placement.gridSize().

I wrote the bulk of the implementation and QA'd the results. I manually tested this feature
using a modified example/zig-formatter which can be found in this branch: neurosnap@2b19faf

./ex.sh | zig build run
Screenshot 2026-04-08 at 11 41 42 AM

ai disclosure

I used AI to help me:

  • find the critical areas to add this feature
  • write tests that confirmed desired behavior
  • debug issues that came up with my impl

@neurosnap neurosnap requested a review from a team as a code owner April 8, 2026 15:32
@neurosnap neurosnap force-pushed the libghostty-formatter-kitty-gfx-vt branch from 490a64f to 135ce88 Compare April 8, 2026 18:08
This adds support for printing kitty graphics using the `terminal.Formatter` through a new
`terminal.ScreenFormatter.Extra` option `kitty_graphics`.

This only implements kitty gfx for the `vt` format option.

References: https://discord.com/channels/1005603569187160125/1420009803173859449/1446588699952287849
@neurosnap neurosnap force-pushed the libghostty-formatter-kitty-gfx-vt branch from 135ce88 to d26cc3b Compare April 8, 2026 18:17

if (self.images.imageById(key.image_id)) |image| {
const grid = placement.gridSize(image, self.terminal);
// Create newlines for the entire image height
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to do this? I thought the Kitty protocol handlers do this automatically. The VT formatter should try to just emit the VT sequences that result in the same behaviors, no?

Copy link
Copy Markdown
Contributor Author

@neurosnap neurosnap Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Good catch. I was experimenting with different implementations and had left the C=1 in the placement escape code which disables automatic cursor advancement. Updated.

This allows the cursor to advance after the image and now we don't have to
manually add newlines after placement.
@neurosnap neurosnap requested a review from mitchellh April 8, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants