diff options
| author | user <user@clank> | 2026-08-14 23:25:46 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-14 23:25:46 +0200 |
| commit | aa01b72770d83091a53a43722ecc9a527bc18931 (patch) | |
| tree | 04a35b6ba2566a154cc344ebc0e031941cbce873 /src/cmd.c | |
| parent | sl0ppty: carry the terminal's cell size, so images can have a size (diff) | |
| download | slosh-aa01b72770d83091a53a43722ecc9a527bc18931.tar.gz slosh-aa01b72770d83091a53a43722ecc9a527bc18931.tar.xz slosh-aa01b72770d83091a53a43722ecc9a527bc18931.zip | |
sl0ppty: re-emit what the program meant, not what it covers
Images rendered after the last commit, and were still wrong twice. Both
mistakes are invisible in a still picture, which is what every test was
looking at, and obvious the moment anything moves.
**The sub-cell offset was dropped.** A placement says where the image starts
*inside* its first cell (`X=`/`Y=`); that is what makes motion smooth rather
than a slideshow. We tracked the placement and re-emitted it without those,
so a bouncing logo moved in steps of a whole cell -- eight pixels across,
sixteen down.
**`c=`/`r=` were passed on unconditionally.** They mean *scale the image into
this many cells*, and the count a natural-size image happens to cover goes up
by one whenever it straddles one more boundary -- so the picture changed size
as it slid along. They are now sent only when the program asked for them,
which lib-vt reports as 0 when it did not.
Cropping splits the same way, and getting it wrong took a test failure to
notice: at natural size a lost cell costs the screen pixels the pane has left
(measured from the offset, not the cell edge, or an offset image hangs up to
a cell over the border); when the program asked to scale, a lost cell is
worth source/cells pixels and the crop is proportional. Cropping a 4-pixel
image scaled across 40 cells by screen pixels removes all of it.
gfx_place() took twenty positional arguments, half of them uint32_t pixel
quantities where a transposed pair compiles perfectly and lands the picture
slightly wrong -- the exact bug class this file exists for. It takes a struct
now.
`{"cmd":"graphics","format":"bytes"}` answers with the escape sequences the
client is actually sent. The model being right is not the same as the bytes
being right, and this whole episode was a lesson in asserting on the first
while the second was wrong. The new tests assert on the bytes.
Diffstat (limited to 'src/cmd.c')
| -rw-r--r-- | src/cmd.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -220,6 +220,21 @@ static char *cmd_json(app_t *a, screen_t *s, input_parser_t *in, } if (strcmp(cmd, "graphics") == 0) { app_compose(a, s); + /* `format:"bytes"` answers with what the client's terminal is actually + * sent, escape sequences and all. The model and the bytes are two + * different things, and this session was one long lesson in asserting on + * the model while the bytes were wrong. */ + if (strcmp(jv_gets(req, "format", "placements"), "bytes") == 0) { + size_t len = 0; + const char *raw = app_graphics(a, &len); + json_t j; + json_init(&j); + json_obj_open(&j, NULL); + json_bool(&j, "ok", true); + json_str(&j, "bytes", raw ? raw : "", raw ? len : 0); + json_obj_close(&j); + return j.buf; + } return jok_raw("placements", app_graphics_json(a)); } if (strcmp(cmd, "clipboard") == 0) { |
