Add "server options" which are server-wide and not bound to a session or

window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.
pull/1/head
Nicholas Marriott 2009-12-10 09:16:52 +00:00
parent 6311bd119e
commit a4c9a80dac
8 changed files with 86 additions and 43 deletions

View File

@ -70,8 +70,8 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
tim = ctime(&start_time);
*strchr(tim, '\n') = '\0';
ctx->print(ctx, "pid %ld, started %s", (long) getpid(), tim);
ctx->print(ctx, "socket path %s, debug level %d%s",
socket_path, debug_level, be_quiet ? ", quiet" : "");
ctx->print(
ctx, "socket path %s, debug level %d", socket_path, debug_level);
if (uname(&un) == 0) {
ctx->print(ctx, "system is %s %s %s %s",
un.sysname, un.release, un.version, un.machine);

View File

@ -48,8 +48,8 @@ void cmd_set_option_choice(struct cmd_ctx *,
const struct cmd_entry cmd_set_option_entry = {
"set-option", "set",
"[-aguw] [-t target-session|target-window] option [value]",
CMD_ARG12, "aguw",
"[-agsuw] [-t target-session|target-window] option [value]",
CMD_ARG12, "agsuw",
NULL,
cmd_target_parse,
cmd_set_option_exec,
@ -73,6 +73,10 @@ const char *set_option_bell_action_list[] = {
"none", "any", "current", NULL
};
const struct set_option_entry set_option_table[] = {
{ "quiet", SET_OPTION_FLAG, 0, 0, NULL },
};
const struct set_option_entry set_session_option_table[] = {
{ "base-index", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
{ "bell-action", SET_OPTION_CHOICE, 0, 0, set_option_bell_action_list },
@ -172,7 +176,10 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int i;
int try_again;
if (cmd_check_flag(data->chflags, 'w')) {
if (cmd_check_flag(data->chflags, 's')) {
oo = &global_options;
table = set_option_table;
} else if (cmd_check_flag(data->chflags, 'w')) {
table = set_window_option_table;
if (cmd_check_flag(data->chflags, 'g'))
oo = &global_w_options;

View File

@ -31,8 +31,8 @@ int cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_show_options_entry = {
"show-options", "show",
"[-gw] [-t target-session|target-window]",
0, "gw",
"[-gsw] [-t target-session|target-window]",
0, "gsw",
cmd_target_init,
cmd_target_parse,
cmd_show_options_exec,
@ -52,7 +52,10 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
const struct set_option_entry *entry;
const char *optval;
if (cmd_check_flag(data->chflags, 'w')) {
if (cmd_check_flag(data->chflags, 's')) {
oo = &global_options;
table = set_option_table;
} else if (cmd_check_flag(data->chflags, 'w')) {
table = set_window_option_table;
if (cmd_check_flag(data->chflags, 'g'))
oo = &global_w_options;

View File

@ -224,7 +224,7 @@ key_bindings_info(struct cmd_ctx *ctx, const char *fmt, ...)
va_list ap;
char *msg;
if (be_quiet)
if (options_get_number(&global_options, "quiet"))
return;
va_start(ap, fmt);

View File

@ -640,7 +640,7 @@ server_client_msg_info(struct cmd_ctx *ctx, const char *fmt, ...)
struct msg_print_data data;
va_list ap;
if (be_quiet)
if (options_get_number(&global_options, "quiet"))
return;
va_start(ap, fmt);

85
tmux.1
View File

@ -151,8 +151,9 @@ signal may be sent to the
.Nm
server process to recreate it.
.It Fl q
Prevent the server sending various informational messages, for example when
window flags are altered.
Set the
.Ic quiet
server option to prevent the server sending various informational messages.
.It Fl S Ar socket-path
Specify a full alternative path to the server socket.
If
@ -1209,13 +1210,26 @@ or for normal mode without.
The appearance and behaviour of
.Nm
may be modified by changing the value of various options.
There are two types of option:
There are three types of option:
.Em server options ,
.Em session options
and
.Em window options .
.Pp
Each individual session may have a set of session options, and there is a
separate set of global session options.
The
.Nm
server has a set of global options which do not apply to any particular
window or session.
These are altered with the
.Ic set-option
.Fl s
command, or displayed with the
.Ic show-options
.Fl s
command.
.Pp
In addition, each individual session may have a set of session options, and
there is a separate set of global session options.
Sessions which do not have a particular option configured inherit the value
from the global session options.
Session options are set or unset with the
@ -1223,7 +1237,7 @@ Session options are set or unset with the
command and may be listed with the
.Ic show-options
command.
The available session options are listed under the
The available server and session options are listed under the
.Ic set-option
command.
.Pp
@ -1241,31 +1255,44 @@ command.
Commands which set options are as follows:
.Bl -tag -width Ds
.It Xo Ic set-option
.Op Fl aguw
.Op Fl agsuw
.Op Fl t Ar target-session | Ar target-window
.Ar option Ar value
.Xc
.D1 (alias: Ic set )
Set a session option.
Set a window option with
.Fl w
(equivalent to the
.Ic set-window-option
command),
a server option with
.Fl s ,
otherwise a session option.
.Pp
If
.Fl g
is specified, the global session or window option is set.
With
.Fl a ,
and if the option expects a string,
.Ar value
is appended to the existing setting.
If
.Fl g
is specified, the global session option is set.
The
.Fl u
flag unsets an option, so a session inherits the option from the global
options - it is not possible to unset a global option.
options.
It is not possible to unset a global option.
.Pp
With
.Fl w ,
this command is equivalent to
.Ic set-window-option
with
.Ar target-window .
Available window options are listed under
.Ic set-window-option .
.Pp
Available server options are:
.Bl -tag -width Ds
.It Ic quiet
Enable of disable the display of various informational messages (see also the
.Fl q
command line flag).
.El
.Pp
Available session options are:
.Bl -tag -width Ds
@ -1850,21 +1877,21 @@ as Shift, Alt or Ctrl.
The default is off.
.El
.It Xo Ic show-options
.Op Fl gw
.Op Fl gsw
.Op Fl t Ar target-session | Ar target-window
.Xc
.D1 (alias: Ic show )
Show the session options for
.Ar target session ,
or the global session options with
.Fl g .
.Pp
If
Show the window options with
.Fl w
is used, this command is equivalent to
.Ic show-window-options
with
.Ar target-window .
(equivalent to
.Ic show-window-options ),
the server options with
.Fl s ,
otherwise the session options for
.Ar target session .
Global session or window options are listed if
.Fl g
is used.
.It Xo Ic show-window-options
.Op Fl g
.Op Fl t Ar target-window

12
tmux.c
View File

@ -36,12 +36,12 @@ extern char *malloc_options;
#endif
char *cfg_file;
struct options global_options; /* server options */
struct options global_s_options; /* session options */
struct options global_w_options; /* window options */
struct environ global_environ;
int debug_level;
int be_quiet;
time_t start_time;
char *socket_path;
int login_shell;
@ -222,14 +222,14 @@ main(int argc, char **argv)
struct cmd *cmd;
enum msgtype msg;
struct passwd *pw;
struct options *so, *wo;
struct options *oo, *so, *wo;
struct keylist *keylist;
struct msg_command_data cmddata;
char *s, *shellcmd, *path, *label, *home, *cause;
char cwd[MAXPATHLEN], **var;
void *buf;
size_t len;
int opt, flags, cmdflags = 0;
int opt, flags, quiet, cmdflags = 0;
short events;
#ifdef DEBUG
@ -268,7 +268,7 @@ main(int argc, char **argv)
label = xstrdup(optarg);
break;
case 'q':
be_quiet = 1;
quiet = 1;
break;
case 'S':
if (path != NULL)
@ -314,6 +314,10 @@ main(int argc, char **argv)
for (var = environ; *var != NULL; var++)
environ_put(&global_environ, *var);
options_init(&global_options, NULL);
oo = &global_options;
options_set_number(oo, "quiet", 0);
options_init(&global_s_options, NULL);
so = &global_s_options;
options_set_number(so, "base-index", 0);

2
tmux.h
View File

@ -1235,6 +1235,7 @@ struct set_option_entry {
};
/* tmux.c */
extern struct options global_options;
extern struct options global_s_options;
extern struct options global_w_options;
extern struct environ global_environ;
@ -1391,6 +1392,7 @@ extern const char clock_table[14][5][5];
void clock_draw(struct screen_write_ctx *, int, int);
/* cmd-set-option.c */
extern const struct set_option_entry set_option_table[];
extern const struct set_option_entry set_session_option_table[];
extern const struct set_option_entry set_window_option_table[];
const char *cmd_set_option_print(