aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-04-04 12:32:02 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-04-04 12:32:02 +0000
commit6d7c686a3cb1671c9cdc3bb1e2f29fdc0e7db0c0 (patch)
tree7a491e32c7ad9e31dd8a9e194a1f04777eb10d12
parentreadme: tweak presentation of OSC 555 (diff)
parentchangelog: osc 4 multiple 'c;spec' pairs (diff)
Merge branch 'osc4-multi-parameter'
-rw-r--r--CHANGELOG.md1
-rw-r--r--osc.c94
2 files changed, 48 insertions, 47 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0299d3b8..a064dc21 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -46,6 +46,7 @@
* Restored cursor position in 'normal' screen when window was resized
while in 'alt' screen.
* Hostname in OSC 7 URI not being validated.
+* OSC 4 with multiple `c;spec` pairs.
### Security
diff --git a/osc.c b/osc.c
index 8fa1c07b..98de86f7 100644
--- a/osc.c
+++ b/osc.c
@@ -430,47 +430,48 @@ osc_dispatch(struct terminal *term)
case 4: {
/* Set color<idx> */
- /* First param - the color index */
- unsigned idx = 0;
- for (; *string != '\0' && *string != ';'; string++) {
- char c = *string;
- idx *= 10;
- idx += c - '0';
- }
+ string--;
+ assert(*string == ';');
- if (idx >= 256)
- break;
+ for (const char *s_idx = strtok(string, ";"), *s_color = strtok(NULL, ";");
+ s_idx != NULL && s_color != NULL;
+ s_idx = strtok(NULL, ";"), s_color = strtok(NULL, ";"))
+ {
+ /* Parse <idx> parameter */
+ unsigned idx = 0;
+ for (; *s_idx != '\0'; s_idx++) {
+ char c = *s_idx;
+ idx *= 10;
+ idx += c - '0';
+ }
- /* Next follows the color specification. For now, we only support rgb:x/y/z */
+ /* Client queried for current value */
+ if (strlen(s_color) == 1 && s_color[0] == '?') {
+ uint32_t color = term->colors.table[idx];
+ uint8_t r = (color >> 16) & 0xff;
+ uint8_t g = (color >> 8) & 0xff;
+ uint8_t b = (color >> 0) & 0xff;
- if (*string == '\0') {
- /* No color specification */
- break;
- }
+ 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));
+ }
- assert(*string == ';');
- string++;
+ else {
+ uint32_t color;
+ bool color_is_valid = s_color[0] == '#'
+ ? parse_legacy_color(s_color, &color)
+ : parse_rgb(s_color, &color);
- /* Client queried for current value */
- if (strlen(string) == 1 && string[0] == '?') {
- uint32_t color = term->colors.table[idx];
- uint8_t r = (color >> 16) & 0xff;
- uint8_t g = (color >> 8) & 0xff;
- uint8_t b = (color >> 0) & 0xff;
+ if (!color_is_valid)
+ continue;
- 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));
- break;
+ 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);
break;
}
@@ -558,24 +559,23 @@ osc_dispatch(struct terminal *term)
LOG_DBG("resetting all colors");
for (size_t i = 0; i < 256; i++)
term->colors.table[i] = term->colors.default_table[i];
- } else {
- unsigned idx = 0;
+ }
- for (; *string != '\0'; string++) {
- char c = *string;
- if (c == ';') {
- LOG_DBG("resetting color #%u", idx);
- term->colors.table[idx] = term->colors.default_table[idx];
- idx = 0;
- continue;
+ else {
+ for (const char *s_idx = strtok(string, ";");
+ s_idx != NULL;
+ s_idx = strtok(NULL, ";"))
+ {
+ unsigned idx = 0;
+ for (; *s_idx != '\0'; s_idx++) {
+ char c = *s_idx;
+ idx *= 10;
+ idx += c - '0';
}
- idx *= 10;
- idx += c - '0';
+ LOG_DBG("resetting color #%u", idx);
+ 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);