Free title earlier, from Alexis Hildebrandt.
[tmux-openbsd.git] / cmd-choose-tree.c
blobf2f4b2e3855e1c497af656183518e6b1515851b0
1 /* $OpenBSD$ */
3 /*
4 * Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
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.
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.
19 #include <sys/types.h>
21 #include "tmux.h"
24 * Enter a mode.
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 *);
32 const struct cmd_entry cmd_choose_tree_entry = {
33 .name = "choose-tree",
34 .alias = NULL,
36 .args = { "F:f:GK:NO:rst:wZ", 0, 1, cmd_choose_tree_args_parse },
37 .usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] "
38 "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
40 .target = { 't', CMD_FIND_PANE, 0 },
42 .flags = 0,
43 .exec = cmd_choose_tree_exec
46 const struct cmd_entry cmd_choose_client_entry = {
47 .name = "choose-client",
48 .alias = NULL,
50 .args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
51 .usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
52 "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
54 .target = { 't', CMD_FIND_PANE, 0 },
56 .flags = 0,
57 .exec = cmd_choose_tree_exec
60 const struct cmd_entry cmd_choose_buffer_entry = {
61 .name = "choose-buffer",
62 .alias = NULL,
64 .args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
65 .usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
66 "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
68 .target = { 't', CMD_FIND_PANE, 0 },
70 .flags = 0,
71 .exec = cmd_choose_tree_exec
74 const struct cmd_entry cmd_customize_mode_entry = {
75 .name = "customize-mode",
76 .alias = NULL,
78 .args = { "F:f:Nt:Z", 0, 0, NULL },
79 .usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE,
81 .target = { 't', CMD_FIND_PANE, 0 },
83 .flags = 0,
84 .exec = cmd_choose_tree_exec
87 static enum args_parse_type
88 cmd_choose_tree_args_parse(__unused struct args *args, __unused u_int idx,
89 __unused char **cause)
91 return (ARGS_PARSE_COMMANDS_OR_STRING);
94 static enum cmd_retval
95 cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
97 struct args *args = cmd_get_args(self);
98 struct cmd_find_state *target = cmdq_get_target(item);
99 struct window_pane *wp = target->wp;
100 const struct window_mode *mode;
102 if (cmd_get_entry(self) == &cmd_choose_buffer_entry) {
103 if (paste_is_empty())
104 return (CMD_RETURN_NORMAL);
105 mode = &window_buffer_mode;
106 } else if (cmd_get_entry(self) == &cmd_choose_client_entry) {
107 if (server_client_how_many() == 0)
108 return (CMD_RETURN_NORMAL);
109 mode = &window_client_mode;
110 } else if (cmd_get_entry(self) == &cmd_customize_mode_entry)
111 mode = &window_customize_mode;
112 else
113 mode = &window_tree_mode;
115 window_pane_set_mode(wp, NULL, mode, target, args);
116 return (CMD_RETURN_NORMAL);