mirror of
https://github.com/tmux/tmux.git
synced 2024-12-04 19:58:48 +00:00
Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or panes (for example in pane-border-format), it will be run separately for each pane.
This commit is contained in:
parent
dd0c814779
commit
7d23d019c0
2
cfg.c
2
cfg.c
@ -123,7 +123,7 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
||||
line);
|
||||
continue;
|
||||
}
|
||||
ft = format_create(NULL, FORMAT_NOJOBS);
|
||||
ft = format_create(NULL, FORMAT_NONE, FORMAT_NOJOBS);
|
||||
|
||||
s = p + 3;
|
||||
while (isspace((u_char)*s))
|
||||
|
@ -77,7 +77,7 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
||||
}
|
||||
|
||||
if (cflag != NULL) {
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
cwd = format_expand(ft, cflag);
|
||||
format_free(ft);
|
||||
|
@ -107,7 +107,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = BREAK_PANE_TEMPLATE;
|
||||
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, item->state.c, dst_s, wl, wp);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
|
@ -73,7 +73,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (template == NULL)
|
||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
||||
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
|
||||
msg = format_expand_time(ft, template, time(NULL));
|
||||
|
@ -82,7 +82,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
else
|
||||
cwd = NULL;
|
||||
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, item->state.c, s, wl, wp);
|
||||
shellcmd = format_expand(ft, args->argv[0]);
|
||||
format_free(ft);
|
||||
|
@ -57,7 +57,7 @@ cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
pb = NULL;
|
||||
while ((pb = paste_walk(pb)) != NULL) {
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults_paste_buffer(ft, pb);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
|
@ -72,7 +72,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (c->session == NULL || (s != NULL && s != c->session))
|
||||
continue;
|
||||
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", idx);
|
||||
format_defaults(ft, c, NULL, NULL, NULL);
|
||||
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmdq_item *);
|
||||
static enum cmd_retval cmd_list_keys_commands(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
@ -37,8 +36,8 @@ const struct cmd_entry cmd_list_keys_entry = {
|
||||
.name = "list-keys",
|
||||
.alias = "lsk",
|
||||
|
||||
.args = { "t:T:", 0, 0 },
|
||||
.usage = "[-t mode-table] [-T key-table]",
|
||||
.args = { "T:", 0, 0 },
|
||||
.usage = "[-T key-table]",
|
||||
|
||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||
.exec = cmd_list_keys_exec
|
||||
@ -68,9 +67,6 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (self->entry == &cmd_list_commands_entry)
|
||||
return (cmd_list_keys_commands(self, item));
|
||||
|
||||
if (args_has(args, 't'))
|
||||
return (cmd_list_keys_table(self, item));
|
||||
|
||||
tablename = args_get(args, 'T');
|
||||
if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) {
|
||||
cmdq_error(item, "table %s doesn't exist", tablename);
|
||||
@ -132,40 +128,6 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_keys_table(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *tablename, *cmdstr;
|
||||
const struct mode_key_table *mtab;
|
||||
struct mode_key_binding *mbind;
|
||||
int width, keywidth;
|
||||
|
||||
tablename = args_get(args, 't');
|
||||
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||
cmdq_error(item, "unknown key table: %s", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
keywidth = 0;
|
||||
RB_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||
width = strlen(key_string_lookup_key(mbind->key));
|
||||
if (width > keywidth)
|
||||
keywidth = width;
|
||||
}
|
||||
|
||||
RB_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd);
|
||||
if (cmdstr != NULL) {
|
||||
cmdq_print(item, "bind-key -t %s %*s %s",
|
||||
mtab->name, (int)keywidth,
|
||||
key_string_lookup_key(mbind->key), cmdstr);
|
||||
}
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
@ -182,7 +144,7 @@ cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
||||
"#{command_list_usage}";
|
||||
}
|
||||
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, NULL, NULL, NULL, NULL);
|
||||
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
||||
|
@ -123,7 +123,7 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
|
||||
|
||||
n = 0;
|
||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, wl, wp);
|
||||
|
||||
|
@ -65,7 +65,7 @@ cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
n = 0;
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, NULL, NULL);
|
||||
|
||||
|
@ -105,7 +105,7 @@ cmd_list_windows_session(struct cmd *self, struct session *s,
|
||||
|
||||
n = 0;
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, wl, NULL);
|
||||
|
||||
|
@ -139,7 +139,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
/* Get the new session working directory. */
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, NULL, NULL, NULL);
|
||||
to_free = cwd = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
@ -298,7 +298,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = NEW_SESSION_TEMPLATE;
|
||||
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, NULL, NULL);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
|
@ -95,7 +95,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
to_free = NULL;
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, NULL, NULL);
|
||||
cwd = to_free = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
@ -143,7 +143,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = NEW_WINDOW_TEMPLATE;
|
||||
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, NULL);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
|
@ -90,7 +90,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
/* Expand the command. */
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
cmd = format_expand_time(ft, args->argv[0], time(NULL));
|
||||
format_free(ft);
|
||||
|
@ -268,7 +268,7 @@ cmdq_format(struct cmdq_item *item, const char *key, const char *fmt, ...)
|
||||
|
||||
for (loop = item; loop != NULL; loop = item->next) {
|
||||
if (loop->formats == NULL)
|
||||
loop->formats = format_create(NULL, 0);
|
||||
loop->formats = format_create(NULL, FORMAT_NONE, 0);
|
||||
format_add(loop->formats, key, "%s", value);
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
else
|
||||
cwd = NULL;
|
||||
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, item->state.c, s, wl, wp);
|
||||
shellcmd = format_expand(ft, args->argv[0]);
|
||||
format_free(ft);
|
||||
|
@ -92,7 +92,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
to_free = NULL;
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, item->state.c, s, NULL, NULL);
|
||||
to_free = cwd = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
@ -169,7 +169,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = SPLIT_WINDOW_TEMPLATE;
|
||||
|
||||
ft = format_create(item, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, item->state.c, s, wl, new_wp);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
|
@ -88,7 +88,7 @@ control_notify_window_layout_changed(struct window *w)
|
||||
if (w->layout_root == NULL)
|
||||
continue;
|
||||
|
||||
ft = format_create(NULL, 0);
|
||||
ft = format_create(NULL, FORMAT_NONE, 0);
|
||||
wl = winlink_find_by_window(&s->windows, w);
|
||||
if (wl != NULL) {
|
||||
format_defaults(ft, c, NULL, wl, NULL);
|
||||
|
12
format.c
12
format.c
@ -77,6 +77,7 @@ static void format_defaults_winlink(struct format_tree *, struct session *,
|
||||
|
||||
/* Entry in format job tree. */
|
||||
struct format_job {
|
||||
u_int tag;
|
||||
const char *cmd;
|
||||
const char *expanded;
|
||||
|
||||
@ -99,6 +100,10 @@ RB_GENERATE_STATIC(format_job_tree, format_job, entry, format_job_cmp);
|
||||
static int
|
||||
format_job_cmp(struct format_job *fj1, struct format_job *fj2)
|
||||
{
|
||||
if (fj1->tag < fj2->tag)
|
||||
return (-1);
|
||||
if (fj1->tag > fj2->tag)
|
||||
return (1);
|
||||
return (strcmp(fj1->cmd, fj2->cmd));
|
||||
}
|
||||
|
||||
@ -123,6 +128,7 @@ struct format_tree {
|
||||
struct session *s;
|
||||
struct window_pane *wp;
|
||||
|
||||
u_int tag;
|
||||
int flags;
|
||||
|
||||
RB_HEAD(format_entry_tree, format_entry) tree;
|
||||
@ -238,9 +244,11 @@ format_job_get(struct format_tree *ft, const char *cmd)
|
||||
char *expanded;
|
||||
int force;
|
||||
|
||||
fj0.tag = ft->tag;
|
||||
fj0.cmd = cmd;
|
||||
if ((fj = RB_FIND(format_job_tree, &format_jobs, &fj0)) == NULL) {
|
||||
fj = xcalloc(1, sizeof *fj);
|
||||
fj->tag = ft->tag;
|
||||
fj->cmd = xstrdup(cmd);
|
||||
fj->expanded = NULL;
|
||||
|
||||
@ -497,7 +505,7 @@ format_merge(struct format_tree *ft, struct format_tree *from)
|
||||
|
||||
/* Create a new tree. */
|
||||
struct format_tree *
|
||||
format_create(struct cmdq_item *item, int flags)
|
||||
format_create(struct cmdq_item *item, int tag, int flags)
|
||||
{
|
||||
struct format_tree *ft;
|
||||
|
||||
@ -508,6 +516,8 @@ format_create(struct cmdq_item *item, int flags)
|
||||
|
||||
ft = xcalloc(1, sizeof *ft);
|
||||
RB_INIT(&ft->tree);
|
||||
|
||||
ft->tag = tag;
|
||||
ft->flags = flags;
|
||||
|
||||
format_add_cb(ft, "host", format_cb_host);
|
||||
|
2
names.c
2
names.c
@ -124,7 +124,7 @@ format_window_name(struct window *w)
|
||||
const char *fmt;
|
||||
char *name;
|
||||
|
||||
ft = format_create(NULL, 0);
|
||||
ft = format_create(NULL, FORMAT_WINDOW|w->id, 0);
|
||||
format_defaults_window(ft, w);
|
||||
format_defaults_pane(ft, w->active);
|
||||
|
||||
|
@ -280,7 +280,7 @@ screen_redraw_make_pane_status(struct client *c, struct window *w,
|
||||
|
||||
fmt = options_get_string(w->options, "pane-border-format");
|
||||
|
||||
ft = format_create(NULL, 0);
|
||||
ft = format_create(NULL, FORMAT_PANE|wp->id, 0);
|
||||
format_defaults(ft, c, NULL, NULL, wp);
|
||||
|
||||
memcpy(&old, &wp->status_screen, sizeof old);
|
||||
|
@ -1222,7 +1222,7 @@ server_client_set_title(struct client *c)
|
||||
|
||||
template = options_get_string(s->options, "set-titles-string");
|
||||
|
||||
ft = format_create(NULL, 0);
|
||||
ft = format_create(NULL, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, NULL, NULL, NULL);
|
||||
|
||||
title = format_expand_time(ft, template, time(NULL));
|
||||
|
15
status.c
15
status.c
@ -500,14 +500,19 @@ status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t)
|
||||
{
|
||||
struct format_tree *ft;
|
||||
char *expanded;
|
||||
u_int tag;
|
||||
|
||||
if (fmt == NULL)
|
||||
return (xstrdup(""));
|
||||
|
||||
if (c->flags & CLIENT_STATUSFORCE)
|
||||
ft = format_create(NULL, FORMAT_STATUS|FORMAT_FORCE);
|
||||
if (wl != NULL)
|
||||
tag = FORMAT_WINDOW|wl->window->id;
|
||||
else
|
||||
ft = format_create(NULL, FORMAT_STATUS);
|
||||
tag = FORMAT_NONE;
|
||||
if (c->flags & CLIENT_STATUSFORCE)
|
||||
ft = format_create(NULL, tag, FORMAT_STATUS|FORMAT_FORCE);
|
||||
else
|
||||
ft = format_create(NULL, tag, FORMAT_STATUS);
|
||||
format_defaults(ft, c, NULL, wl, NULL);
|
||||
|
||||
expanded = format_expand_time(ft, fmt, t);
|
||||
@ -665,7 +670,7 @@ status_prompt_set(struct client *c, const char *msg, const char *input,
|
||||
time_t t;
|
||||
char *tmp;
|
||||
|
||||
ft = format_create(NULL, 0);
|
||||
ft = format_create(NULL, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, NULL, NULL, NULL);
|
||||
|
||||
t = time(NULL);
|
||||
@ -726,7 +731,7 @@ status_prompt_update(struct client *c, const char *msg, const char *input)
|
||||
time_t t;
|
||||
char *tmp;
|
||||
|
||||
ft = format_create(NULL, 0);
|
||||
ft = format_create(NULL, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, NULL, NULL, NULL);
|
||||
|
||||
t = time(NULL);
|
||||
|
5
tmux.h
5
tmux.h
@ -1503,8 +1503,11 @@ char *paste_make_sample(struct paste_buffer *);
|
||||
#define FORMAT_STATUS 0x1
|
||||
#define FORMAT_FORCE 0x2
|
||||
#define FORMAT_NOJOBS 0x4
|
||||
#define FORMAT_NONE 0
|
||||
#define FORMAT_PANE 0x80000000U
|
||||
#define FORMAT_WINDOW 0x40000000U
|
||||
struct format_tree;
|
||||
struct format_tree *format_create(struct cmdq_item *, int);
|
||||
struct format_tree *format_create(struct cmdq_item *, int, int);
|
||||
void format_free(struct format_tree *);
|
||||
void printflike(3, 4) format_add(struct format_tree *, const char *,
|
||||
const char *, ...);
|
||||
|
214
window-choose.c
214
window-choose.c
@ -74,8 +74,6 @@ struct window_choose_mode_item {
|
||||
struct window_choose_mode_data {
|
||||
struct screen screen;
|
||||
|
||||
struct mode_key_data mdata;
|
||||
|
||||
struct window_choose_mode_item *list;
|
||||
u_int list_size;
|
||||
struct window_choose_mode_item *old_list;
|
||||
@ -91,11 +89,16 @@ struct window_choose_mode_data {
|
||||
void (*callbackfn)(struct window_choose_data *);
|
||||
};
|
||||
|
||||
static const char window_choose_keys_emacs[] = "0123456789"
|
||||
"abcdefghijklmnoprstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
static const char window_choose_keys_vi[] = "0123456789"
|
||||
"abcdefhilmnoprstuvwxyz"
|
||||
"ABCDEFIJKMNOPQRSTUVWXYZ";
|
||||
|
||||
static void window_choose_free1(struct window_choose_mode_data *);
|
||||
static int window_choose_key_index(struct window_choose_mode_data *,
|
||||
u_int);
|
||||
static int window_choose_index_key(struct window_choose_mode_data *,
|
||||
key_code);
|
||||
static int window_choose_key_index(struct window_pane *, u_int);
|
||||
static int window_choose_index_key(struct window_pane *, key_code);
|
||||
static void window_choose_prompt_input(enum window_choose_input_type,
|
||||
const char *, struct window_pane *, key_code);
|
||||
static void window_choose_reset_top(struct window_pane *, u_int);
|
||||
@ -168,7 +171,6 @@ window_choose_init(struct window_pane *wp)
|
||||
{
|
||||
struct window_choose_mode_data *data;
|
||||
struct screen *s;
|
||||
int keys;
|
||||
|
||||
wp->modedata = data = xcalloc(1, sizeof *data);
|
||||
|
||||
@ -189,12 +191,6 @@ window_choose_init(struct window_pane *wp)
|
||||
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
||||
s->mode &= ~MODE_CURSOR;
|
||||
|
||||
keys = options_get_number(wp->window->options, "mode-keys");
|
||||
if (keys == MODEKEY_EMACS)
|
||||
mode_key_init(&data->mdata, &mode_key_tree_emacs_choice);
|
||||
else
|
||||
mode_key_init(&data->mdata, &mode_key_tree_vi_choice);
|
||||
|
||||
return (s);
|
||||
}
|
||||
|
||||
@ -206,7 +202,7 @@ window_choose_data_create(int type, struct client *c, struct session *s)
|
||||
wcd = xmalloc(sizeof *wcd);
|
||||
wcd->type = type;
|
||||
|
||||
wcd->ft = format_create(NULL, 0);
|
||||
wcd->ft = format_create(NULL, FORMAT_NONE, 0);
|
||||
wcd->ft_template = NULL;
|
||||
|
||||
wcd->command = NULL;
|
||||
@ -547,9 +543,74 @@ window_choose_get_item(struct window_pane *wp, key_code key,
|
||||
return (&data->list[idx]);
|
||||
}
|
||||
|
||||
static key_code
|
||||
window_choose_translate_key(key_code key)
|
||||
{
|
||||
switch (key) {
|
||||
case '0'|KEYC_ESCAPE:
|
||||
case '1'|KEYC_ESCAPE:
|
||||
case '2'|KEYC_ESCAPE:
|
||||
case '3'|KEYC_ESCAPE:
|
||||
case '4'|KEYC_ESCAPE:
|
||||
case '5'|KEYC_ESCAPE:
|
||||
case '6'|KEYC_ESCAPE:
|
||||
case '7'|KEYC_ESCAPE:
|
||||
case '8'|KEYC_ESCAPE:
|
||||
case '9'|KEYC_ESCAPE:
|
||||
case '\003': /* C-c */
|
||||
case 'q':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case KEYC_BSPACE:
|
||||
case ' ':
|
||||
case KEYC_LEFT:
|
||||
case KEYC_RIGHT:
|
||||
case KEYC_LEFT|KEYC_CTRL:
|
||||
case KEYC_RIGHT|KEYC_CTRL:
|
||||
case KEYC_MOUSEDOWN1_PANE:
|
||||
case KEYC_MOUSEDOWN3_PANE:
|
||||
case KEYC_WHEELUP_PANE:
|
||||
case KEYC_WHEELDOWN_PANE:
|
||||
return (key);
|
||||
case '\031': /* C-y */
|
||||
case KEYC_UP|KEYC_CTRL:
|
||||
return (KEYC_UP|KEYC_CTRL);
|
||||
case '\002': /* C-b */
|
||||
case KEYC_PPAGE:
|
||||
return (KEYC_PPAGE);
|
||||
case '\005': /* C-e */
|
||||
case KEYC_DOWN|KEYC_CTRL:
|
||||
return (KEYC_DOWN|KEYC_CTRL);
|
||||
case '\006': /* C-f */
|
||||
case KEYC_NPAGE:
|
||||
return (KEYC_NPAGE);
|
||||
case 'j':
|
||||
case KEYC_DOWN:
|
||||
return (KEYC_DOWN);
|
||||
case 'k':
|
||||
case KEYC_UP:
|
||||
return (KEYC_UP);
|
||||
case 'g':
|
||||
case KEYC_HOME:
|
||||
return (KEYC_HOME);
|
||||
case 'G':
|
||||
case KEYC_END:
|
||||
return (KEYC_END);
|
||||
case 'H':
|
||||
return ('R'|KEYC_ESCAPE);
|
||||
case 'L':
|
||||
return ('r'|KEYC_ESCAPE);
|
||||
}
|
||||
if ((key >= '0' && key <= '9') ||
|
||||
(key >= 'a' && key <= 'z') ||
|
||||
(key >= 'A' && key <= 'Z'))
|
||||
return (key);
|
||||
return (KEYC_NONE);
|
||||
}
|
||||
|
||||
static void
|
||||
window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
__unused struct session *sess, key_code key, struct mouse_event *m)
|
||||
__unused struct session *sp, key_code key, struct mouse_event *m)
|
||||
{
|
||||
struct window_choose_mode_data *data = wp->modedata;
|
||||
struct screen *s = &data->screen;
|
||||
@ -557,17 +618,26 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
struct window_choose_mode_item *item;
|
||||
size_t input_len;
|
||||
u_int items, n;
|
||||
int idx;
|
||||
int idx, keys;
|
||||
|
||||
keys = options_get_number(wp->window->options, "mode-keys");
|
||||
if (keys == MODEKEY_VI) {
|
||||
key = window_choose_translate_key(key);
|
||||
if (key == KEYC_NONE)
|
||||
return;
|
||||
}
|
||||
items = data->list_size;
|
||||
|
||||
if (data->input_type == WINDOW_CHOOSE_GOTO_ITEM) {
|
||||
switch (mode_key_lookup(&data->mdata, key)) {
|
||||
case MODEKEYCHOICE_CANCEL:
|
||||
switch (key) {
|
||||
case '\003': /* C-c */
|
||||
case '\033': /* Escape */
|
||||
case 'q':
|
||||
data->input_type = WINDOW_CHOOSE_NORMAL;
|
||||
window_choose_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_CHOOSE:
|
||||
case '\n':
|
||||
case '\r':
|
||||
n = strtonum(data->input_str, 0, INT_MAX, NULL);
|
||||
if (n > items - 1) {
|
||||
data->input_type = WINDOW_CHOOSE_NORMAL;
|
||||
@ -576,7 +646,7 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
}
|
||||
window_choose_fire_callback(wp, data->list[n].wcd);
|
||||
break;
|
||||
case MODEKEYCHOICE_BACKSPACE:
|
||||
case KEYC_BSPACE:
|
||||
input_len = strlen(data->input_str);
|
||||
if (input_len > 0)
|
||||
data->input_str[input_len - 1] = '\0';
|
||||
@ -592,16 +662,21 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mode_key_lookup(&data->mdata, key)) {
|
||||
case MODEKEYCHOICE_CANCEL:
|
||||
switch (key) {
|
||||
case '\003': /* C-c */
|
||||
case '\033': /* Escape */
|
||||
case 'q':
|
||||
window_choose_fire_callback(wp, NULL);
|
||||
break;
|
||||
case MODEKEYCHOICE_CHOOSE:
|
||||
case '\n':
|
||||
case '\r':
|
||||
case KEYC_MOUSEDOWN1_PANE:
|
||||
if ((item = window_choose_get_item(wp, key, m)) == NULL)
|
||||
break;
|
||||
window_choose_fire_callback(wp, item->wcd);
|
||||
break;
|
||||
case MODEKEYCHOICE_TREE_TOGGLE:
|
||||
case ' ':
|
||||
case KEYC_MOUSEDOWN3_PANE:
|
||||
if ((item = window_choose_get_item(wp, key, m)) == NULL)
|
||||
break;
|
||||
if (item->state & TREE_EXPANDED) {
|
||||
@ -613,7 +688,7 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
}
|
||||
window_choose_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_TREE_COLLAPSE:
|
||||
case KEYC_LEFT:
|
||||
if ((item = window_choose_get_item(wp, key, m)) == NULL)
|
||||
break;
|
||||
if (item->state & TREE_EXPANDED) {
|
||||
@ -622,10 +697,10 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
window_choose_redraw_screen(wp);
|
||||
}
|
||||
break;
|
||||
case MODEKEYCHOICE_TREE_COLLAPSE_ALL:
|
||||
case KEYC_LEFT|KEYC_CTRL:
|
||||
window_choose_collapse_all(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_TREE_EXPAND:
|
||||
case KEYC_RIGHT:
|
||||
if ((item = window_choose_get_item(wp, key, m)) == NULL)
|
||||
break;
|
||||
if (!(item->state & TREE_EXPANDED)) {
|
||||
@ -634,10 +709,12 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
window_choose_redraw_screen(wp);
|
||||
}
|
||||
break;
|
||||
case MODEKEYCHOICE_TREE_EXPAND_ALL:
|
||||
case KEYC_RIGHT|KEYC_CTRL:
|
||||
window_choose_expand_all(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_UP:
|
||||
case '\020': /* C-p */
|
||||
case KEYC_UP:
|
||||
case KEYC_WHEELUP_PANE:
|
||||
if (items == 0)
|
||||
break;
|
||||
if (data->selected == 0) {
|
||||
@ -659,7 +736,9 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
screen_write_stop(&ctx);
|
||||
}
|
||||
break;
|
||||
case MODEKEYCHOICE_DOWN:
|
||||
case '\016': /* C-n */
|
||||
case KEYC_DOWN:
|
||||
case KEYC_WHEELDOWN_PANE:
|
||||
if (items == 0)
|
||||
break;
|
||||
if (data->selected == items - 1) {
|
||||
@ -680,7 +759,7 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
} else
|
||||
window_choose_scroll_down(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_SCROLLUP:
|
||||
case KEYC_UP|KEYC_CTRL:
|
||||
if (items == 0 || data->top == 0)
|
||||
break;
|
||||
if (data->selected == data->top + screen_size_y(s) - 1) {
|
||||
@ -693,7 +772,7 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
} else
|
||||
window_choose_scroll_up(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_SCROLLDOWN:
|
||||
case KEYC_DOWN|KEYC_CTRL:
|
||||
if (items == 0 ||
|
||||
data->top + screen_size_y(&data->screen) >= items)
|
||||
break;
|
||||
@ -706,7 +785,7 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
} else
|
||||
window_choose_scroll_down(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_PAGEUP:
|
||||
case KEYC_PPAGE:
|
||||
if (data->selected < screen_size_y(s)) {
|
||||
data->selected = 0;
|
||||
data->top = 0;
|
||||
@ -719,7 +798,7 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
}
|
||||
window_choose_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_PAGEDOWN:
|
||||
case KEYC_NPAGE:
|
||||
data->selected += screen_size_y(s);
|
||||
if (data->selected > items - 1)
|
||||
data->selected = items - 1;
|
||||
@ -733,35 +812,46 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
data->top = data->selected;
|
||||
window_choose_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_BACKSPACE:
|
||||
case KEYC_BSPACE:
|
||||
input_len = strlen(data->input_str);
|
||||
if (input_len > 0)
|
||||
data->input_str[input_len - 1] = '\0';
|
||||
window_choose_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_STARTNUMBERPREFIX:
|
||||
case '0'|KEYC_ESCAPE:
|
||||
case '1'|KEYC_ESCAPE:
|
||||
case '2'|KEYC_ESCAPE:
|
||||
case '3'|KEYC_ESCAPE:
|
||||
case '4'|KEYC_ESCAPE:
|
||||
case '5'|KEYC_ESCAPE:
|
||||
case '6'|KEYC_ESCAPE:
|
||||
case '7'|KEYC_ESCAPE:
|
||||
case '8'|KEYC_ESCAPE:
|
||||
case '9'|KEYC_ESCAPE:
|
||||
key &= KEYC_MASK_KEY;
|
||||
if (key < '0' || key > '9')
|
||||
break;
|
||||
window_choose_prompt_input(WINDOW_CHOOSE_GOTO_ITEM,
|
||||
"Goto Item", wp, key);
|
||||
break;
|
||||
case MODEKEYCHOICE_STARTOFLIST:
|
||||
case KEYC_HOME:
|
||||
case '<'|KEYC_ESCAPE:
|
||||
data->selected = 0;
|
||||
data->top = 0;
|
||||
window_choose_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_TOPLINE:
|
||||
case 'R'|KEYC_ESCAPE:
|
||||
data->selected = data->top;
|
||||
window_choose_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_BOTTOMLINE:
|
||||
case 'r'|KEYC_ESCAPE:
|
||||
data->selected = data->top + screen_size_y(s) - 1;
|
||||
if (data->selected > items - 1)
|
||||
data->selected = items - 1;
|
||||
window_choose_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEYCHOICE_ENDOFLIST:
|
||||
case KEYC_END:
|
||||
case '>'|KEYC_ESCAPE:
|
||||
data->selected = items - 1;
|
||||
if (screen_size_y(s) < items)
|
||||
data->top = items - screen_size_y(s);
|
||||
@ -770,7 +860,7 @@ window_choose_key(struct window_pane *wp, __unused struct client *c,
|
||||
window_choose_redraw_screen(wp);
|
||||
break;
|
||||
default:
|
||||
idx = window_choose_index_key(data, key);
|
||||
idx = window_choose_index_key(wp, key);
|
||||
if (idx < 0 || (u_int) idx >= data->list_size)
|
||||
break;
|
||||
data->selected = idx;
|
||||
@ -808,7 +898,7 @@ window_choose_write_line(struct window_pane *wp, struct screen_write_ctx *ctx,
|
||||
item->wcd->wl->flags & WINLINK_ALERTFLAGS)
|
||||
gc.attr |= GRID_ATTR_BRIGHT;
|
||||
|
||||
key = window_choose_key_index(data, data->top + py);
|
||||
key = window_choose_key_index(wp, data->top + py);
|
||||
if (key != -1)
|
||||
xsnprintf(label, sizeof label, "(%c)", key);
|
||||
else
|
||||
@ -839,18 +929,17 @@ window_choose_write_line(struct window_pane *wp, struct screen_write_ctx *ctx,
|
||||
}
|
||||
|
||||
static int
|
||||
window_choose_key_index(struct window_choose_mode_data *data, u_int idx)
|
||||
window_choose_key_index(struct window_pane *wp, u_int idx)
|
||||
{
|
||||
static const char keys[] = "0123456789"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
const char *ptr;
|
||||
int mkey;
|
||||
const char *ptr;
|
||||
int keys;
|
||||
|
||||
for (ptr = keys; *ptr != '\0'; ptr++) {
|
||||
mkey = mode_key_lookup(&data->mdata, *ptr);
|
||||
if (mkey != MODEKEY_NONE && mkey != MODEKEY_OTHER)
|
||||
continue;
|
||||
keys = options_get_number(wp->window->options, "mode-keys");
|
||||
if (keys == MODEKEY_VI)
|
||||
ptr = window_choose_keys_vi;
|
||||
else
|
||||
ptr = window_choose_keys_emacs;
|
||||
for (; *ptr != '\0'; ptr++) {
|
||||
if (idx-- == 0)
|
||||
return (*ptr);
|
||||
}
|
||||
@ -858,19 +947,18 @@ window_choose_key_index(struct window_choose_mode_data *data, u_int idx)
|
||||
}
|
||||
|
||||
static int
|
||||
window_choose_index_key(struct window_choose_mode_data *data, key_code key)
|
||||
window_choose_index_key(struct window_pane *wp, key_code key)
|
||||
{
|
||||
static const char keys[] = "0123456789"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
const char *ptr;
|
||||
int mkey;
|
||||
u_int idx = 0;
|
||||
const char *ptr;
|
||||
int keys;
|
||||
u_int idx = 0;
|
||||
|
||||
for (ptr = keys; *ptr != '\0'; ptr++) {
|
||||
mkey = mode_key_lookup(&data->mdata, *ptr);
|
||||
if (mkey != MODEKEY_NONE && mkey != MODEKEY_OTHER)
|
||||
continue;
|
||||
keys = options_get_number(wp->window->options, "mode-keys");
|
||||
if (keys == MODEKEY_VI)
|
||||
ptr = window_choose_keys_vi;
|
||||
else
|
||||
ptr = window_choose_keys_emacs;
|
||||
for (; *ptr != '\0'; ptr++) {
|
||||
if (key == (key_code)*ptr)
|
||||
return (idx);
|
||||
idx++;
|
||||
|
@ -1611,7 +1611,7 @@ window_copy_copy_pipe(struct window_pane *wp, struct session *sess,
|
||||
if (buf == NULL)
|
||||
return;
|
||||
|
||||
ft = format_create(NULL, 0);
|
||||
ft = format_create(NULL, FORMAT_NONE, 0);
|
||||
format_defaults(ft, NULL, sess, NULL, wp);
|
||||
expanded = format_expand(ft, arg);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user