mirror of
https://github.com/mpv-player/mpv
synced 2025-04-23 12:59:51 +02:00
vo_kitty: do not add trailing NULL
byte in payload
In the past `strlen` was used in the write function, which omitted the trailing NULL byte, however with the addition of `bstr` API the NULL byte produced by `av_base64_encode` in the output is also written to stdout, this causes terminals (namely Ghostty) to not display the frame. There was also an additional edge case where if the entire output is less than 4096 bytes the finishing escape sequence `\033_Gm=0;` was never emitted. Adding a check for this after the for loop fixes this behavior.
This commit is contained in:
parent
d9dc84c0fc
commit
8edabd5644
@ -346,19 +346,32 @@ static void flip_page(struct vo *vo)
|
||||
DCS_GUARD_APPEND(p, bstr_xappend_asprintf(NULL, &p->cmd, KITTY_ESC_IMG,
|
||||
p->width, p->height));
|
||||
|
||||
for (int offset = 0; offset < p->output_size; ) {
|
||||
int chunk = MPMIN(4096, p->output_size - offset);
|
||||
int output_size = p->output_size - 1;
|
||||
int offset = 0;
|
||||
|
||||
for (; offset < output_size; ) {
|
||||
int chunk = MPMIN(4096, output_size - offset);
|
||||
|
||||
if (offset > 0)
|
||||
DCS_GUARD_APPEND(p, bstr_xappend_asprintf(NULL, &p->cmd,
|
||||
KITTY_ESC_CONTINUE,
|
||||
offset + chunk < p->output_size));
|
||||
offset + chunk < output_size));
|
||||
|
||||
// Append at max chunk bytes
|
||||
bstr_xappend(NULL, &p->cmd, (bstr){p->output + offset, chunk});
|
||||
DCS_GUARD_APPEND(p, bstr_xappend(NULL, &p->cmd, KITTY_ESC_END));
|
||||
offset += chunk;
|
||||
}
|
||||
|
||||
// When the data is less than or equal to chunk size the final packet
|
||||
// isn't sent, i.e. an escape sequence with `m=0`.
|
||||
// This ensures that an escape sequence with `m=0` is sent and
|
||||
// terminals stay happy
|
||||
if (offset == 0) {
|
||||
DCS_GUARD_APPEND(p, bstr_xappend_asprintf(NULL, &p->cmd,
|
||||
KITTY_ESC_CONTINUE, 0));
|
||||
DCS_GUARD_APPEND(p, bstr_xappend(NULL, &p->cmd, KITTY_ESC_END));
|
||||
}
|
||||
}
|
||||
|
||||
write_bstr(p->cmd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user