Move the cursor back into the last column on CUU/CUD to match xterm
[tmux-openbsd.git] / cmd-select-pane.c
blob77be368f77e8654da3e045687ad7121e8c946356
1 /* $OpenBSD$ */
3 /*
4 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
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 * Select pane.
27 void cmd_select_pane_key_binding(struct cmd *, int);
28 enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *);
30 const struct cmd_entry cmd_select_pane_entry = {
31 "select-pane", "selectp",
32 "lDLRt:U", 0, 0,
33 "[-lDLRU] " CMD_TARGET_PANE_USAGE,
35 cmd_select_pane_key_binding,
36 NULL,
37 cmd_select_pane_exec
40 const struct cmd_entry cmd_last_pane_entry = {
41 "last-pane", "lastp",
42 "t:", 0, 0,
43 CMD_TARGET_WINDOW_USAGE,
45 NULL,
46 NULL,
47 cmd_select_pane_exec
50 void
51 cmd_select_pane_key_binding(struct cmd *self, int key)
53 self->args = args_create(0);
54 if (key == KEYC_UP)
55 args_set(self->args, 'U', NULL);
56 if (key == KEYC_DOWN)
57 args_set(self->args, 'D', NULL);
58 if (key == KEYC_LEFT)
59 args_set(self->args, 'L', NULL);
60 if (key == KEYC_RIGHT)
61 args_set(self->args, 'R', NULL);
62 if (key == 'o')
63 args_set(self->args, 't', ":.+");
66 enum cmd_retval
67 cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
69 struct args *args = self->args;
70 struct winlink *wl;
71 struct window_pane *wp;
73 if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
74 wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
75 if (wl == NULL)
76 return (CMD_RETURN_ERROR);
78 if (wl->window->last == NULL) {
79 cmdq_error(cmdq, "no last pane");
80 return (CMD_RETURN_ERROR);
83 server_unzoom_window(wl->window);
84 window_set_active_pane(wl->window, wl->window->last);
85 server_status_window(wl->window);
86 server_redraw_window_borders(wl->window);
88 return (CMD_RETURN_NORMAL);
91 if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
92 return (CMD_RETURN_ERROR);
94 server_unzoom_window(wp->window);
95 if (!window_pane_visible(wp)) {
96 cmdq_error(cmdq, "pane not visible");
97 return (CMD_RETURN_ERROR);
100 if (args_has(self->args, 'L'))
101 wp = window_pane_find_left(wp);
102 else if (args_has(self->args, 'R'))
103 wp = window_pane_find_right(wp);
104 else if (args_has(self->args, 'U'))
105 wp = window_pane_find_up(wp);
106 else if (args_has(self->args, 'D'))
107 wp = window_pane_find_down(wp);
108 if (wp == NULL) {
109 cmdq_error(cmdq, "pane not found");
110 return (CMD_RETURN_ERROR);
113 window_set_active_pane(wl->window, wp);
114 server_status_window(wl->window);
115 server_redraw_window_borders(wl->window);
117 return (CMD_RETURN_NORMAL);