/src/tmux/cmd-choose-tree.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* $OpenBSD$ */ |
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 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 *); |
31 | | |
32 | | const struct cmd_entry cmd_choose_tree_entry = { |
33 | | .name = "choose-tree", |
34 | | .alias = NULL, |
35 | | |
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]", |
39 | | |
40 | | .target = { 't', CMD_FIND_PANE, 0 }, |
41 | | |
42 | | .flags = 0, |
43 | | .exec = cmd_choose_tree_exec |
44 | | }; |
45 | | |
46 | | const struct cmd_entry cmd_choose_client_entry = { |
47 | | .name = "choose-client", |
48 | | .alias = NULL, |
49 | | |
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]", |
53 | | |
54 | | .target = { 't', CMD_FIND_PANE, 0 }, |
55 | | |
56 | | .flags = 0, |
57 | | .exec = cmd_choose_tree_exec |
58 | | }; |
59 | | |
60 | | const struct cmd_entry cmd_choose_buffer_entry = { |
61 | | .name = "choose-buffer", |
62 | | .alias = NULL, |
63 | | |
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]", |
67 | | |
68 | | .target = { 't', CMD_FIND_PANE, 0 }, |
69 | | |
70 | | .flags = 0, |
71 | | .exec = cmd_choose_tree_exec |
72 | | }; |
73 | | |
74 | | const struct cmd_entry cmd_customize_mode_entry = { |
75 | | .name = "customize-mode", |
76 | | .alias = NULL, |
77 | | |
78 | | .args = { "F:f:Nt:Z", 0, 0, NULL }, |
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 | | }; |
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 | 0 | { |
91 | 0 | return (ARGS_PARSE_COMMANDS_OR_STRING); |
92 | 0 | } |
93 | | |
94 | | static enum cmd_retval |
95 | | cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item) |
96 | 0 | { |
97 | 0 | struct args *args = cmd_get_args(self); |
98 | 0 | struct cmd_find_state *target = cmdq_get_target(item); |
99 | 0 | struct window_pane *wp = target->wp; |
100 | 0 | const struct window_mode *mode; |
101 | |
|
102 | 0 | if (cmd_get_entry(self) == &cmd_choose_buffer_entry) { |
103 | 0 | if (paste_is_empty()) |
104 | 0 | return (CMD_RETURN_NORMAL); |
105 | 0 | mode = &window_buffer_mode; |
106 | 0 | } else if (cmd_get_entry(self) == &cmd_choose_client_entry) { |
107 | 0 | if (server_client_how_many() == 0) |
108 | 0 | return (CMD_RETURN_NORMAL); |
109 | 0 | mode = &window_client_mode; |
110 | 0 | } else if (cmd_get_entry(self) == &cmd_customize_mode_entry) |
111 | 0 | mode = &window_customize_mode; |
112 | 0 | else |
113 | 0 | mode = &window_tree_mode; |
114 | | |
115 | 0 | window_pane_set_mode(wp, NULL, mode, target, args); |
116 | 0 | return (CMD_RETURN_NORMAL); |
117 | 0 | } |