2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
#include <fnmatch.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set an option.
|
|
|
|
*/
|
|
|
|
|
2016-10-16 19:04:05 +00:00
|
|
|
static enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmdq_item *);
|
2013-03-21 16:17:01 +00:00
|
|
|
|
2017-01-15 20:48:41 +00:00
|
|
|
static int cmd_set_option_set(struct cmd *, struct cmdq_item *,
|
2017-01-16 14:49:14 +00:00
|
|
|
struct options *, struct options_entry *, const char *);
|
2017-01-15 20:48:41 +00:00
|
|
|
static int cmd_set_option_flag(struct cmdq_item *,
|
2016-10-10 21:51:39 +00:00
|
|
|
const struct options_table_entry *, struct options *,
|
|
|
|
const char *);
|
2017-01-15 20:48:41 +00:00
|
|
|
static int cmd_set_option_choice(struct cmdq_item *,
|
2016-10-10 21:51:39 +00:00
|
|
|
const struct options_table_entry *, struct options *,
|
|
|
|
const char *);
|
2011-01-01 16:51:21 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
const struct cmd_entry cmd_set_option_entry = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "set-option",
|
|
|
|
.alias = "set",
|
|
|
|
|
2019-06-20 11:59:59 +00:00
|
|
|
.args = { "aFgopqst:uw", 1, 2 },
|
|
|
|
.usage = "[-aFgopqsuw] " CMD_TARGET_PANE_USAGE " option [value]",
|
2015-12-13 21:53:57 +00:00
|
|
|
|
2019-06-20 11:59:59 +00:00
|
|
|
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
2015-12-14 00:31:54 +00:00
|
|
|
|
2016-10-14 22:14:22 +00:00
|
|
|
.flags = CMD_AFTERHOOK,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = cmd_set_option_exec
|
2009-06-01 22:58:49 +00:00
|
|
|
};
|
|
|
|
|
2011-01-04 02:03:41 +00:00
|
|
|
const struct cmd_entry cmd_set_window_option_entry = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "set-window-option",
|
|
|
|
.alias = "setw",
|
|
|
|
|
2017-05-10 13:05:41 +00:00
|
|
|
.args = { "aFgoqt:u", 1, 2 },
|
|
|
|
.usage = "[-aFgoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
2015-12-13 21:53:57 +00:00
|
|
|
|
2017-04-22 10:22:39 +00:00
|
|
|
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
2015-12-14 00:31:54 +00:00
|
|
|
|
2016-10-14 22:14:22 +00:00
|
|
|
.flags = CMD_AFTERHOOK,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = cmd_set_option_exec
|
2011-01-04 02:03:41 +00:00
|
|
|
};
|
|
|
|
|
2019-04-26 11:38:51 +00:00
|
|
|
const struct cmd_entry cmd_set_hook_entry = {
|
|
|
|
.name = "set-hook",
|
|
|
|
.alias = NULL,
|
|
|
|
|
|
|
|
.args = { "agRt:u", 1, 2 },
|
|
|
|
.usage = "[-agRu] " CMD_TARGET_SESSION_USAGE " hook [command]",
|
|
|
|
|
|
|
|
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
|
|
|
|
|
|
|
.flags = CMD_AFTERHOOK,
|
|
|
|
.exec = cmd_set_option_exec
|
|
|
|
};
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static enum cmd_retval
|
2016-10-16 19:04:05 +00:00
|
|
|
cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2017-01-15 20:48:41 +00:00
|
|
|
struct args *args = self->args;
|
2017-01-24 20:24:54 +00:00
|
|
|
int append = args_has(args, 'a');
|
2017-04-22 10:22:39 +00:00
|
|
|
struct cmd_find_state *fs = &item->target;
|
2017-05-10 13:05:41 +00:00
|
|
|
struct client *c, *loop;
|
2017-01-15 20:48:41 +00:00
|
|
|
struct session *s = fs->s;
|
|
|
|
struct winlink *wl = fs->wl;
|
2017-02-16 10:53:25 +00:00
|
|
|
struct window *w;
|
2019-06-20 11:59:59 +00:00
|
|
|
struct window_pane *wp;
|
2017-01-15 20:48:41 +00:00
|
|
|
struct options *oo;
|
2017-01-16 14:49:14 +00:00
|
|
|
struct options_entry *parent, *o;
|
2017-05-10 13:05:41 +00:00
|
|
|
char *name, *argument, *value = NULL, *cause;
|
2017-01-15 20:48:41 +00:00
|
|
|
int window, idx, already, error, ambiguous;
|
2019-06-20 11:59:59 +00:00
|
|
|
int scope;
|
2019-03-18 21:46:01 +00:00
|
|
|
struct style *sy;
|
2017-05-10 13:05:41 +00:00
|
|
|
|
2019-06-20 07:41:29 +00:00
|
|
|
window = (self->entry == &cmd_set_window_option_entry);
|
|
|
|
|
2017-05-10 13:05:41 +00:00
|
|
|
/* Expand argument. */
|
|
|
|
c = cmd_find_client(item, NULL, 1);
|
|
|
|
argument = format_single(item, args->argv[0], c, s, wl, NULL);
|
2017-01-15 20:48:41 +00:00
|
|
|
|
2019-06-20 07:41:29 +00:00
|
|
|
/* If set-hook -R, fire the hook straight away. */
|
2019-04-26 11:38:51 +00:00
|
|
|
if (self->entry == &cmd_set_hook_entry && args_has(args, 'R')) {
|
|
|
|
notify_hook(item, argument);
|
2019-06-20 07:41:29 +00:00
|
|
|
free(argument);
|
2019-04-26 11:38:51 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
}
|
|
|
|
|
2017-01-15 20:48:41 +00:00
|
|
|
/* Parse option name and index. */
|
2017-05-10 13:05:41 +00:00
|
|
|
name = options_match(argument, &idx, &ambiguous);
|
2017-01-15 20:48:41 +00:00
|
|
|
if (name == NULL) {
|
2017-01-15 20:50:34 +00:00
|
|
|
if (args_has(args, 'q'))
|
2017-05-10 13:05:41 +00:00
|
|
|
goto out;
|
2017-01-15 20:48:41 +00:00
|
|
|
if (ambiguous)
|
2017-05-10 13:05:41 +00:00
|
|
|
cmdq_error(item, "ambiguous option: %s", argument);
|
2017-01-15 20:48:41 +00:00
|
|
|
else
|
2017-05-10 13:05:41 +00:00
|
|
|
cmdq_error(item, "invalid option: %s", argument);
|
|
|
|
goto fail;
|
2011-03-29 21:09:13 +00:00
|
|
|
}
|
|
|
|
if (args->argc < 2)
|
2017-01-15 20:48:41 +00:00
|
|
|
value = NULL;
|
2017-05-10 13:05:41 +00:00
|
|
|
else if (args_has(args, 'F'))
|
|
|
|
value = format_single(item, args->argv[1], c, s, wl, NULL);
|
2011-03-29 21:09:13 +00:00
|
|
|
else
|
2017-05-10 13:05:41 +00:00
|
|
|
value = xstrdup(args->argv[1]);
|
2017-01-15 20:48:41 +00:00
|
|
|
|
2019-06-20 07:41:29 +00:00
|
|
|
/* Get the scope and table for the option .*/
|
|
|
|
scope = options_scope_from_name(args, window, name, fs, &oo, &cause);
|
2017-01-15 20:48:41 +00:00
|
|
|
if (scope == OPTIONS_TABLE_NONE) {
|
2017-01-15 20:50:34 +00:00
|
|
|
if (args_has(args, 'q'))
|
2017-05-10 13:05:41 +00:00
|
|
|
goto out;
|
2017-01-15 20:48:41 +00:00
|
|
|
cmdq_error(item, "%s", cause);
|
|
|
|
free(cause);
|
2017-04-22 06:13:30 +00:00
|
|
|
goto fail;
|
2011-03-29 21:09:13 +00:00
|
|
|
}
|
2017-01-15 20:48:41 +00:00
|
|
|
o = options_get_only(oo, name);
|
|
|
|
parent = options_get(oo, name);
|
|
|
|
|
|
|
|
/* Check that array options and indexes match up. */
|
2019-03-18 11:58:40 +00:00
|
|
|
if (idx != -1 && (*name == '@' || !options_isarray(parent))) {
|
|
|
|
cmdq_error(item, "not an array: %s", argument);
|
|
|
|
goto fail;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 20:48:41 +00:00
|
|
|
/* With -o, check this option is not already set. */
|
|
|
|
if (!args_has(args, 'u') && args_has(args, 'o')) {
|
|
|
|
if (idx == -1)
|
|
|
|
already = (o != NULL);
|
|
|
|
else {
|
|
|
|
if (o == NULL)
|
|
|
|
already = 0;
|
|
|
|
else
|
|
|
|
already = (options_array_get(o, idx) != NULL);
|
|
|
|
}
|
|
|
|
if (already) {
|
|
|
|
if (args_has(args, 'q'))
|
2017-05-10 13:05:41 +00:00
|
|
|
goto out;
|
|
|
|
cmdq_error(item, "already set: %s", argument);
|
2017-04-22 06:13:30 +00:00
|
|
|
goto fail;
|
2017-01-15 20:48:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Change the option. */
|
2011-01-04 00:42:46 +00:00
|
|
|
if (args_has(args, 'u')) {
|
2017-01-15 20:48:41 +00:00
|
|
|
if (o == NULL)
|
2017-09-07 13:18:44 +00:00
|
|
|
goto out;
|
2017-01-15 20:48:41 +00:00
|
|
|
if (idx == -1) {
|
2017-12-22 10:18:51 +00:00
|
|
|
if (*name == '@')
|
|
|
|
options_remove(o);
|
|
|
|
else if (oo == global_options ||
|
2017-01-15 20:48:41 +00:00
|
|
|
oo == global_s_options ||
|
|
|
|
oo == global_w_options)
|
|
|
|
options_default(oo, options_table_entry(o));
|
|
|
|
else
|
|
|
|
options_remove(o);
|
2019-04-26 11:38:51 +00:00
|
|
|
} else if (options_array_set(o, idx, NULL, 0, &cause) != 0) {
|
|
|
|
cmdq_error(item, "%s", cause);
|
|
|
|
free(cause);
|
|
|
|
goto fail;
|
|
|
|
}
|
2017-01-24 20:24:54 +00:00
|
|
|
} else if (*name == '@') {
|
|
|
|
if (value == NULL) {
|
|
|
|
cmdq_error(item, "empty value");
|
2017-04-22 06:13:30 +00:00
|
|
|
goto fail;
|
2017-01-24 20:24:54 +00:00
|
|
|
}
|
|
|
|
options_set_string(oo, name, append, "%s", value);
|
2019-03-18 11:58:40 +00:00
|
|
|
} else if (idx == -1 && !options_isarray(parent)) {
|
2017-01-15 20:48:41 +00:00
|
|
|
error = cmd_set_option_set(self, item, oo, parent, value);
|
|
|
|
if (error != 0)
|
2017-04-22 06:13:30 +00:00
|
|
|
goto fail;
|
2009-06-01 22:58:49 +00:00
|
|
|
} else {
|
2017-01-24 20:24:54 +00:00
|
|
|
if (value == NULL) {
|
|
|
|
cmdq_error(item, "empty value");
|
2017-04-22 06:13:30 +00:00
|
|
|
goto fail;
|
2017-01-24 20:24:54 +00:00
|
|
|
}
|
2017-01-15 20:48:41 +00:00
|
|
|
if (o == NULL)
|
|
|
|
o = options_empty(oo, options_table_entry(parent));
|
2017-01-25 23:50:51 +00:00
|
|
|
if (idx == -1) {
|
|
|
|
if (!append)
|
|
|
|
options_array_clear(o);
|
2019-04-26 11:38:51 +00:00
|
|
|
if (options_array_assign(o, value, &cause) != 0) {
|
|
|
|
cmdq_error(item, "%s", cause);
|
|
|
|
free(cause);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
} else if (options_array_set(o, idx, value, append,
|
|
|
|
&cause) != 0) {
|
|
|
|
cmdq_error(item, "%s", cause);
|
|
|
|
free(cause);
|
2017-04-22 06:13:30 +00:00
|
|
|
goto fail;
|
2017-01-15 20:48:41 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 14:56:44 +00:00
|
|
|
/* Update timers and so on for various options. */
|
2017-01-15 20:48:41 +00:00
|
|
|
if (strcmp(name, "automatic-rename") == 0) {
|
2015-04-22 15:30:11 +00:00
|
|
|
RB_FOREACH(w, windows, &windows) {
|
2016-11-04 18:56:25 +00:00
|
|
|
if (w->active == NULL)
|
|
|
|
continue;
|
2015-10-27 15:58:42 +00:00
|
|
|
if (options_get_number(w->options, "automatic-rename"))
|
2015-08-29 00:29:15 +00:00
|
|
|
w->active->flags |= PANE_CHANGED;
|
2012-04-08 06:47:26 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-15 20:48:41 +00:00
|
|
|
if (strcmp(name, "key-table") == 0) {
|
2017-05-10 13:05:41 +00:00
|
|
|
TAILQ_FOREACH(loop, &clients, entry)
|
|
|
|
server_client_set_key_table(loop, NULL);
|
2015-12-12 18:32:24 +00:00
|
|
|
}
|
2017-06-23 15:36:52 +00:00
|
|
|
if (strcmp(name, "user-keys") == 0) {
|
|
|
|
TAILQ_FOREACH(loop, &clients, entry) {
|
|
|
|
if (loop->tty.flags & TTY_OPENED)
|
|
|
|
tty_keys_build(&loop->tty);
|
|
|
|
}
|
|
|
|
}
|
2019-03-18 21:46:01 +00:00
|
|
|
if (strcmp(name, "status-fg") == 0 || strcmp(name, "status-bg") == 0) {
|
|
|
|
sy = options_get_style(oo, "status-style");
|
|
|
|
sy->gc.fg = options_get_number(oo, "status-fg");
|
|
|
|
sy->gc.bg = options_get_number(oo, "status-bg");
|
|
|
|
}
|
|
|
|
if (strcmp(name, "status-style") == 0) {
|
|
|
|
sy = options_get_style(oo, "status-style");
|
|
|
|
options_set_number(oo, "status-fg", sy->gc.fg);
|
|
|
|
options_set_number(oo, "status-bg", sy->gc.bg);
|
|
|
|
}
|
2017-01-15 20:48:41 +00:00
|
|
|
if (strcmp(name, "status") == 0 ||
|
|
|
|
strcmp(name, "status-interval") == 0)
|
2015-08-28 12:16:28 +00:00
|
|
|
status_timer_start_all();
|
2017-01-15 20:48:41 +00:00
|
|
|
if (strcmp(name, "monitor-silence") == 0)
|
2015-08-29 08:30:54 +00:00
|
|
|
alerts_reset_all();
|
2017-01-15 20:48:41 +00:00
|
|
|
if (strcmp(name, "window-style") == 0 ||
|
|
|
|
strcmp(name, "window-active-style") == 0) {
|
2019-06-20 11:59:59 +00:00
|
|
|
RB_FOREACH(wp, window_pane_tree, &all_window_panes)
|
|
|
|
wp->flags |= PANE_STYLECHANGED;
|
2016-05-30 09:50:20 +00:00
|
|
|
}
|
2017-01-15 20:48:41 +00:00
|
|
|
if (strcmp(name, "pane-border-status") == 0) {
|
2016-04-29 15:00:48 +00:00
|
|
|
RB_FOREACH(w, windows, &windows)
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
layout_fix_panes(w);
|
2016-04-29 15:00:48 +00:00
|
|
|
}
|
2017-05-31 17:56:48 +00:00
|
|
|
RB_FOREACH(s, sessions, &sessions)
|
2019-03-16 17:14:07 +00:00
|
|
|
status_update_cache(s);
|
2016-04-29 15:00:48 +00:00
|
|
|
|
2017-01-15 20:48:41 +00:00
|
|
|
/*
|
|
|
|
* Update sizes and redraw. May not always be necessary but do it
|
|
|
|
* anyway.
|
|
|
|
*/
|
2009-06-01 22:58:49 +00:00
|
|
|
recalculate_sizes();
|
2017-05-10 13:05:41 +00:00
|
|
|
TAILQ_FOREACH(loop, &clients, entry) {
|
|
|
|
if (loop->session != NULL)
|
|
|
|
server_redraw_client(loop);
|
2009-12-03 17:44:02 +00:00
|
|
|
}
|
2009-11-01 23:20:37 +00:00
|
|
|
|
2017-05-10 13:05:41 +00:00
|
|
|
out:
|
|
|
|
free(argument);
|
|
|
|
free(value);
|
2017-04-22 06:13:30 +00:00
|
|
|
free(name);
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2017-04-22 06:13:30 +00:00
|
|
|
|
|
|
|
fail:
|
2017-05-10 13:05:41 +00:00
|
|
|
free(argument);
|
|
|
|
free(value);
|
2017-04-22 06:13:30 +00:00
|
|
|
free(name);
|
|
|
|
return (CMD_RETURN_ERROR);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2009-12-03 17:44:02 +00:00
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static int
|
2017-01-15 20:48:41 +00:00
|
|
|
cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
|
2017-01-16 14:49:14 +00:00
|
|
|
struct options_entry *parent, const char *value)
|
2009-12-03 17:44:02 +00:00
|
|
|
{
|
2017-01-15 20:48:41 +00:00
|
|
|
const struct options_table_entry *oe;
|
|
|
|
struct args *args = self->args;
|
|
|
|
int append = args_has(args, 'a');
|
2017-01-16 14:49:14 +00:00
|
|
|
struct options_entry *o;
|
2017-01-15 20:48:41 +00:00
|
|
|
long long number;
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
const char *errstr, *new;
|
|
|
|
char *old;
|
2017-01-15 20:48:41 +00:00
|
|
|
key_code key;
|
|
|
|
|
|
|
|
oe = options_table_entry(parent);
|
|
|
|
if (value == NULL &&
|
|
|
|
oe->type != OPTIONS_TABLE_FLAG &&
|
|
|
|
oe->type != OPTIONS_TABLE_CHOICE) {
|
|
|
|
cmdq_error(item, "empty value");
|
2011-01-01 16:51:21 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (oe->type) {
|
|
|
|
case OPTIONS_TABLE_STRING:
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
old = xstrdup(options_get_string(oo, oe->name));
|
2017-01-15 20:48:41 +00:00
|
|
|
options_set_string(oo, oe->name, append, "%s", value);
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
new = options_get_string(oo, oe->name);
|
2020-03-17 11:10:12 +00:00
|
|
|
if (strcmp(oe->name, "default-shell") == 0 &&
|
|
|
|
!checkshell(new)) {
|
|
|
|
options_set_string(oo, oe->name, 0, "%s", old);
|
|
|
|
free(old);
|
|
|
|
cmdq_error(item, "not a suitable shell: %s", value);
|
|
|
|
return (-1);
|
|
|
|
}
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (oe->pattern != NULL && fnmatch(oe->pattern, new, 0) != 0) {
|
|
|
|
options_set_string(oo, oe->name, 0, "%s", old);
|
|
|
|
free(old);
|
|
|
|
cmdq_error(item, "value is invalid: %s", value);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
free(old);
|
2017-01-15 20:48:41 +00:00
|
|
|
return (0);
|
2011-01-01 16:51:21 +00:00
|
|
|
case OPTIONS_TABLE_NUMBER:
|
2017-01-15 20:48:41 +00:00
|
|
|
number = strtonum(value, oe->minimum, oe->maximum, &errstr);
|
|
|
|
if (errstr != NULL) {
|
|
|
|
cmdq_error(item, "value is %s: %s", errstr, value);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
options_set_number(oo, oe->name, number);
|
|
|
|
return (0);
|
2012-01-21 08:40:09 +00:00
|
|
|
case OPTIONS_TABLE_KEY:
|
2017-01-15 20:48:41 +00:00
|
|
|
key = key_string_lookup_string(value);
|
|
|
|
if (key == KEYC_UNKNOWN) {
|
|
|
|
cmdq_error(item, "bad key: %s", value);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
options_set_number(oo, oe->name, key);
|
|
|
|
return (0);
|
2011-01-01 16:51:21 +00:00
|
|
|
case OPTIONS_TABLE_COLOUR:
|
2017-01-15 20:48:41 +00:00
|
|
|
if ((number = colour_fromstring(value)) == -1) {
|
|
|
|
cmdq_error(item, "bad colour: %s", value);
|
|
|
|
return (-1);
|
|
|
|
}
|
2019-03-18 21:46:01 +00:00
|
|
|
options_set_number(oo, oe->name, number);
|
2017-01-15 20:48:41 +00:00
|
|
|
return (0);
|
2011-01-01 16:51:21 +00:00
|
|
|
case OPTIONS_TABLE_FLAG:
|
2017-01-15 20:48:41 +00:00
|
|
|
return (cmd_set_option_flag(item, oe, oo, value));
|
2011-01-01 16:51:21 +00:00
|
|
|
case OPTIONS_TABLE_CHOICE:
|
2017-01-15 20:48:41 +00:00
|
|
|
return (cmd_set_option_choice(item, oe, oo, value));
|
2014-01-28 23:07:09 +00:00
|
|
|
case OPTIONS_TABLE_STYLE:
|
2017-01-15 20:48:41 +00:00
|
|
|
o = options_set_style(oo, oe->name, append, value);
|
|
|
|
if (o == NULL) {
|
|
|
|
cmdq_error(item, "bad style: %s", value);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return (0);
|
2019-04-26 11:38:51 +00:00
|
|
|
case OPTIONS_TABLE_COMMAND:
|
|
|
|
break;
|
2011-01-01 16:51:21 +00:00
|
|
|
}
|
2017-01-15 20:48:41 +00:00
|
|
|
return (-1);
|
2011-01-01 16:51:21 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 20:48:41 +00:00
|
|
|
static int
|
|
|
|
cmd_set_option_flag(struct cmdq_item *item,
|
2014-04-17 14:45:49 +00:00
|
|
|
const struct options_table_entry *oe, struct options *oo,
|
|
|
|
const char *value)
|
2009-12-03 17:44:02 +00:00
|
|
|
{
|
2011-01-04 00:42:46 +00:00
|
|
|
int flag;
|
2009-12-03 17:44:02 +00:00
|
|
|
|
2011-01-04 00:42:46 +00:00
|
|
|
if (value == NULL || *value == '\0')
|
2011-01-01 16:51:21 +00:00
|
|
|
flag = !options_get_number(oo, oe->name);
|
2017-01-15 20:48:41 +00:00
|
|
|
else if (strcmp(value, "1") == 0 ||
|
|
|
|
strcasecmp(value, "on") == 0 ||
|
|
|
|
strcasecmp(value, "yes") == 0)
|
|
|
|
flag = 1;
|
|
|
|
else if (strcmp(value, "0") == 0 ||
|
|
|
|
strcasecmp(value, "off") == 0 ||
|
|
|
|
strcasecmp(value, "no") == 0)
|
|
|
|
flag = 0;
|
2009-12-03 17:44:02 +00:00
|
|
|
else {
|
2017-01-15 20:48:41 +00:00
|
|
|
cmdq_error(item, "bad value: %s", value);
|
|
|
|
return (-1);
|
2009-12-03 17:44:02 +00:00
|
|
|
}
|
2017-01-15 20:48:41 +00:00
|
|
|
options_set_number(oo, oe->name, flag);
|
|
|
|
return (0);
|
2009-12-03 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 20:48:41 +00:00
|
|
|
static int
|
|
|
|
cmd_set_option_choice(struct cmdq_item *item,
|
2013-03-24 09:55:02 +00:00
|
|
|
const struct options_table_entry *oe, struct options *oo,
|
|
|
|
const char *value)
|
2009-12-03 17:44:02 +00:00
|
|
|
{
|
2017-01-15 20:48:41 +00:00
|
|
|
const char **cp;
|
2011-01-04 00:42:46 +00:00
|
|
|
int n, choice = -1;
|
2009-12-03 17:44:02 +00:00
|
|
|
|
2015-04-24 21:38:18 +00:00
|
|
|
if (value == NULL) {
|
|
|
|
choice = options_get_number(oo, oe->name);
|
|
|
|
if (choice < 2)
|
|
|
|
choice = !choice;
|
|
|
|
} else {
|
|
|
|
n = 0;
|
2017-01-15 20:48:41 +00:00
|
|
|
for (cp = oe->choices; *cp != NULL; cp++) {
|
|
|
|
if (strcmp(*cp, value) == 0)
|
|
|
|
choice = n;
|
2015-04-24 21:38:18 +00:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
if (choice == -1) {
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "unknown value: %s", value);
|
2017-01-15 20:48:41 +00:00
|
|
|
return (-1);
|
2009-12-03 17:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-15 20:48:41 +00:00
|
|
|
options_set_number(oo, oe->name, choice);
|
|
|
|
return (0);
|
2014-01-28 23:07:09 +00:00
|
|
|
}
|