diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-04-12 06:50:26 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-04-12 06:50:26 +0000 |
commit | 9dae6b02295a75d863f5a8037238876f36fdfa81 (patch) | |
tree | 046a6b70b5f884ae70a1d4c748e4ba67c958bd08 /usr.bin/tmux/window-tree.c | |
parent | 17bf87ec6a29fe188ab74984009a4bb6d3f16978 (diff) |
Permit shortcut keys in buffer, client, tree modes to be configured with
a format; the default remains the line number. GitHub issue 2636.
Diffstat (limited to 'usr.bin/tmux/window-tree.c')
-rw-r--r-- | usr.bin/tmux/window-tree.c | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/usr.bin/tmux/window-tree.c b/usr.bin/tmux/window-tree.c index 760da789d47..c60fedeb44a 100644 --- a/usr.bin/tmux/window-tree.c +++ b/usr.bin/tmux/window-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-tree.c,v 1.53 2020/12/03 07:12:12 nicm Exp $ */ +/* $OpenBSD: window-tree.c,v 1.54 2021/04/12 06:50:25 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -56,6 +56,17 @@ static void window_tree_key(struct window_mode_entry *, "}" \ "}" +#define WINDOW_TREE_DEFAULT_KEY_FORMAT \ + "#{?#{e|<:#{line},10}," \ + "#{line}" \ + "," \ + "#{?#{e|<:#{line},36}," \ + "M-#{a:#{e|+:97,#{e|-:#{line},10}}}" \ + "," \ + "" \ + "}" \ + "}" + static const struct menu_item window_tree_menu_items[] = { { "Select", '\r', NULL }, { "Expand", KEYC_RIGHT, NULL }, @@ -117,6 +128,7 @@ struct window_tree_modedata { struct mode_tree_data *data; char *format; + char *key_format; char *command; int squash_groups; @@ -856,6 +868,35 @@ window_tree_menu(void *modedata, struct client *c, key_code key) window_tree_key(wme, c, NULL, NULL, key, NULL); } +static key_code +window_tree_get_key(void *modedata, void *itemdata, u_int line) +{ + struct window_tree_modedata *data = modedata; + struct window_tree_itemdata *item = itemdata; + struct format_tree *ft; + struct session *s; + struct winlink *wl; + struct window_pane *wp; + char *expanded; + key_code key; + + ft = format_create(NULL, NULL, FORMAT_NONE, 0); + window_tree_pull_item(item, &s, &wl, &wp); + if (item->type == WINDOW_TREE_SESSION) + format_defaults(ft, NULL, s, NULL, NULL); + else if (item->type == WINDOW_TREE_WINDOW) + format_defaults(ft, NULL, s, wl, NULL); + else + format_defaults(ft, NULL, s, wl, wp); + format_add(ft, "line", "%u", line); + + expanded = format_expand(ft, data->key_format); + key = key_string_lookup_string(expanded); + free(expanded); + format_free(ft); + return key; +} + static struct screen * window_tree_init(struct window_mode_entry *wme, struct cmd_find_state *fs, struct args *args) @@ -880,6 +921,10 @@ window_tree_init(struct window_mode_entry *wme, struct cmd_find_state *fs, data->format = xstrdup(WINDOW_TREE_DEFAULT_FORMAT); else data->format = xstrdup(args_get(args, 'F')); + if (args == NULL || !args_has(args, 'K')) + data->key_format = xstrdup(WINDOW_TREE_DEFAULT_KEY_FORMAT); + else + data->key_format = xstrdup(args_get(args, 'K')); if (args == NULL || args->argc == 0) data->command = xstrdup(WINDOW_TREE_DEFAULT_COMMAND); else @@ -887,9 +932,9 @@ window_tree_init(struct window_mode_entry *wme, struct cmd_find_state *fs, data->squash_groups = !args_has(args, 'G'); data->data = mode_tree_start(wp, args, window_tree_build, - window_tree_draw, window_tree_search, window_tree_menu, NULL, data, - window_tree_menu_items, window_tree_sort_list, - nitems(window_tree_sort_list), &s); + window_tree_draw, window_tree_search, window_tree_menu, NULL, + window_tree_get_key, data, window_tree_menu_items, + window_tree_sort_list, nitems(window_tree_sort_list), &s); mode_tree_zoom(data->data, args); mode_tree_build(data->data); @@ -913,6 +958,7 @@ window_tree_destroy(struct window_tree_modedata *data) free(data->item_list); free(data->format); + free(data->key_format); free(data->command); free(data); |