diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-08-25 11:35:33 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-08-25 11:35:33 +0000 |
commit | 158072d60618b37d1a180094cc8bde54959e1335 (patch) | |
tree | 512be0c02cbc000109fae74c9b251a3670df5b18 /usr.bin/tmux | |
parent | 95da6db99b68b5abc9b2937b7ef941801c92c540 (diff) |
Allow colour to be spelt as color, from Boris Verkhovsky. GitHub issue
2317.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/colour.c | 8 | ||||
-rw-r--r-- | usr.bin/tmux/options-table.c | 10 | ||||
-rw-r--r-- | usr.bin/tmux/options.c | 44 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 11 |
4 files changed, 56 insertions, 17 deletions
diff --git a/usr.bin/tmux/colour.c b/usr.bin/tmux/colour.c index 09b6d9463a8..6f7b21e1baf 100644 --- a/usr.bin/tmux/colour.c +++ b/usr.bin/tmux/colour.c @@ -1,4 +1,4 @@ -/* $OpenBSD: colour.c,v 1.18 2019/06/27 15:17:41 nicm Exp $ */ +/* $OpenBSD: colour.c,v 1.19 2020/08/25 11:35:32 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -189,6 +189,12 @@ colour_fromstring(const char *s) return (-1); return (n | COLOUR_FLAG_256); } + if (strncasecmp(s, "color", (sizeof "color") - 1) == 0) { + n = strtonum(s + (sizeof "color") - 1, 0, 255, &errstr); + if (errstr != NULL) + return (-1); + return (n | COLOUR_FLAG_256); + } if (strcasecmp(s, "default") == 0) return (8); diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c index b54998c3d4c..fa8f453361a 100644 --- a/usr.bin/tmux/options-table.c +++ b/usr.bin/tmux/options-table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options-table.c,v 1.133 2020/07/24 07:05:37 nicm Exp $ */ +/* $OpenBSD: options-table.c,v 1.134 2020/08/25 11:35:32 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -171,6 +171,14 @@ static const char *options_table_status_format_default[] = { .separator = "" \ } +/* Map of name conversions. */ +const struct options_name_map options_other_names[] = { + { "display-panes-color", "display-panes-colour" }, + { "display-panes-active-color", "display-panes-active-colour" }, + { "clock-mode-color", "clock-mode-colour" }, + { NULL, NULL } +}; + /* Top-level options. */ const struct options_table_entry options_table[] = { /* Server options. */ diff --git a/usr.bin/tmux/options.c b/usr.bin/tmux/options.c index 273b3e8c795..4967915767f 100644 --- a/usr.bin/tmux/options.c +++ b/usr.bin/tmux/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.59 2020/06/16 08:18:34 nicm Exp $ */ +/* $OpenBSD: options.c,v 1.60 2020/08/25 11:35:32 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -95,6 +95,18 @@ options_cmp(struct options_entry *lhs, struct options_entry *rhs) return (strcmp(lhs->name, rhs->name)); } +static const char * +options_map_name(const char *name) +{ + const struct options_name_map *map; + + for (map = options_other_names; map->from != NULL; map++) { + if (strcmp(map->from, name) == 0) + return (map->to); + } + return (name); +} + static const struct options_table_entry * options_parent_table_entry(struct options *oo, const char *s) { @@ -204,10 +216,14 @@ options_next(struct options_entry *o) struct options_entry * options_get_only(struct options *oo, const char *name) { - struct options_entry o; + struct options_entry o = { .name = name }, *found; - o.name = name; - return (RB_FIND(options_tree, &oo->tree, &o)); + found = RB_FIND(options_tree, &oo->tree, &o); + if (found == NULL) { + o.name = options_map_name(name); + return (RB_FIND(options_tree, &oo->tree, &o)); + } + return (found); } struct options_entry * @@ -608,19 +624,21 @@ char * options_match(const char *s, int *idx, int *ambiguous) { const struct options_table_entry *oe, *found; - char *name; + char *parsed; + const char *name; size_t namelen; - name = options_parse(s, idx); - if (name == NULL) + parsed = options_parse(s, idx); + if (parsed == NULL) return (NULL); - namelen = strlen(name); - - if (*name == '@') { + if (*parsed == '@') { *ambiguous = 0; - return (name); + return (parsed); } + name = options_map_name(parsed); + namelen = strlen(name); + found = NULL; for (oe = options_table; oe->name != NULL; oe++) { if (strcmp(oe->name, name) == 0) { @@ -630,13 +648,13 @@ options_match(const char *s, int *idx, int *ambiguous) if (strncmp(oe->name, name, namelen) == 0) { if (found != NULL) { *ambiguous = 1; - free(name); + free(parsed); return (NULL); } found = oe; } } - free(name); + free(parsed); if (found == NULL) { *ambiguous = 0; return (NULL); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 3c2eaec3446..3ef2389f944 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1075 2020/07/27 08:03:10 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1076 2020/08/25 11:35:32 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1788,6 +1788,7 @@ enum options_table_type { struct options_table_entry { const char *name; + const char *alternative_name; enum options_table_type type; int scope; int flags; @@ -1807,6 +1808,11 @@ struct options_table_entry { const char *unit; }; +struct options_name_map { + const char *from; + const char *to; +}; + /* Common command usages. */ #define CMD_TARGET_PANE_USAGE "[-t target-pane]" #define CMD_TARGET_WINDOW_USAGE "[-t target-window]" @@ -2039,7 +2045,8 @@ int options_remove_or_default(struct options_entry *, int, char **); /* options-table.c */ -extern const struct options_table_entry options_table[]; +extern const struct options_table_entry options_table[]; +extern const struct options_name_map options_other_names[]; /* job.c */ typedef void (*job_update_cb) (struct job *); |