xref: /openbsd/usr.bin/tmux/cmd-choose-tree.c (revision 4cfece93)
1 /* $OpenBSD: cmd-choose-tree.c,v 1.47 2020/05/16 16:02:24 nicm Exp $ */
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 /*
24  * Enter a mode.
25  */
26 
27 static enum cmd_retval	cmd_choose_tree_exec(struct cmd *, struct cmdq_item *);
28 
29 const struct cmd_entry cmd_choose_tree_entry = {
30 	.name = "choose-tree",
31 	.alias = NULL,
32 
33 	.args = { "F:Gf:NO:rst:wZ", 0, 1 },
34 	.usage = "[-GNrswZ] [-F format] [-f filter] [-O sort-order] "
35 	         CMD_TARGET_PANE_USAGE " [template]",
36 
37 	.target = { 't', CMD_FIND_PANE, 0 },
38 
39 	.flags = 0,
40 	.exec = cmd_choose_tree_exec
41 };
42 
43 const struct cmd_entry cmd_choose_client_entry = {
44 	.name = "choose-client",
45 	.alias = NULL,
46 
47 	.args = { "F:f:NO:rt:Z", 0, 1 },
48 	.usage = "[-NrZ] [-F format] [-f filter] [-O sort-order] "
49 	         CMD_TARGET_PANE_USAGE " [template]",
50 
51 	.target = { 't', CMD_FIND_PANE, 0 },
52 
53 	.flags = 0,
54 	.exec = cmd_choose_tree_exec
55 };
56 
57 const struct cmd_entry cmd_choose_buffer_entry = {
58 	.name = "choose-buffer",
59 	.alias = NULL,
60 
61 	.args = { "F:f:NO:rt:Z", 0, 1 },
62 	.usage = "[-NrZ] [-F format] [-f filter] [-O sort-order] "
63 	         CMD_TARGET_PANE_USAGE " [template]",
64 
65 	.target = { 't', CMD_FIND_PANE, 0 },
66 
67 	.flags = 0,
68 	.exec = cmd_choose_tree_exec
69 };
70 
71 const struct cmd_entry cmd_customize_mode_entry = {
72 	.name = "customize-mode",
73 	.alias = NULL,
74 
75 	.args = { "F:f:Nt:Z", 0, 0 },
76 	.usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE,
77 
78 	.target = { 't', CMD_FIND_PANE, 0 },
79 
80 	.flags = 0,
81 	.exec = cmd_choose_tree_exec
82 };
83 
84 static enum cmd_retval
85 cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
86 {
87 	struct args			*args = cmd_get_args(self);
88 	struct cmd_find_state		*target = cmdq_get_target(item);
89 	struct window_pane		*wp = target->wp;
90 	const struct window_mode	*mode;
91 
92 	if (cmd_get_entry(self) == &cmd_choose_buffer_entry) {
93 		if (paste_get_top(NULL) == NULL)
94 			return (CMD_RETURN_NORMAL);
95 		mode = &window_buffer_mode;
96 	} else if (cmd_get_entry(self) == &cmd_choose_client_entry) {
97 		if (server_client_how_many() == 0)
98 			return (CMD_RETURN_NORMAL);
99 		mode = &window_client_mode;
100 	} else if (cmd_get_entry(self) == &cmd_customize_mode_entry)
101 		mode = &window_customize_mode;
102 	else
103 		mode = &window_tree_mode;
104 
105 	window_pane_set_mode(wp, NULL, mode, target, args);
106 	return (CMD_RETURN_NORMAL);
107 }
108