mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Split internal status-colour into status-fg/status-bg options and lose workarounds in set-option stuff.
This commit is contained in:
parent
e704d6aee2
commit
b69f4a3312
1
TODO
1
TODO
@ -77,7 +77,6 @@
|
||||
- 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
|
||||
|
138
cmd-set-option.c
138
cmd-set-option.c
@ -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>
|
||||
@ -58,35 +58,33 @@ const struct cmd_entry cmd_set_option_entry = {
|
||||
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 },
|
||||
SET_OPTION_CHOICE, 0, 0, set_option_bell_action_choices },
|
||||
{ "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||
{ "default-command", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "display-time", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||
{ "history-limit", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
|
||||
{ "prefix", SET_OPTION_KEY, 0, 0, NULL },
|
||||
{ "set-titles", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "status", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "status-interval", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||
{ "status-left", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "status-right", SET_OPTION_STRING, 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 *);
|
||||
void set_option_string(struct cmd_ctx *,
|
||||
struct options *, const struct set_option_entry *, char *);
|
||||
void set_option_number(struct cmd_ctx *,
|
||||
struct options *, const struct set_option_entry *, char *);
|
||||
void set_option_key(struct cmd_ctx *,
|
||||
struct options *, const struct set_option_entry *, char *);
|
||||
void set_option_colour(struct cmd_ctx *,
|
||||
struct options *, const struct set_option_entry *, char *);
|
||||
void set_option_flag(struct cmd_ctx *,
|
||||
struct options *, const struct set_option_entry *, char *);
|
||||
void set_option_choice(struct cmd_ctx *,
|
||||
struct options *, const struct set_option_entry *, char *);
|
||||
|
||||
int
|
||||
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 options *oo;
|
||||
const struct set_option_entry *entry;
|
||||
const char *option;
|
||||
u_int i;
|
||||
|
||||
if (data == NULL)
|
||||
@ -171,31 +168,24 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
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);
|
||||
set_option_string(ctx, oo, entry, data->value);
|
||||
break;
|
||||
case SET_OPTION_NUMBER:
|
||||
set_option_number(ctx, oo, entry, option, data->value);
|
||||
set_option_number(ctx, oo, entry, data->value);
|
||||
break;
|
||||
case SET_OPTION_KEY:
|
||||
set_option_key(ctx, oo, entry, option, data->value);
|
||||
set_option_key(ctx, oo, entry, 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);
|
||||
case SET_OPTION_COLOUR:
|
||||
set_option_colour(ctx, oo, entry, data->value);
|
||||
break;
|
||||
case SET_OPTION_FLAG:
|
||||
set_option_flag(ctx, oo, entry, option, data->value);
|
||||
set_option_flag(ctx, oo, entry, data->value);
|
||||
break;
|
||||
case SET_OPTION_CHOICE:
|
||||
set_option_choice(ctx, oo, entry, option, data->value);
|
||||
set_option_choice(ctx, oo, entry, data->value);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -212,20 +202,19 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
void
|
||||
set_option_string(struct cmd_ctx *ctx, struct options *oo,
|
||||
unused const struct set_option_entry *entry,
|
||||
const char *option, char *value)
|
||||
const struct set_option_entry *entry, char *value)
|
||||
{
|
||||
if (value == NULL) {
|
||||
ctx->error(ctx, "empty value");
|
||||
return;
|
||||
}
|
||||
|
||||
options_set_string(oo, option, "%s", value);
|
||||
options_set_string(oo, entry->name, "%s", value);
|
||||
}
|
||||
|
||||
void
|
||||
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;
|
||||
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);
|
||||
return;
|
||||
}
|
||||
options_set_number(oo, option, number);
|
||||
options_set_number(oo, entry->name, number);
|
||||
}
|
||||
|
||||
void
|
||||
set_option_key(struct cmd_ctx *ctx, struct options *oo,
|
||||
unused const struct set_option_entry *entry,
|
||||
const char *option, char *value)
|
||||
const struct set_option_entry *entry, char *value)
|
||||
{
|
||||
int key;
|
||||
|
||||
@ -259,65 +247,37 @@ set_option_key(struct cmd_ctx *ctx, struct options *oo,
|
||||
ctx->error(ctx, "unknown key: %s", value);
|
||||
return;
|
||||
}
|
||||
options_set_number(oo, option, key);
|
||||
options_set_number(oo, entry->name, key);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
set_option_fg(struct cmd_ctx *ctx, struct options *oo,
|
||||
unused const struct set_option_entry *entry,
|
||||
const char *option, char *value)
|
||||
set_option_colour(struct cmd_ctx *ctx, struct options *oo,
|
||||
const struct set_option_entry *entry, char *value)
|
||||
{
|
||||
u_char number, colour;
|
||||
u_char colour;
|
||||
|
||||
if (value == NULL) {
|
||||
ctx->error(ctx, "empty value");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((number = screen_stringcolour(value)) > 8) {
|
||||
if ((colour = 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);
|
||||
options_set_number(oo, entry->name, colour);
|
||||
}
|
||||
|
||||
void
|
||||
set_option_flag(struct cmd_ctx *ctx, struct options *oo,
|
||||
unused const struct set_option_entry *entry,
|
||||
const char *option, char *value)
|
||||
const struct set_option_entry *entry, char *value)
|
||||
{
|
||||
int flag;
|
||||
|
||||
if (value == NULL || *value == '\0')
|
||||
flag = !options_get_number(oo, option);
|
||||
flag = !options_get_number(oo, entry->name);
|
||||
else {
|
||||
if ((value[0] == '1' && value[1] == '\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
|
||||
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;
|
||||
int n, choice = -1;
|
||||
@ -365,7 +325,7 @@ set_option_choice(struct cmd_ctx *ctx, struct options *oo,
|
||||
return;
|
||||
}
|
||||
|
||||
options_set_number(oo, option, choice);
|
||||
options_set_number(oo, entry->name, choice);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -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>
|
||||
@ -99,7 +99,6 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct session *s;
|
||||
struct options *oo;
|
||||
const struct set_option_entry *entry;
|
||||
const char *option;
|
||||
u_int i;
|
||||
char *vs;
|
||||
long long vn;
|
||||
@ -116,46 +115,37 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
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)
|
||||
if (options_find1(oo, entry->name) == NULL)
|
||||
continue;
|
||||
|
||||
switch (entry->type) {
|
||||
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);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
case SET_OPTION_KEY:
|
||||
vn = options_get_number(oo, option);
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, key_string_lookup_key(vn));
|
||||
break;
|
||||
case SET_OPTION_FG:
|
||||
vn = options_get_number(oo, option);
|
||||
case SET_OPTION_COLOUR:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, screen_colourstring(vn >> 4));
|
||||
break;
|
||||
case SET_OPTION_BG:
|
||||
vn = options_get_number(oo, option);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, screen_colourstring(vn & 0x0f));
|
||||
entry->name, screen_colourstring(vn));
|
||||
break;
|
||||
case SET_OPTION_FLAG:
|
||||
vn = options_get_number(oo, option);
|
||||
vn = options_get_number(oo, entry->name);
|
||||
if (vn)
|
||||
ctx->print(ctx, "%s on", option);
|
||||
ctx->print(ctx, "%s on", entry->name);
|
||||
else
|
||||
ctx->print(ctx, "%s off", option);
|
||||
ctx->print(ctx, "%s off", entry->name);
|
||||
break;
|
||||
case SET_OPTION_CHOICE:
|
||||
vn = options_get_number(oo, option);
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, entry->choices[vn]);
|
||||
break;
|
||||
|
5
status.c
5
status.c
@ -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>
|
||||
@ -48,7 +48,8 @@ status_redraw(struct client *c)
|
||||
|
||||
if (clock_gettime(CLOCK_REALTIME, &c->status_timer) != 0)
|
||||
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;
|
||||
if (yy == 0)
|
||||
|
5
tmux.c
5
tmux.c
@ -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>
|
||||
@ -210,7 +210,8 @@ main(int argc, char **argv)
|
||||
|
||||
options_init(&global_options, NULL);
|
||||
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, "history-limit", 2000);
|
||||
options_set_number(&global_options, "display-time", 750);
|
||||
|
8
tmux.h
8
tmux.h
@ -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>
|
||||
@ -800,13 +800,11 @@ struct set_option_entry {
|
||||
SET_OPTION_STRING,
|
||||
SET_OPTION_NUMBER,
|
||||
SET_OPTION_KEY,
|
||||
SET_OPTION_FG,
|
||||
SET_OPTION_BG,
|
||||
SET_OPTION_COLOUR,
|
||||
SET_OPTION_FLAG,
|
||||
SET_OPTION_CHOICE
|
||||
} type;
|
||||
const char *option;
|
||||
|
||||
|
||||
u_int minimum;
|
||||
u_int maximum;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user