mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-01 01:40:13 -05:00
Merge branch 'osc4-multi-parameter'
This commit is contained in:
commit
6d7c686a3c
2 changed files with 51 additions and 50 deletions
|
|
@ -46,6 +46,7 @@
|
||||||
* Restored cursor position in 'normal' screen when window was resized
|
* Restored cursor position in 'normal' screen when window was resized
|
||||||
while in 'alt' screen.
|
while in 'alt' screen.
|
||||||
* Hostname in OSC 7 URI not being validated.
|
* Hostname in OSC 7 URI not being validated.
|
||||||
|
* OSC 4 with multiple `c;spec` pairs.
|
||||||
|
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
|
||||||
100
osc.c
100
osc.c
|
|
@ -430,47 +430,48 @@ osc_dispatch(struct terminal *term)
|
||||||
case 4: {
|
case 4: {
|
||||||
/* Set color<idx> */
|
/* Set color<idx> */
|
||||||
|
|
||||||
/* First param - the color index */
|
string--;
|
||||||
unsigned idx = 0;
|
|
||||||
for (; *string != '\0' && *string != ';'; string++) {
|
|
||||||
char c = *string;
|
|
||||||
idx *= 10;
|
|
||||||
idx += c - '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (idx >= 256)
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Next follows the color specification. For now, we only support rgb:x/y/z */
|
|
||||||
|
|
||||||
if (*string == '\0') {
|
|
||||||
/* No color specification */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(*string == ';');
|
assert(*string == ';');
|
||||||
string++;
|
|
||||||
|
|
||||||
/* Client queried for current value */
|
for (const char *s_idx = strtok(string, ";"), *s_color = strtok(NULL, ";");
|
||||||
if (strlen(string) == 1 && string[0] == '?') {
|
s_idx != NULL && s_color != NULL;
|
||||||
uint32_t color = term->colors.table[idx];
|
s_idx = strtok(NULL, ";"), s_color = strtok(NULL, ";"))
|
||||||
uint8_t r = (color >> 16) & 0xff;
|
{
|
||||||
uint8_t g = (color >> 8) & 0xff;
|
/* Parse <idx> parameter */
|
||||||
uint8_t b = (color >> 0) & 0xff;
|
unsigned idx = 0;
|
||||||
|
for (; *s_idx != '\0'; s_idx++) {
|
||||||
|
char c = *s_idx;
|
||||||
|
idx *= 10;
|
||||||
|
idx += c - '0';
|
||||||
|
}
|
||||||
|
|
||||||
char reply[32];
|
/* Client queried for current value */
|
||||||
snprintf(reply, sizeof(reply), "\033]4;%u;rgb:%02x/%02x/%02x\033\\",
|
if (strlen(s_color) == 1 && s_color[0] == '?') {
|
||||||
idx, r, g, b);
|
uint32_t color = term->colors.table[idx];
|
||||||
term_to_slave(term, reply, strlen(reply));
|
uint8_t r = (color >> 16) & 0xff;
|
||||||
break;
|
uint8_t g = (color >> 8) & 0xff;
|
||||||
|
uint8_t b = (color >> 0) & 0xff;
|
||||||
|
|
||||||
|
char reply[32];
|
||||||
|
snprintf(reply, sizeof(reply), "\033]4;%u;rgb:%02x/%02x/%02x\033\\",
|
||||||
|
idx, r, g, b);
|
||||||
|
term_to_slave(term, reply, strlen(reply));
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
uint32_t color;
|
||||||
|
bool color_is_valid = s_color[0] == '#'
|
||||||
|
? parse_legacy_color(s_color, &color)
|
||||||
|
: parse_rgb(s_color, &color);
|
||||||
|
|
||||||
|
if (!color_is_valid)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
LOG_DBG("change color definition for #%u to %06x", idx, color);
|
||||||
|
term->colors.table[idx] = color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t color;
|
|
||||||
if (string[0] == '#' ? !parse_legacy_color(string, &color) : !parse_rgb(string, &color))
|
|
||||||
break;
|
|
||||||
|
|
||||||
LOG_DBG("change color definition for #%u to %06x", idx, color);
|
|
||||||
term->colors.table[idx] = color;
|
|
||||||
render_refresh(term);
|
render_refresh(term);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -558,24 +559,23 @@ osc_dispatch(struct terminal *term)
|
||||||
LOG_DBG("resetting all colors");
|
LOG_DBG("resetting all colors");
|
||||||
for (size_t i = 0; i < 256; i++)
|
for (size_t i = 0; i < 256; i++)
|
||||||
term->colors.table[i] = term->colors.default_table[i];
|
term->colors.table[i] = term->colors.default_table[i];
|
||||||
} else {
|
}
|
||||||
unsigned idx = 0;
|
|
||||||
|
|
||||||
for (; *string != '\0'; string++) {
|
else {
|
||||||
char c = *string;
|
for (const char *s_idx = strtok(string, ";");
|
||||||
if (c == ';') {
|
s_idx != NULL;
|
||||||
LOG_DBG("resetting color #%u", idx);
|
s_idx = strtok(NULL, ";"))
|
||||||
term->colors.table[idx] = term->colors.default_table[idx];
|
{
|
||||||
idx = 0;
|
unsigned idx = 0;
|
||||||
continue;
|
for (; *s_idx != '\0'; s_idx++) {
|
||||||
|
char c = *s_idx;
|
||||||
|
idx *= 10;
|
||||||
|
idx += c - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
idx *= 10;
|
LOG_DBG("resetting color #%u", idx);
|
||||||
idx += c - '0';
|
term->colors.table[idx] = term->colors.default_table[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DBG("resetting color #%u", idx);
|
|
||||||
term->colors.table[idx] = term->colors.default_table[idx];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render_refresh(term);
|
render_refresh(term);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue