summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2008-06-23 07:41:21 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2008-06-23 07:41:21 +0000
commitc24d849fa41114108b52a0a5e9256a7f0558b0d8 (patch)
tree93dbcffb22bbddf9181fbc3e89d93d8e36bb6afd
parente013970b0b0b44bf871233cffcf5ca77ce700e2e (diff)
Split options into a table to allow abbreviations.
-rw-r--r--CHANGES9
-rw-r--r--TODO2
-rw-r--r--cmd-send-prefix.c9
-rw-r--r--cmd-set-option.c417
-rw-r--r--cmd-show-options.c64
-rw-r--r--cmd.c8
-rw-r--r--options.c63
-rw-r--r--server.c4
-rw-r--r--status.c4
-rw-r--r--tmux.c6
-rw-r--r--tmux.h30
11 files changed, 331 insertions, 285 deletions
diff --git a/CHANGES b/CHANGES
index 0c245e14..6d048909 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,10 @@
+23 June 2008
+
+* Split information about options into a table and use it to parse options
+ on input (allowing abbreviations) and to print them with show-options
+ (meaning that bell-action gets a proper string). This turned out a bit ugly
+ though :-/.
+
22 June 2008
* Do not translate black and white into default if the terminal supports
@@ -550,4 +557,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.136 2008-06-22 16:54:08 nicm Exp $
+$Id: CHANGES,v 1.137 2008-06-23 07:41:20 nicm Exp $
diff --git a/TODO b/TODO
index 5833a87d..14ceaa4b 100644
--- a/TODO
+++ b/TODO
@@ -70,7 +70,6 @@
session not being watched?
- tidy up window modes
- support \033_string\033\\ for window title too
-- fix bell-action in show-options
- list-keys should be sorted
- document buffer stuff
- copy-mode enhancements: next word etc etc
@@ -78,6 +77,7 @@
- command history for command-prompt. better tab completion
- options parsing could be much more generic, opening the way for abbreviation
and tab completion of option names
+- split status-colour into fg/bg
---
save-buffer -b number filename
load-buffer -b number filename
diff --git a/cmd-send-prefix.c b/cmd-send-prefix.c
index 5751a44b..bcc82c3c 100644
--- a/cmd-send-prefix.c
+++ b/cmd-send-prefix.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-send-prefix.c,v 1.17 2008-06-20 17:31:48 nicm Exp $ */
+/* $Id: cmd-send-prefix.c,v 1.18 2008-06-23 07:41:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -45,12 +45,13 @@ cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
struct cmd_target_data *data = self->data;
struct session *s;
struct winlink *wl;
+ int key;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return;
-
- window_key(
- wl->window, ctx->curclient, options_get_key(&s->options, "prefix"));
+
+ key = options_get_number(&s->options, "prefix");
+ window_key(wl->window, ctx->curclient, key);
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
diff --git a/cmd-set-option.c b/cmd-set-option.c
index 501a94ff..80190fcc 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-set-option.c,v 1.34 2008-06-20 18:45:35 nicm Exp $ */
+/* $Id: cmd-set-option.c,v 1.35 2008-06-23 07:41:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -55,6 +55,39 @@ const struct cmd_entry cmd_set_option_entry = {
cmd_set_option_print
};
+const char *set_option_bell_action_choices[] = { "none", "any", "current" };
+const struct set_option_entry set_option_table[NSETOPTION] = {
+ { "bell-action",
+ SET_OPTION_CHOICE, NULL, 0, 0, set_option_bell_action_choices },
+ { "buffer-limit", SET_OPTION_NUMBER, NULL, 1, INT_MAX, NULL },
+ { "default-command", SET_OPTION_STRING, NULL, 0, 0, NULL },
+ { "display-time", SET_OPTION_NUMBER, NULL, 1, INT_MAX, NULL },
+ { "history-limit", SET_OPTION_NUMBER, NULL, 0, SHRT_MAX, NULL },
+ { "prefix", SET_OPTION_KEY, NULL, 0, 0, NULL },
+ { "set-titles", SET_OPTION_FLAG, NULL, 0, 0, NULL },
+ { "status", SET_OPTION_FLAG, NULL, 0, 0, NULL },
+ { "status-bg", SET_OPTION_BG,"status-colour", 0, 0, NULL },
+ { "status-fg", SET_OPTION_FG,"status-colour", 0, 0, NULL },
+ { "status-interval", SET_OPTION_NUMBER, NULL, 0, INT_MAX, NULL },
+ { "status-left", SET_OPTION_STRING, NULL, 0, 0, NULL },
+ { "status-right", SET_OPTION_STRING, NULL, 0, 0, NULL },
+};
+
+void set_option_string(struct cmd_ctx *, struct options *,
+ const struct set_option_entry *, const char *, char *);
+void set_option_number(struct cmd_ctx *, struct options *,
+ const struct set_option_entry *, const char *, char *);
+void set_option_key(struct cmd_ctx *, struct options *,
+ const struct set_option_entry *, const char *, char *);
+void set_option_fg(struct cmd_ctx *, struct options *,
+ const struct set_option_entry *, const char *, char *);
+void set_option_bg(struct cmd_ctx *, struct options *,
+ const struct set_option_entry *, const char *, char *);
+void set_option_flag(struct cmd_ctx *, struct options *,
+ const struct set_option_entry *, const char *, char *);
+void set_option_choice(struct cmd_ctx *, struct options *,
+ const struct set_option_entry *, const char *, char *);
+
int
cmd_set_option_parse(struct cmd *self, int argc, char **argv, char **cause)
{
@@ -97,16 +130,15 @@ usage:
}
void
-cmd_set_option_exec(struct cmd *self, unused struct cmd_ctx *ctx)
+cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_set_option_data *data = self->data;
- struct client *c;
struct session *s;
+ struct client *c;
struct options *oo;
- const char *errstr;
+ const struct set_option_entry *entry;
+ const char *option;
u_int i;
- int number, flag, key;
- u_char colour;
if (data == NULL)
return;
@@ -122,203 +154,218 @@ cmd_set_option_exec(struct cmd *self, unused struct cmd_ctx *ctx)
return;
}
- number = -1;
- if (data->value != NULL) {
- number = strtonum(data->value, 0, INT_MAX, &errstr);
- if (errstr != NULL)
- number = 0;
-
- flag = -1;
- if (number == 1 || strcasecmp(data->value, "on") == 0 ||
- strcasecmp(data->value, "yes") == 0)
- flag = 1;
- else if (number == 0 || strcasecmp(data->value, "off") == 0 ||
- strcasecmp(data->value, "no") == 0)
- flag = 0;
- } else
- flag = -2;
-
- if (strcmp(data->option, "prefix") == 0) {
- if (data->value == NULL) {
- ctx->error(ctx, "invalid value");
- return;
- }
- key = key_string_lookup_string(data->value);
- if (key == KEYC_NONE) {
- ctx->error(ctx, "unknown key: %s", data->value);
- return;
- }
- options_set_key(oo, "prefix", key);
- } else if (strcmp(data->option, "status") == 0) {
- if (flag == -1) {
- ctx->error(ctx, "bad value: %s", data->value);
- return;
- }
- if (flag == -2)
- flag = !options_get_number(oo, "status");
- options_set_number(oo, "status", flag);
- recalculate_sizes();
- } else if (strcmp(data->option, "status-fg") == 0) {
- if (data->value == NULL) {
- ctx->error(ctx, "invalid value");
- return;
- }
- number = screen_stringcolour(data->value);
- if (number > 8) {
- ctx->error(ctx, "bad colour: %s", data->value);
+ entry = NULL;
+ for (i = 0; i < NSETOPTION; i++) {
+ if (strncmp(set_option_table[i].name,
+ data->option, strlen(data->option)) != 0)
+ continue;
+ if (entry != NULL) {
+ ctx->error(ctx, "ambiguous option: %s", data->option);
return;
}
+ entry = &set_option_table[i];
- colour = options_get_colours(oo, "status-colour");
- colour &= 0x0f;
- colour |= number << 4;
- options_set_colours(oo, "status-colour", colour);
+ }
+ if (entry == NULL) {
+ ctx->error(ctx, "unknown option: %s", data->option);
+ return;
+ }
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL && c->session != NULL)
- server_redraw_client(c);
- }
- } else if (strcmp(data->option, "status-bg") == 0) {
- if (data->value == NULL) {
- ctx->error(ctx, "invalid value");
- return;
- }
- number = screen_stringcolour(data->value);
- if (number > 8) {
- ctx->error(ctx, "bad colour: %s", data->value);
- return;
- }
+ option = entry->name;
+ if (entry->option != NULL)
+ option = entry->option;
+
+ switch (entry->type) {
+ case SET_OPTION_STRING:
+ set_option_string(ctx, oo, entry, option, data->value);
+ break;
+ case SET_OPTION_NUMBER:
+ set_option_number(ctx, oo, entry, option, data->value);
+ break;
+ case SET_OPTION_KEY:
+ set_option_key(ctx, oo, entry, option, data->value);
+ break;
+ case SET_OPTION_FG:
+ set_option_fg(ctx, oo, entry, option, data->value);
+ break;
+ case SET_OPTION_BG:
+ set_option_bg(ctx, oo, entry, option, data->value);
+ break;
+ case SET_OPTION_FLAG:
+ set_option_flag(ctx, oo, entry, option, data->value);
+ break;
+ case SET_OPTION_CHOICE:
+ set_option_choice(ctx, oo, entry, option, data->value);
+ break;
+ }
- colour = options_get_colours(oo, "status-colour");
- colour &= 0xf0;
- colour |= number;
- options_set_colours(oo, "status-colour", colour);
+ recalculate_sizes();
+ for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
+ c = ARRAY_ITEM(&clients, i);
+ if (c != NULL && c->session != NULL)
+ server_redraw_client(c);
+ }
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL && c->session != NULL)
- server_redraw_client(c);
- }
- } else if (strcmp(data->option, "bell-action") == 0) {
- if (data->value == NULL) {
- ctx->error(ctx, "invalid value");
- return;
- }
- if (strcmp(data->value, "any") == 0)
- number = BELL_ANY;
- else if (strcmp(data->value, "none") == 0)
- number = BELL_NONE;
- else if (strcmp(data->value, "current") == 0)
- number = BELL_CURRENT;
+ if (ctx->cmdclient != NULL)
+ server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+}
+
+void
+set_option_string(struct cmd_ctx *ctx, struct options *oo,
+ unused const struct set_option_entry *entry,
+ const char *option, char *value)
+{
+ if (value == NULL) {
+ ctx->error(ctx, "empty value");
+ return;
+ }
+
+ options_set_string(oo, option, "%s", value);
+}
+
+void
+set_option_number(struct cmd_ctx *ctx, struct options *oo,
+ const struct set_option_entry *entry, const char *option, char *value)
+{
+ long long number;
+ const char *errstr;
+
+ if (value == NULL) {
+ ctx->error(ctx, "empty value");
+ return;
+ }
+
+ number = strtonum(value, entry->minimum, entry->maximum, &errstr);
+ if (errstr != NULL) {
+ ctx->error(ctx, "value is %s: %s", errstr, value);
+ return;
+ }
+ options_set_number(oo, option, number);
+}
+
+void
+set_option_key(struct cmd_ctx *ctx, struct options *oo,
+ unused const struct set_option_entry *entry,
+ const char *option, char *value)
+{
+ int key;
+
+ if (value == NULL) {
+ ctx->error(ctx, "empty value");
+ return;
+ }
+
+ if ((key = key_string_lookup_string(value)) == KEYC_NONE) {
+ ctx->error(ctx, "unknown key: %s", value);
+ return;
+ }
+ options_set_number(oo, option, key);
+
+}
+
+void
+set_option_fg(struct cmd_ctx *ctx, struct options *oo,
+ unused const struct set_option_entry *entry,
+ const char *option, char *value)
+{
+ u_char number, colour;
+
+ if (value == NULL) {
+ ctx->error(ctx, "empty value");
+ return;
+ }
+
+ if ((number = screen_stringcolour(value)) > 8) {
+ ctx->error(ctx, "bad colour: %s", value);
+ return;
+ }
+
+ colour = options_get_number(oo, option);
+ colour &= 0x0f;
+ colour |= number << 4;
+ options_set_number(oo, option, colour);
+}
+
+void
+set_option_bg(struct cmd_ctx *ctx, struct options *oo,
+ unused const struct set_option_entry *entry,
+ const char *option, char *value)
+{
+ u_char number, colour;
+
+ if (value == NULL) {
+ ctx->error(ctx, "empty value");
+ return;
+ }
+
+ if ((number = screen_stringcolour(value)) > 8) {
+ ctx->error(ctx, "bad colour: %s", value);
+ return;
+ }
+
+ colour = options_get_number(oo, option);
+ colour &= 0xf0;
+ colour |= number;
+ options_set_number(oo, option, colour);
+}
+
+void
+set_option_flag(struct cmd_ctx *ctx, struct options *oo,
+ unused const struct set_option_entry *entry,
+ const char *option, char *value)
+{
+ int flag;
+
+ if (value == NULL || *value == '\0')
+ flag = !options_get_number(oo, option);
+ else {
+ if ((value[0] == '1' && value[1] == '\0') ||
+ strcasecmp(value, "on") == 0 ||
+ strcasecmp(value, "yes") == 0)
+ flag = 1;
+ else if ((value[0] == '0' && value[1] == '\0') ||
+ strcasecmp(value, "off") == 0 ||
+ strcasecmp(value, "no") == 0)
+ flag = 0;
else {
- ctx->error(ctx, "unknown bell-action: %s", data->value);
- return;
- }
- options_set_number(oo, "bell-action", number);
- } else if (strcmp(data->option, "default-command") == 0) {
- if (data->value == NULL) {
- ctx->error(ctx, "invalid value");
- return;
- }
- options_set_string(oo, "default-command", "%s", data->value);
- } else if (strcmp(data->option, "history-limit") == 0) {
- if (data->value == NULL || number == -1) {
- ctx->error(ctx, "invalid value");
- return;
- }
- if (errstr != NULL) {
- ctx->error(ctx, "history-limit %s", errstr);
- return;
- }
- if (number > SHRT_MAX) {
- ctx->error(ctx, "history-limit too big: %u", number);
- return;
- }
- options_set_number(oo, "history-limit", number);
- } else if (strcmp(data->option, "display-time") == 0) {
- if (data->value == NULL || number == -1) {
- ctx->error(ctx, "invalid value");
- return;
- }
- if (errstr != NULL) {
- ctx->error(ctx, "display-time %s", errstr);
- return;
- }
- if (number > INT_MAX) {
- ctx->error(ctx, "display-time too big: %u", number);
- return;
- }
- options_set_number(oo, "display-time", number);
- } else if (strcmp(data->option, "buffer-limit") == 0) {
- if (data->value == NULL || number == -1) {
- ctx->error(ctx, "invalid value");
- return;
- }
- if (errstr != NULL) {
- ctx->error(ctx, "buffer-limit %s", errstr);
- return;
- }
- if (number == 0) {
- ctx->error(ctx, "zero buffer-limit");
- return;
- }
- if (number > INT_MAX) {
- ctx->error(ctx, "buffer-limit too big: %u", number);
- return;
- }
- options_set_number(oo, "buffer-limit", number);
- } else if (strcmp(data->option, "status-left") == 0) {
- if (data->value == NULL) {
- ctx->error(ctx, "invalid value");
+ ctx->error(ctx, "bad value: %s", value);
return;
}
+ }
- options_set_string(oo, "status-left", "%s", data->value);
+ options_set_number(oo, option, flag);
+}
+
+void
+set_option_choice(struct cmd_ctx *ctx, struct options *oo,
+ const struct set_option_entry *entry, const char *option, char *value)
+{
+ const char **choicep;
+ int n, choice = -1;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL && c->session != NULL)
- server_redraw_client(c);
- }
- } else if (strcmp(data->option, "status-right") == 0) {
- if (data->value == NULL) {
- ctx->error(ctx, "invalid value");
- return;
- }
+ if (value == NULL) {
+ ctx->error(ctx, "empty value");
+ return;
+ }
- options_set_string(oo, "status-right", "%s", data->value);
+ n = 0;
+ for (choicep = entry->choices; *choicep != NULL; choicep++) {
+ n++;
+ if (strncmp(*choicep, value, strlen(value)) != 0)
+ continue;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL && c->session != NULL)
- server_redraw_client(c);
- }
- } else if (strcmp(data->option, "status-interval") == 0) {
- if (data->value == NULL || number == -1) {
- ctx->error(ctx, "invalid value");
+ if (choice != -1) {
+ ctx->error(ctx, "ambiguous option: %s", value);
return;
}
- if (errstr != NULL) {
- ctx->error(ctx, "status-interval %s", errstr);
- return;
- }
- options_set_number(oo, "status-interval", number);
- } else if (strcmp(data->option, "set-titles") == 0) {
- if (flag == -1) {
- ctx->error(ctx, "bad value: %s", data->value);
- return;
- }
- if (flag == -2)
- flag = !options_get_number(oo, "set-titles");
- options_set_number(oo, "set-titles", flag);
- } else {
- ctx->error(ctx, "unknown option: %s", data->option);
+ choice = n - 1;
+ }
+ if (choice == -1) {
+ ctx->error(ctx, "unknown option: %s", value);
return;
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ options_set_number(oo, option, choice);
}
void
diff --git a/cmd-show-options.c b/cmd-show-options.c
index 439730f2..439a524a 100644
--- a/cmd-show-options.c
+++ b/cmd-show-options.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-show-options.c,v 1.3 2008-06-18 22:21:51 nicm Exp $ */
+/* $Id: cmd-show-options.c,v 1.4 2008-06-23 07:41:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -98,7 +98,11 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
struct cmd_show_options_data *data = self->data;
struct session *s;
struct options *oo;
- struct options_entry *o;
+ const struct set_option_entry *entry;
+ const char *option;
+ u_int i;
+ char *vs;
+ long long vn;
if (data == NULL)
return;
@@ -109,23 +113,51 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
else
oo = &s->options;
- SPLAY_FOREACH(o, options_tree, &oo->tree) {
- switch (o->type) {
- case OPTIONS_STRING:
- ctx->print(
- ctx, "%s \"%s\"", o->name, o->value.string);
+ for (i = 0; i < NSETOPTION; i++) {
+ entry = &set_option_table[i];
+
+ option = entry->name;
+ if (entry->option != NULL)
+ option = entry->option;
+
+ if (options_find1(oo, option) == NULL)
+ continue;
+
+ switch (entry->type) {
+ case SET_OPTION_STRING:
+ vs = options_get_string(oo, option);
+ ctx->print(ctx, "%s \"%s\"", entry->name, vs);
+ break;
+ case SET_OPTION_NUMBER:
+ vn = options_get_number(oo, option);
+ ctx->print(ctx, "%s %lld", entry->name, vn);
+ break;
+ case SET_OPTION_KEY:
+ vn = options_get_number(oo, option);
+ ctx->print(ctx, "%s %s",
+ entry->name, key_string_lookup_key(vn));
+ break;
+ case SET_OPTION_FG:
+ vn = options_get_number(oo, option);
+ ctx->print(ctx, "%s %s",
+ entry->name, screen_colourstring(vn >> 4));
break;
- case OPTIONS_NUMBER:
- ctx->print(ctx, "%s %lld", o->name, o->value.number);
+ case SET_OPTION_BG:
+ vn = options_get_number(oo, option);
+ ctx->print(ctx, "%s %s",
+ entry->name, screen_colourstring(vn & 0x0f));
break;
- case OPTIONS_KEY:
- ctx->print(ctx, "%s %s", o->name,
- key_string_lookup_key(o->value.key));
+ case SET_OPTION_FLAG:
+ vn = options_get_number(oo, option);
+ if (vn)
+ ctx->print(ctx, "%s on", option);
+ else
+ ctx->print(ctx, "%s off", option);
break;
- case OPTIONS_COLOURS:
- ctx->print(ctx, "%s fg=%s, bg=%s", o->name,
- screen_colourstring(o->value.colours >> 4),
- screen_colourstring(o->value.colours & 0x0f));
+ case SET_OPTION_CHOICE:
+ vn = options_get_number(oo, option);
+ ctx->print(ctx, "%s %s",
+ entry->name, entry->choices[vn]);
break;
}
}
diff --git a/cmd.c b/cmd.c
index 26c36b72..e7c9e810 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,4 +1,4 @@
-/* $Id: cmd.c,v 1.54 2008-06-21 14:16:30 nicm Exp $ */
+/* $Id: cmd.c,v 1.55 2008-06-23 07:41:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -75,7 +75,7 @@ cmd_complete(const char *s)
{
const struct cmd_entry **entryp;
ARRAY_DECL(, const char *) list;
- char *prefix;
+ char *prefix, *s2;
u_int i;
size_t j;
@@ -98,9 +98,9 @@ cmd_complete(const char *s)
/* If an exact match, return it, with a trailing space. */
if (ARRAY_LENGTH(&list) == 1) {
- xasprintf(&s, "%s ", ARRAY_FIRST(&list));
+ xasprintf(&s2, "%s ", ARRAY_FIRST(&list));
ARRAY_FREE(&list);
- return (s);
+ return (s2);
}
/* Now loop through the list and find the longest common prefix. */
diff --git a/options.c b/options.c
index 24b3f759..63ff6e4f 100644
--- a/options.c
+++ b/options.c
@@ -1,4 +1,4 @@
-/* $Id: options.c,v 1.2 2008-06-15 08:01:54 nicm Exp $ */
+/* $Id: options.c,v 1.3 2008-06-23 07:41:21 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -30,9 +30,6 @@
SPLAY_GENERATE(options_tree, options_entry, entry, options_cmp);
-struct options_entry *options_find1(struct options *, const char *);
-struct options_entry *options_find(struct options *, const char *);
-
int
options_cmp(struct options_entry *o1, struct options_entry *o2)
{
@@ -145,61 +142,3 @@ options_get_number(struct options *oo, const char *name)
fatalx("option not a number");
return (o->value.number);
}
-
-void
-options_set_key(struct options *oo, const char *name, int value)
-{
- struct options_entry *o;
-
- if ((o = options_find1(oo, name)) == NULL) {
- o = xmalloc(sizeof *o);
- o->name = xstrdup(name);
- SPLAY_INSERT(options_tree, &oo->tree, o);
- } else if (o->type == OPTIONS_STRING)
- xfree(o->value.string);
-
- o->type = OPTIONS_KEY;
- o->value.key = value;
-
-}
-
-int
-options_get_key(struct options *oo, const char *name)
-{
- struct options_entry *o;
-
- if ((o = options_find(oo, name)) == NULL)
- fatalx("missing option");
- if (o->type != OPTIONS_KEY)
- fatalx("option not a key");
- return (o->value.key);
-}
-
-void
-options_set_colours(struct options *oo, const char *name, u_char value)
-{
- struct options_entry *o;
-
- if ((o = options_find1(oo, name)) == NULL) {
- o = xmalloc(sizeof *o);
- o->name = xstrdup(name);
- SPLAY_INSERT(options_tree, &oo->tree, o);
- } else if (o->type == OPTIONS_STRING)
- xfree(o->value.string);
-
- o->type = OPTIONS_COLOURS;
- o->value.colours = value;
-
-}
-
-u_char
-options_get_colours(struct options *oo, const char *name)
-{
- struct options_entry *o;
-
- if ((o = options_find(oo, name)) == NULL)
- fatalx("missing option");
- if (o->type != OPTIONS_COLOURS)
- fatalx("option not a colours");
- return (o->value.colours);
-}
diff --git a/server.c b/server.c
index f5349c5a..8e596299 100644
--- a/server.c
+++ b/server.c
@@ -1,4 +1,4 @@
-/* $Id: server.c,v 1.75 2008-06-22 16:56:47 nicm Exp $ */
+/* $Id: server.c,v 1.76 2008-06-23 07:41:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -527,7 +527,7 @@ server_handle_client(struct client *c)
struct window *w = c->session->curw->window;
int key, prefix;
- prefix = options_get_key(&c->session->options, "prefix");
+ prefix = options_get_number(&c->session->options, "prefix");
while (tty_keys_next(&c->tty, &key) == 0) {
server_clear_client_message(c);
if (c->prompt_string != NULL) {
diff --git a/status.c b/status.c
index 72f6060a..0aaea394 100644
--- a/status.c
+++ b/status.c
@@ -1,4 +1,4 @@
-/* $Id: status.c,v 1.37 2008-06-21 14:11:39 nicm Exp $ */
+/* $Id: status.c,v 1.38 2008-06-23 07:41:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -48,7 +48,7 @@ status_redraw(struct client *c)
if (clock_gettime(CLOCK_REALTIME, &c->status_timer) != 0)
fatal("clock_gettime failed");
- colr = options_get_colours(&s->options, "status-colour");
+ colr = options_get_number(&s->options, "status-colour");
yy = c->sy - 1;
if (yy == 0)
diff --git a/tmux.c b/tmux.c
index baef9dc5..b9e6e2fc 100644
--- a/tmux.c
+++ b/tmux.c
@@ -1,4 +1,4 @@
-/* $Id: tmux.c,v 1.66 2008-06-20 18:45:35 nicm Exp $ */
+/* $Id: tmux.c,v 1.67 2008-06-23 07:41:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -210,11 +210,11 @@ main(int argc, char **argv)
options_init(&global_options, NULL);
options_set_number(&global_options, "status", 1);
- options_set_colours(&global_options, "status-colour", 0x02);
+ options_set_number(&global_options, "status-colour", 0x02);
options_set_number(&global_options, "bell-action", BELL_ANY);
options_set_number(&global_options, "history-limit", 2000);
options_set_number(&global_options, "display-time", 750);
- options_set_key(&global_options, "prefix", META);
+ options_set_number(&global_options, "prefix", META);
options_set_string(&global_options, "status-left", "%s", ""); /* ugh */
options_set_string(
&global_options, "status-right", "%%H:%%M %%d-%%b-%%y");
diff --git a/tmux.h b/tmux.h
index c175b15f..0543cb6b 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.164 2008-06-22 22:20:07 nicm Exp $ */
+/* $Id: tmux.h,v 1.165 2008-06-23 07:41:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -793,6 +793,28 @@ struct binding {
};
ARRAY_DECL(bindings, struct binding *);
+/* Set/display option data. */
+struct set_option_entry {
+ const char *name;
+ enum {
+ SET_OPTION_STRING,
+ SET_OPTION_NUMBER,
+ SET_OPTION_KEY,
+ SET_OPTION_FG,
+ SET_OPTION_BG,
+ SET_OPTION_FLAG,
+ SET_OPTION_CHOICE
+ } type;
+ const char *option;
+
+ u_int minimum;
+ u_int maximum;
+
+ const char **choices;
+};
+extern const struct set_option_entry set_option_table[];
+#define NSETOPTION 13
+
#ifdef NO_STRTONUM
/* strtonum.c */
long long strtonum(const char *, long long, long long, const char **);
@@ -848,15 +870,13 @@ int options_cmp(struct options_entry *, struct options_entry *);
SPLAY_PROTOTYPE(options_tree, options_entry, entry, options_cmp);
void options_init(struct options *, struct options *);
void options_free(struct options *);
+struct options_entry *options_find1(struct options *, const char *);
+struct options_entry *options_find(struct options *, const char *);
void printflike3 options_set_string(
struct options *, const char *, const char *, ...);
char *options_get_string(struct options *, const char *);
void options_set_number(struct options *, const char *, long long);
long long options_get_number(struct options *, const char *);
-void options_set_key(struct options *, const char *, int);
-int options_get_key(struct options *, const char *);
-void options_set_colours(struct options *, const char *, u_char);
-u_char options_get_colours(struct options *, const char *);
/* tty.c */
void tty_init(struct tty *, char *, char *);