osc: use BEL terminator in OSC replies to BEL-terminated OSC queries

This matches the documented (and observed) behavior in xterm:

> XTerm accepts either BEL or ST for terminating OSC sequences, and
> when returning information, uses the same terminator used in a query

-- https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
This commit is contained in:
Craig Barnes 2021-10-20 12:48:37 +01:00
parent 6dfacb9c08
commit 52dcf72d0b
3 changed files with 19 additions and 6 deletions

23
osc.c
View file

@ -159,7 +159,11 @@ from_clipboard_done(void *user)
term_to_slave(term, res, 4); term_to_slave(term, res, 4);
} }
term_to_slave(term, "\033\\", 2); if (term->vt.osc.bel)
term_to_slave(term, "\a", 1);
else
term_to_slave(term, "\033\\", 2);
free(ctx); free(ctx);
} }
@ -642,10 +646,12 @@ osc_dispatch(struct terminal *term)
uint8_t r = (color >> 16) & 0xff; uint8_t r = (color >> 16) & 0xff;
uint8_t g = (color >> 8) & 0xff; uint8_t g = (color >> 8) & 0xff;
uint8_t b = (color >> 0) & 0xff; uint8_t b = (color >> 0) & 0xff;
const char *terminator = term->vt.osc.bel ? "\a" : "\033\\";
char reply[32]; char reply[32];
size_t n = xsnprintf(reply, sizeof(reply), "\033]4;%u;rgb:%02x/%02x/%02x\033\\", size_t n = xsnprintf(
idx, r, g, b); reply, sizeof(reply), "\033]4;%u;rgb:%02x/%02x/%02x%s",
idx, r, g, b, terminator);
term_to_slave(term, reply, n); term_to_slave(term, reply, n);
} }
@ -695,6 +701,7 @@ osc_dispatch(struct terminal *term)
uint8_t r = (color >> 16) & 0xff; uint8_t r = (color >> 16) & 0xff;
uint8_t g = (color >> 8) & 0xff; uint8_t g = (color >> 8) & 0xff;
uint8_t b = (color >> 0) & 0xff; uint8_t b = (color >> 0) & 0xff;
const char *terminator = term->vt.osc.bel ? "\a" : "\033\\";
/* /*
* Reply in XParseColor format * Reply in XParseColor format
@ -702,8 +709,8 @@ osc_dispatch(struct terminal *term)
*/ */
char reply[32]; char reply[32];
size_t n = xsnprintf( size_t n = xsnprintf(
reply, sizeof(reply), "\033]%u;rgb:%02x/%02x/%02x\033\\", reply, sizeof(reply), "\033]%u;rgb:%02x/%02x/%02x%s",
param, r, g, b); param, r, g, b, terminator);
term_to_slave(term, reply, n); term_to_slave(term, reply, n);
break; break;
@ -761,9 +768,13 @@ osc_dispatch(struct terminal *term)
uint8_t r = (term->cursor_color.cursor >> 16) & 0xff; uint8_t r = (term->cursor_color.cursor >> 16) & 0xff;
uint8_t g = (term->cursor_color.cursor >> 8) & 0xff; uint8_t g = (term->cursor_color.cursor >> 8) & 0xff;
uint8_t b = (term->cursor_color.cursor >> 0) & 0xff; uint8_t b = (term->cursor_color.cursor >> 0) & 0xff;
const char *terminator = term->vt.osc.bel ? "\a" : "\033\\";
char reply[32]; char reply[32];
size_t n = xsnprintf(reply, sizeof(reply), "\033]12;rgb:%02x/%02x/%02x\033\\", r, g, b); size_t n = xsnprintf(
reply, sizeof(reply), "\033]12;rgb:%02x/%02x/%02x%s",
r, g, b, terminator);
term_to_slave(term, reply, n); term_to_slave(term, reply, n);
break; break;
} }

View file

@ -172,6 +172,7 @@ struct vt {
uint8_t *data; uint8_t *data;
size_t size; size_t size;
size_t idx; size_t idx;
bool bel; /* true if OSC string was terminated by BEL */
} osc; } osc;
/* Start coordinate for current OSC-8 URI */ /* Start coordinate for current OSC-8 URI */

1
vt.c
View file

@ -579,6 +579,7 @@ action_osc_end(struct terminal *term, uint8_t c)
if (!osc_ensure_size(term, term->vt.osc.idx + 1)) if (!osc_ensure_size(term, term->vt.osc.idx + 1))
return; return;
term->vt.osc.data[term->vt.osc.idx] = '\0'; term->vt.osc.data[term->vt.osc.idx] = '\0';
term->vt.osc.bel = c == '\a';
osc_dispatch(term); osc_dispatch(term);
} }