Skip to content

zn v0.12.1: preview pictures re-fit when the pane's width changes - #19

Merged
adibhanna merged 1 commit into
mainfrom
zn-0.12.1
Oct 27, 2026
Merged

adibhanna merged 1 commit into
mainfrom
zn-0.12.1

Conversation

@adibhanna

Copy link
Copy Markdown
Contributor

Preview pictures now re-fit when the preview pane's width changes.

In 0.12.0 a picture's size in terminal cells was fixed the first time it was shown. LaTeX, TikZ, typst and mermaid pictures kept the size of the moment their render finished, and a vault image only re-sized when the pane got narrower. A note first previewed in a narrow pane (a split, a window still opening) kept small pictures after the pane grew: a long formula sized for 60 columns stayed a faint dotted line at 152, as in the 0.12.0 announcement screenshot.

The image store now keeps each picture's PNG and fits it to the current width both ways. A size already sent is reused, at most three sizes per picture stay in the terminal (the oldest is freed), and the kept PNGs are capped at 64 MiB.

Verified: go vet ./..., go test ./..., cross-builds for darwin, linux and windows. Five new tests; the two behaviour tests fail on main (the picture stays 30 cells wide after the preview grows to 122) and pass here. In real Ghostty, zn in a pane widened from 60 to 152 columns: on 0.12.0 the long formula stays tiny, with the fix it re-fits.

A picture's size in terminal cells was fixed the first time it was
shown. LaTeX, TikZ, typst and mermaid pictures kept the size their
background render finished at, and a vault image was only re-sent when
the pane got narrower, never wider. So a note first previewed in a
narrow pane (a split, a window still opening) kept small pictures after
the pane grew: a long formula sized for 60 columns stayed a faint dotted
line at 152, which is what the 0.12.0 announcement screenshot showed.

The image store now keeps each picture's PNG and fits it to the width
it is asked for, both ways, every time the preview redraws. A size
already sent is reused, so moving between two widths sends nothing new,
and at most three sizes of one picture stay in the terminal: the oldest
is freed with a delete command. The kept PNGs are capped at 64 MiB;
past that the least recently shown picture's bytes go, and it keeps the
size it has (a vault image reloads from disk instead).

It does not follow a change of the terminal's font size: the cell size
is still read once, at the first picture.
@adibhanna
adibhanna merged commit 40caf0a into main Oct 27, 2026
5 checks passed
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.

1 participant