/src/tmux/cmd-choose-tree.c
Line | Count | Source |
1 | | /* $OpenBSD: cmd-choose-tree.c,v 1.58 2026/07/14 17:17:17 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 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:GhK:kNO:rst:wyZ", 0, 1, cmd_choose_tree_args_parse }, |
37 | | .usage = "[-GhkNrswZ] [-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:hiK:kNO:rt:yZ", 0, 1, cmd_choose_tree_args_parse }, |
51 | | .usage = "[-hikNrZ] [-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:kNO:rt:yZ", 0, 1, cmd_choose_tree_args_parse }, |
65 | | .usage = "[-kNrZ] [-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:kNt:yZ", 0, 0, NULL }, |
79 | | .usage = "[-kNZ] [-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 | | const struct cmd_entry cmd_switch_mode_entry = { |
88 | | .name = "switch-mode", |
89 | | .alias = NULL, |
90 | | |
91 | | .args = { "F:kst:wZ", 0, 1, cmd_choose_tree_args_parse }, |
92 | | .usage = "[-kswZ] [-F format] " CMD_TARGET_PANE_USAGE " [command]", |
93 | | |
94 | | .target = { 't', CMD_FIND_PANE, 0 }, |
95 | | |
96 | | .flags = 0, |
97 | | .exec = cmd_choose_tree_exec |
98 | | }; |
99 | | |
100 | | const struct cmd_entry cmd_display_panes_entry = { |
101 | | .name = "display-panes", |
102 | | .alias = "displayp", |
103 | | |
104 | | .args = { "d:kNs:t:Z", 0, 1, cmd_choose_tree_args_parse }, |
105 | | .usage = "[-kNZ] [-d duration] [-s source-window] " |
106 | | CMD_TARGET_PANE_USAGE " [template]", |
107 | | |
108 | | .source = { 's', CMD_FIND_WINDOW, 0 }, |
109 | | .target = { 't', CMD_FIND_PANE, 0 }, |
110 | | |
111 | | .flags = CMD_AFTERHOOK, |
112 | | .exec = cmd_choose_tree_exec |
113 | | }; |
114 | | |
115 | | static enum args_parse_type |
116 | | cmd_choose_tree_args_parse(__unused struct args *args, __unused u_int idx, |
117 | | __unused char **cause) |
118 | 0 | { |
119 | 0 | return (ARGS_PARSE_COMMANDS_OR_STRING); |
120 | 0 | } |
121 | | |
122 | | static enum cmd_retval |
123 | | cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item) |
124 | 0 | { |
125 | 0 | struct args *args = cmd_get_args(self); |
126 | 0 | struct cmd_find_state *target = cmdq_get_target(item); |
127 | 0 | struct window_pane *wp = target->wp; |
128 | 0 | const struct window_mode *mode; |
129 | 0 | enum sort_order order; |
130 | |
|
131 | 0 | order = sort_order_from_string(args_get(args, 'O')); |
132 | 0 | if (order == SORT_END && args_has(args, 'O')) { |
133 | 0 | cmdq_error(item, "invalid sort order"); |
134 | 0 | return (CMD_RETURN_ERROR); |
135 | 0 | } |
136 | | |
137 | 0 | if (cmd_get_entry(self) == &cmd_choose_buffer_entry) { |
138 | 0 | if (paste_is_empty()) |
139 | 0 | return (CMD_RETURN_NORMAL); |
140 | 0 | mode = &window_buffer_mode; |
141 | 0 | } else if (cmd_get_entry(self) == &cmd_choose_client_entry) { |
142 | 0 | if (server_client_how_many() == 0) |
143 | 0 | return (CMD_RETURN_NORMAL); |
144 | 0 | mode = &window_client_mode; |
145 | 0 | } else if (cmd_get_entry(self) == &cmd_customize_mode_entry) |
146 | 0 | mode = &window_customize_mode; |
147 | 0 | else if (cmd_get_entry(self) == &cmd_switch_mode_entry) |
148 | 0 | mode = &window_switch_mode; |
149 | 0 | else if (cmd_get_entry(self) == &cmd_display_panes_entry) |
150 | 0 | mode = &window_panes_mode; |
151 | 0 | else |
152 | 0 | mode = &window_tree_mode; |
153 | | |
154 | 0 | window_pane_set_mode(wp, NULL, mode, item, target, args); |
155 | 0 | return (CMD_RETURN_NORMAL); |
156 | 0 | } |