Split internal status-colour into status-fg/status-bg options and lose workarounds in set-option stuff.

This commit is contained in:
Nicholas Marriott 2008-06-23 22:12:29 +00:00
parent e704d6aee2
commit b69f4a3312
6 changed files with 70 additions and 121 deletions

1
TODO
View File

@ -77,7 +77,6 @@
- command history for command-prompt. better tab completion - command history for command-prompt. better tab completion
- options parsing could be much more generic, opening the way for abbreviation - options parsing could be much more generic, opening the way for abbreviation
and tab completion of option names and tab completion of option names
- split status-colour into fg/bg
--- ---
save-buffer -b number filename save-buffer -b number filename
load-buffer -b number filename load-buffer -b number filename

View File

@ -1,4 +1,4 @@
/* $Id: cmd-set-option.c,v 1.35 2008-06-23 07:41:21 nicm Exp $ */ /* $Id: cmd-set-option.c,v 1.36 2008-06-23 22:12:29 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -58,35 +58,33 @@ const struct cmd_entry cmd_set_option_entry = {
const char *set_option_bell_action_choices[] = { "none", "any", "current" }; const char *set_option_bell_action_choices[] = { "none", "any", "current" };
const struct set_option_entry set_option_table[NSETOPTION] = { const struct set_option_entry set_option_table[NSETOPTION] = {
{ "bell-action", { "bell-action",
SET_OPTION_CHOICE, NULL, 0, 0, set_option_bell_action_choices }, SET_OPTION_CHOICE, 0, 0, set_option_bell_action_choices },
{ "buffer-limit", SET_OPTION_NUMBER, NULL, 1, INT_MAX, NULL }, { "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
{ "default-command", SET_OPTION_STRING, NULL, 0, 0, NULL }, { "default-command", SET_OPTION_STRING, 0, 0, NULL },
{ "display-time", SET_OPTION_NUMBER, NULL, 1, INT_MAX, NULL }, { "display-time", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
{ "history-limit", SET_OPTION_NUMBER, NULL, 0, SHRT_MAX, NULL }, { "history-limit", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
{ "prefix", SET_OPTION_KEY, NULL, 0, 0, NULL }, { "prefix", SET_OPTION_KEY, 0, 0, NULL },
{ "set-titles", SET_OPTION_FLAG, NULL, 0, 0, NULL }, { "set-titles", SET_OPTION_FLAG, 0, 0, NULL },
{ "status", SET_OPTION_FLAG, NULL, 0, 0, NULL }, { "status", SET_OPTION_FLAG, 0, 0, NULL },
{ "status-bg", SET_OPTION_BG,"status-colour", 0, 0, NULL }, { "status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
{ "status-fg", SET_OPTION_FG,"status-colour", 0, 0, NULL }, { "status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
{ "status-interval", SET_OPTION_NUMBER, NULL, 0, INT_MAX, NULL }, { "status-interval", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
{ "status-left", SET_OPTION_STRING, NULL, 0, 0, NULL }, { "status-left", SET_OPTION_STRING, 0, 0, NULL },
{ "status-right", SET_OPTION_STRING, NULL, 0, 0, NULL }, { "status-right", SET_OPTION_STRING, 0, 0, NULL },
}; };
void set_option_string(struct cmd_ctx *, struct options *, void set_option_string(struct cmd_ctx *,
const struct set_option_entry *, const char *, char *); struct options *, const struct set_option_entry *, char *);
void set_option_number(struct cmd_ctx *, struct options *, void set_option_number(struct cmd_ctx *,
const struct set_option_entry *, const char *, char *); struct options *, const struct set_option_entry *, char *);
void set_option_key(struct cmd_ctx *, struct options *, void set_option_key(struct cmd_ctx *,
const struct set_option_entry *, const char *, char *); struct options *, const struct set_option_entry *, char *);
void set_option_fg(struct cmd_ctx *, struct options *, void set_option_colour(struct cmd_ctx *,
const struct set_option_entry *, const char *, char *); struct options *, const struct set_option_entry *, char *);
void set_option_bg(struct cmd_ctx *, struct options *, void set_option_flag(struct cmd_ctx *,
const struct set_option_entry *, const char *, char *); struct options *, const struct set_option_entry *, char *);
void set_option_flag(struct cmd_ctx *, struct options *, void set_option_choice(struct cmd_ctx *,
const struct set_option_entry *, const char *, char *); struct options *, const struct set_option_entry *, char *);
void set_option_choice(struct cmd_ctx *, struct options *,
const struct set_option_entry *, const char *, char *);
int int
cmd_set_option_parse(struct cmd *self, int argc, char **argv, char **cause) cmd_set_option_parse(struct cmd *self, int argc, char **argv, char **cause)
@ -137,7 +135,6 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
struct client *c; struct client *c;
struct options *oo; struct options *oo;
const struct set_option_entry *entry; const struct set_option_entry *entry;
const char *option;
u_int i; u_int i;
if (data == NULL) if (data == NULL)
@ -171,31 +168,24 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
return; return;
} }
option = entry->name;
if (entry->option != NULL)
option = entry->option;
switch (entry->type) { switch (entry->type) {
case SET_OPTION_STRING: case SET_OPTION_STRING:
set_option_string(ctx, oo, entry, option, data->value); set_option_string(ctx, oo, entry, data->value);
break; break;
case SET_OPTION_NUMBER: case SET_OPTION_NUMBER:
set_option_number(ctx, oo, entry, option, data->value); set_option_number(ctx, oo, entry, data->value);
break; break;
case SET_OPTION_KEY: case SET_OPTION_KEY:
set_option_key(ctx, oo, entry, option, data->value); set_option_key(ctx, oo, entry, data->value);
break; break;
case SET_OPTION_FG: case SET_OPTION_COLOUR:
set_option_fg(ctx, oo, entry, option, data->value); set_option_colour(ctx, oo, entry, data->value);
break;
case SET_OPTION_BG:
set_option_bg(ctx, oo, entry, option, data->value);
break; break;
case SET_OPTION_FLAG: case SET_OPTION_FLAG:
set_option_flag(ctx, oo, entry, option, data->value); set_option_flag(ctx, oo, entry, data->value);
break; break;
case SET_OPTION_CHOICE: case SET_OPTION_CHOICE:
set_option_choice(ctx, oo, entry, option, data->value); set_option_choice(ctx, oo, entry, data->value);
break; break;
} }
@ -212,20 +202,19 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
void void
set_option_string(struct cmd_ctx *ctx, struct options *oo, set_option_string(struct cmd_ctx *ctx, struct options *oo,
unused const struct set_option_entry *entry, const struct set_option_entry *entry, char *value)
const char *option, char *value)
{ {
if (value == NULL) { if (value == NULL) {
ctx->error(ctx, "empty value"); ctx->error(ctx, "empty value");
return; return;
} }
options_set_string(oo, option, "%s", value); options_set_string(oo, entry->name, "%s", value);
} }
void void
set_option_number(struct cmd_ctx *ctx, struct options *oo, set_option_number(struct cmd_ctx *ctx, struct options *oo,
const struct set_option_entry *entry, const char *option, char *value) const struct set_option_entry *entry, char *value)
{ {
long long number; long long number;
const char *errstr; const char *errstr;
@ -240,13 +229,12 @@ set_option_number(struct cmd_ctx *ctx, struct options *oo,
ctx->error(ctx, "value is %s: %s", errstr, value); ctx->error(ctx, "value is %s: %s", errstr, value);
return; return;
} }
options_set_number(oo, option, number); options_set_number(oo, entry->name, number);
} }
void void
set_option_key(struct cmd_ctx *ctx, struct options *oo, set_option_key(struct cmd_ctx *ctx, struct options *oo,
unused const struct set_option_entry *entry, const struct set_option_entry *entry, char *value)
const char *option, char *value)
{ {
int key; int key;
@ -259,65 +247,37 @@ set_option_key(struct cmd_ctx *ctx, struct options *oo,
ctx->error(ctx, "unknown key: %s", value); ctx->error(ctx, "unknown key: %s", value);
return; return;
} }
options_set_number(oo, option, key); options_set_number(oo, entry->name, key);
} }
void void
set_option_fg(struct cmd_ctx *ctx, struct options *oo, set_option_colour(struct cmd_ctx *ctx, struct options *oo,
unused const struct set_option_entry *entry, const struct set_option_entry *entry, char *value)
const char *option, char *value)
{ {
u_char number, colour; u_char colour;
if (value == NULL) { if (value == NULL) {
ctx->error(ctx, "empty value"); ctx->error(ctx, "empty value");
return; return;
} }
if ((number = screen_stringcolour(value)) > 8) { if ((colour = screen_stringcolour(value)) > 8) {
ctx->error(ctx, "bad colour: %s", value); ctx->error(ctx, "bad colour: %s", value);
return; return;
} }
colour = options_get_number(oo, option); options_set_number(oo, entry->name, colour);
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 void
set_option_flag(struct cmd_ctx *ctx, struct options *oo, set_option_flag(struct cmd_ctx *ctx, struct options *oo,
unused const struct set_option_entry *entry, const struct set_option_entry *entry, char *value)
const char *option, char *value)
{ {
int flag; int flag;
if (value == NULL || *value == '\0') if (value == NULL || *value == '\0')
flag = !options_get_number(oo, option); flag = !options_get_number(oo, entry->name);
else { else {
if ((value[0] == '1' && value[1] == '\0') || if ((value[0] == '1' && value[1] == '\0') ||
strcasecmp(value, "on") == 0 || strcasecmp(value, "on") == 0 ||
@ -333,12 +293,12 @@ set_option_flag(struct cmd_ctx *ctx, struct options *oo,
} }
} }
options_set_number(oo, option, flag); options_set_number(oo, entry->name, flag);
} }
void void
set_option_choice(struct cmd_ctx *ctx, struct options *oo, set_option_choice(struct cmd_ctx *ctx, struct options *oo,
const struct set_option_entry *entry, const char *option, char *value) const struct set_option_entry *entry, char *value)
{ {
const char **choicep; const char **choicep;
int n, choice = -1; int n, choice = -1;
@ -365,7 +325,7 @@ set_option_choice(struct cmd_ctx *ctx, struct options *oo,
return; return;
} }
options_set_number(oo, option, choice); options_set_number(oo, entry->name, choice);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-show-options.c,v 1.4 2008-06-23 07:41:21 nicm Exp $ */ /* $Id: cmd-show-options.c,v 1.5 2008-06-23 22:12:29 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -99,7 +99,6 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
struct session *s; struct session *s;
struct options *oo; struct options *oo;
const struct set_option_entry *entry; const struct set_option_entry *entry;
const char *option;
u_int i; u_int i;
char *vs; char *vs;
long long vn; long long vn;
@ -116,46 +115,37 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
for (i = 0; i < NSETOPTION; i++) { for (i = 0; i < NSETOPTION; i++) {
entry = &set_option_table[i]; entry = &set_option_table[i];
option = entry->name; if (options_find1(oo, entry->name) == NULL)
if (entry->option != NULL)
option = entry->option;
if (options_find1(oo, option) == NULL)
continue; continue;
switch (entry->type) { switch (entry->type) {
case SET_OPTION_STRING: case SET_OPTION_STRING:
vs = options_get_string(oo, option); vs = options_get_string(oo, entry->name);
ctx->print(ctx, "%s \"%s\"", entry->name, vs); ctx->print(ctx, "%s \"%s\"", entry->name, vs);
break; break;
case SET_OPTION_NUMBER: case SET_OPTION_NUMBER:
vn = options_get_number(oo, option); vn = options_get_number(oo, entry->name);
ctx->print(ctx, "%s %lld", entry->name, vn); ctx->print(ctx, "%s %lld", entry->name, vn);
break; break;
case SET_OPTION_KEY: case SET_OPTION_KEY:
vn = options_get_number(oo, option); vn = options_get_number(oo, entry->name);
ctx->print(ctx, "%s %s", ctx->print(ctx, "%s %s",
entry->name, key_string_lookup_key(vn)); entry->name, key_string_lookup_key(vn));
break; break;
case SET_OPTION_FG: case SET_OPTION_COLOUR:
vn = options_get_number(oo, option); vn = options_get_number(oo, entry->name);
ctx->print(ctx, "%s %s", ctx->print(ctx, "%s %s",
entry->name, screen_colourstring(vn >> 4)); entry->name, screen_colourstring(vn));
break;
case SET_OPTION_BG:
vn = options_get_number(oo, option);
ctx->print(ctx, "%s %s",
entry->name, screen_colourstring(vn & 0x0f));
break; break;
case SET_OPTION_FLAG: case SET_OPTION_FLAG:
vn = options_get_number(oo, option); vn = options_get_number(oo, entry->name);
if (vn) if (vn)
ctx->print(ctx, "%s on", option); ctx->print(ctx, "%s on", entry->name);
else else
ctx->print(ctx, "%s off", option); ctx->print(ctx, "%s off", entry->name);
break; break;
case SET_OPTION_CHOICE: case SET_OPTION_CHOICE:
vn = options_get_number(oo, option); vn = options_get_number(oo, entry->name);
ctx->print(ctx, "%s %s", ctx->print(ctx, "%s %s",
entry->name, entry->choices[vn]); entry->name, entry->choices[vn]);
break; break;

View File

@ -1,4 +1,4 @@
/* $Id: status.c,v 1.40 2008-06-23 21:54:48 nicm Exp $ */ /* $Id: status.c,v 1.41 2008-06-23 22:12:29 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -48,7 +48,8 @@ status_redraw(struct client *c)
if (clock_gettime(CLOCK_REALTIME, &c->status_timer) != 0) if (clock_gettime(CLOCK_REALTIME, &c->status_timer) != 0)
fatal("clock_gettime failed"); fatal("clock_gettime failed");
colr = options_get_number(&s->options, "status-colour"); colr = options_get_number(&s->options, "status-bg") +
(options_get_number(&s->options, "status-fg") << 4);
yy = c->sy - 1; yy = c->sy - 1;
if (yy == 0) if (yy == 0)

5
tmux.c
View File

@ -1,4 +1,4 @@
/* $Id: tmux.c,v 1.68 2008-06-23 16:58:49 nicm Exp $ */ /* $Id: tmux.c,v 1.69 2008-06-23 22:12:29 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -210,7 +210,8 @@ main(int argc, char **argv)
options_init(&global_options, NULL); options_init(&global_options, NULL);
options_set_number(&global_options, "status", 1); options_set_number(&global_options, "status", 1);
options_set_number(&global_options, "status-colour", 0x02); options_set_number(&global_options, "status-fg", 0);
options_set_number(&global_options, "status-bg", 2);
options_set_number(&global_options, "bell-action", BELL_ANY); options_set_number(&global_options, "bell-action", BELL_ANY);
options_set_number(&global_options, "history-limit", 2000); options_set_number(&global_options, "history-limit", 2000);
options_set_number(&global_options, "display-time", 750); options_set_number(&global_options, "display-time", 750);

6
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.165 2008-06-23 07:41:21 nicm Exp $ */ /* $Id: tmux.h,v 1.166 2008-06-23 22:12:29 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -800,12 +800,10 @@ struct set_option_entry {
SET_OPTION_STRING, SET_OPTION_STRING,
SET_OPTION_NUMBER, SET_OPTION_NUMBER,
SET_OPTION_KEY, SET_OPTION_KEY,
SET_OPTION_FG, SET_OPTION_COLOUR,
SET_OPTION_BG,
SET_OPTION_FLAG, SET_OPTION_FLAG,
SET_OPTION_CHOICE SET_OPTION_CHOICE
} type; } type;
const char *option;
u_int minimum; u_int minimum;
u_int maximum; u_int maximum;