[BACK]Return to cmd-choose-tree.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-choose-tree.c, Revision 1.51

1.51    ! nicm        1: /* $OpenBSD: cmd-choose-tree.c,v 1.50 2021/08/27 17:25:55 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
                      5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
                     15:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                     16:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18:
                     19: #include <sys/types.h>
                     20:
                     21: #include "tmux.h"
                     22:
                     23: /*
1.35      nicm       24:  * Enter a mode.
1.1       nicm       25:  */
1.27      nicm       26:
1.50      nicm       27: static enum args_parse_type    cmd_choose_tree_args_parse(struct args *args,
                     28:                                    u_int idx, char **cause);
                     29: static enum cmd_retval         cmd_choose_tree_exec(struct cmd *,
                     30:                                    struct cmdq_item *);
1.1       nicm       31:
                     32: const struct cmd_entry cmd_choose_tree_entry = {
1.30      nicm       33:        .name = "choose-tree",
                     34:        .alias = NULL,
                     35:
1.50      nicm       36:        .args = { "F:f:GK:NO:rst:wZ", 0, 1, cmd_choose_tree_args_parse },
1.48      nicm       37:        .usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] "
                     38:                 "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
1.30      nicm       39:
1.35      nicm       40:        .target = { 't', CMD_FIND_PANE, 0 },
1.31      nicm       41:
                     42:        .flags = 0,
1.30      nicm       43:        .exec = cmd_choose_tree_exec
1.1       nicm       44: };
                     45:
1.35      nicm       46: const struct cmd_entry cmd_choose_client_entry = {
                     47:        .name = "choose-client",
1.30      nicm       48:        .alias = NULL,
                     49:
1.50      nicm       50:        .args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
1.48      nicm       51:        .usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
                     52:                 "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
1.30      nicm       53:
1.35      nicm       54:        .target = { 't', CMD_FIND_PANE, 0 },
1.30      nicm       55:
1.31      nicm       56:        .flags = 0,
1.30      nicm       57:        .exec = cmd_choose_tree_exec
1.1       nicm       58: };
                     59:
1.35      nicm       60: const struct cmd_entry cmd_choose_buffer_entry = {
                     61:        .name = "choose-buffer",
1.30      nicm       62:        .alias = NULL,
                     63:
1.50      nicm       64:        .args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
1.48      nicm       65:        .usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
                     66:                 "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
1.30      nicm       67:
1.35      nicm       68:        .target = { 't', CMD_FIND_PANE, 0 },
1.31      nicm       69:
                     70:        .flags = 0,
1.30      nicm       71:        .exec = cmd_choose_tree_exec
1.1       nicm       72: };
                     73:
1.47      nicm       74: const struct cmd_entry cmd_customize_mode_entry = {
                     75:        .name = "customize-mode",
                     76:        .alias = NULL,
                     77:
1.49      nicm       78:        .args = { "F:f:Nt:Z", 0, 0, NULL },
1.47      nicm       79:        .usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE,
                     80:
                     81:        .target = { 't', CMD_FIND_PANE, 0 },
                     82:
                     83:        .flags = 0,
                     84:        .exec = cmd_choose_tree_exec
                     85: };
1.50      nicm       86:
                     87: static enum args_parse_type
                     88: cmd_choose_tree_args_parse(__unused struct args *args, __unused u_int idx,
                     89:     __unused char **cause)
                     90: {
                     91:        return (ARGS_PARSE_COMMANDS_OR_STRING);
                     92: }
1.47      nicm       93:
1.32      nicm       94: static enum cmd_retval
1.33      nicm       95: cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       96: {
1.45      nicm       97:        struct args                     *args = cmd_get_args(self);
1.46      nicm       98:        struct cmd_find_state           *target = cmdq_get_target(item);
                     99:        struct window_pane              *wp = target->wp;
1.35      nicm      100:        const struct window_mode        *mode;
                    101:
1.45      nicm      102:        if (cmd_get_entry(self) == &cmd_choose_buffer_entry) {
1.51    ! nicm      103:                if (paste_is_empty())
1.35      nicm      104:                        return (CMD_RETURN_NORMAL);
                    105:                mode = &window_buffer_mode;
1.45      nicm      106:        } else if (cmd_get_entry(self) == &cmd_choose_client_entry) {
1.35      nicm      107:                if (server_client_how_many() == 0)
                    108:                        return (CMD_RETURN_NORMAL);
                    109:                mode = &window_client_mode;
1.47      nicm      110:        } else if (cmd_get_entry(self) == &cmd_customize_mode_entry)
                    111:                mode = &window_customize_mode;
                    112:        else
1.35      nicm      113:                mode = &window_tree_mode;
1.1       nicm      114:
1.46      nicm      115:        window_pane_set_mode(wp, NULL, mode, target, args);
1.4       nicm      116:        return (CMD_RETURN_NORMAL);
1.1       nicm      117: }