diff options
author | nicm <nicm> | 2023-08-17 14:10:28 +0000 |
---|---|---|
committer | nicm <nicm> | 2023-08-17 14:10:28 +0000 |
commit | 8636848e6348bb0e38cd6aaaadbe61e15181bc8f (patch) | |
tree | e9967f79f8a2060093ab0a1ca0a3ce6e3fe744f7 /style.c | |
parent | d9942c769eb059e2cadfb63f2050fad8d0357d19 (diff) |
Add a session, pane and user mouse range types for the status line and
add format variables for mouse_status_line and mouse_status_range so
they can be associated with different commands in the key bindings.
GitHub issue 3652.
Diffstat (limited to 'style.c')
-rw-r--r-- | style.c | 64 |
1 files changed, 58 insertions, 6 deletions
@@ -37,11 +37,18 @@ static struct style style_default = { STYLE_ALIGN_DEFAULT, STYLE_LIST_OFF, - STYLE_RANGE_NONE, 0, + STYLE_RANGE_NONE, 0, "", STYLE_DEFAULT_BASE }; +/* Set range string. */ +static void +style_set_range_string(struct style *sy, const char *s) +{ + strlcpy(sy->range_string, s, sizeof sy->range_string); +} + /* * Parse an embedded style of the form "fg=colour,bg=colour,bright,...". Note * that this adds onto the given style, so it must have been initialized @@ -104,32 +111,67 @@ style_parse(struct style *sy, const struct grid_cell *base, const char *in) } else if (strcasecmp(tmp, "norange") == 0) { sy->range_type = style_default.range_type; sy->range_argument = style_default.range_type; + strlcpy(sy->range_string, style_default.range_string, + sizeof sy->range_string); } else if (end > 6 && strncasecmp(tmp, "range=", 6) == 0) { found = strchr(tmp + 6, '|'); if (found != NULL) { *found++ = '\0'; if (*found == '\0') goto error; - for (cp = found; *cp != '\0'; cp++) { - if (!isdigit((u_char)*cp)) - goto error; - } } if (strcasecmp(tmp + 6, "left") == 0) { if (found != NULL) goto error; sy->range_type = STYLE_RANGE_LEFT; sy->range_argument = 0; + style_set_range_string(sy, ""); } else if (strcasecmp(tmp + 6, "right") == 0) { if (found != NULL) goto error; sy->range_type = STYLE_RANGE_RIGHT; sy->range_argument = 0; + style_set_range_string(sy, ""); + } else if (strcasecmp(tmp + 6, "pane") == 0) { + if (found == NULL) + goto error; + if (*found != '%' || found[1] == '\0') + goto error; + for (cp = found + 1; *cp != '\0'; cp++) { + if (!isdigit((u_char)*cp)) + goto error; + } + sy->range_type = STYLE_RANGE_PANE; + sy->range_argument = atoi(found + 1); + style_set_range_string(sy, ""); } else if (strcasecmp(tmp + 6, "window") == 0) { if (found == NULL) goto error; + for (cp = found; *cp != '\0'; cp++) { + if (!isdigit((u_char)*cp)) + goto error; + } sy->range_type = STYLE_RANGE_WINDOW; sy->range_argument = atoi(found); + style_set_range_string(sy, ""); + } else if (strcasecmp(tmp + 6, "session") == 0) { + if (found == NULL) + goto error; + if (*found != '$' || found[1] == '\0') + goto error; + for (cp = found + 1; *cp != '\0'; cp++) { + if (!isdigit((u_char)*cp)) + goto error; + } + sy->range_type = STYLE_RANGE_SESSION; + sy->range_argument = atoi(found + 1); + style_set_range_string(sy, ""); + } else if (strcasecmp(tmp + 6, "user") == 0) { + if (found == NULL) + goto error; + sy->range_type = STYLE_RANGE_USER; + sy->range_argument = 0; + style_set_range_string(sy, found); } } else if (strcasecmp(tmp, "noalign") == 0) sy->align = style_default.align; @@ -222,9 +264,19 @@ style_tostring(struct style *sy) tmp = "left"; else if (sy->range_type == STYLE_RANGE_RIGHT) tmp = "right"; - else if (sy->range_type == STYLE_RANGE_WINDOW) { + else if (sy->range_type == STYLE_RANGE_PANE) { + snprintf(b, sizeof b, "pane|%%%u", sy->range_argument); + tmp = b; + } else if (sy->range_type == STYLE_RANGE_WINDOW) { snprintf(b, sizeof b, "window|%u", sy->range_argument); tmp = b; + } else if (sy->range_type == STYLE_RANGE_SESSION) { + snprintf(b, sizeof b, "session|$%u", + sy->range_argument); + tmp = b; + } else if (sy->range_type == STYLE_RANGE_USER) { + snprintf(b, sizeof b, "user|%s", sy->range_string); + tmp = b; } off += xsnprintf(s + off, sizeof s - off, "%srange=%s", comma, tmp); |