GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/tmux/cmd-select-pane.c Lines: 0 75 0.0 %
Date: 2016-12-06 Branches: 0 58 0.0 %

Line Branch Exec Source
1
/* $OpenBSD: cmd-select-pane.c,v 1.32 2016/01/19 15:59:12 nicm Exp $ */
2
3
/*
4
 * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
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
 * Select pane.
25
 */
26
27
enum cmd_retval	 cmd_select_pane_exec(struct cmd *, struct cmd_q *);
28
29
const struct cmd_entry cmd_select_pane_entry = {
30
	.name = "select-pane",
31
	.alias = "selectp",
32
33
	.args = { "DdegLlMmP:Rt:U", 0, 0 },
34
	.usage = "[-DdegLlMmRU] [-P style] " CMD_TARGET_PANE_USAGE,
35
36
	.tflag = CMD_PANE,
37
38
	.flags = 0,
39
	.exec = cmd_select_pane_exec
40
};
41
42
const struct cmd_entry cmd_last_pane_entry = {
43
	.name = "last-pane",
44
	.alias = "lastp",
45
46
	.args = { "det:", 0, 0 },
47
	.usage = "[-de] " CMD_TARGET_WINDOW_USAGE,
48
49
	.tflag = CMD_WINDOW,
50
51
	.flags = 0,
52
	.exec = cmd_select_pane_exec
53
};
54
55
enum cmd_retval
56
cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
57
{
58
	struct args		*args = self->args;
59
	struct winlink		*wl = cmdq->state.tflag.wl;
60
	struct window		*w = wl->window;
61
	struct session		*s = cmdq->state.tflag.s;
62
	struct window_pane	*wp = cmdq->state.tflag.wp, *lastwp, *markedwp;
63
	const char		*style;
64
65
	if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
66
67
		if (wl->window->last == NULL) {
68
			cmdq_error(cmdq, "no last pane");
69
			return (CMD_RETURN_ERROR);
70
		}
71
72
		if (args_has(self->args, 'e'))
73
			w->last->flags &= ~PANE_INPUTOFF;
74
		else if (args_has(self->args, 'd'))
75
			w->last->flags |= PANE_INPUTOFF;
76
		else {
77
			server_unzoom_window(w);
78
			window_redraw_active_switch(w, w->last);
79
			if (window_set_active_pane(w, w->last)) {
80
				server_status_window(w);
81
				server_redraw_window_borders(w);
82
			}
83
		}
84
85
		return (CMD_RETURN_NORMAL);
86
	}
87
88
	if (args_has(args, 'm') || args_has(args, 'M')) {
89
		if (args_has(args, 'm') && !window_pane_visible(wp))
90
			return (CMD_RETURN_NORMAL);
91
		lastwp = marked_pane.wp;
92
93
		if (args_has(args, 'M') || server_is_marked(s, wl, wp))
94
			server_clear_marked();
95
		else
96
			server_set_marked(s, wl, wp);
97
		markedwp = marked_pane.wp;
98
99
		if (lastwp != NULL) {
100
			server_redraw_window_borders(lastwp->window);
101
			server_status_window(lastwp->window);
102
		}
103
		if (markedwp != NULL) {
104
			server_redraw_window_borders(markedwp->window);
105
			server_status_window(markedwp->window);
106
		}
107
		return (CMD_RETURN_NORMAL);
108
	}
109
110
	if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
111
		if (args_has(args, 'P')) {
112
			style = args_get(args, 'P');
113
			if (style_parse(&grid_default_cell, &wp->colgc,
114
			    style) == -1) {
115
				cmdq_error(cmdq, "bad style: %s", style);
116
				return (CMD_RETURN_ERROR);
117
			}
118
			wp->flags |= PANE_REDRAW;
119
		}
120
		if (args_has(self->args, 'g'))
121
			cmdq_print(cmdq, "%s", style_tostring(&wp->colgc));
122
		return (CMD_RETURN_NORMAL);
123
	}
124
125
	if (args_has(self->args, 'L')) {
126
		server_unzoom_window(wp->window);
127
		wp = window_pane_find_left(wp);
128
	} else if (args_has(self->args, 'R')) {
129
		server_unzoom_window(wp->window);
130
		wp = window_pane_find_right(wp);
131
	} else if (args_has(self->args, 'U')) {
132
		server_unzoom_window(wp->window);
133
		wp = window_pane_find_up(wp);
134
	} else if (args_has(self->args, 'D')) {
135
		server_unzoom_window(wp->window);
136
		wp = window_pane_find_down(wp);
137
	}
138
	if (wp == NULL)
139
		return (CMD_RETURN_NORMAL);
140
141
	if (args_has(self->args, 'e')) {
142
		wp->flags &= ~PANE_INPUTOFF;
143
		return (CMD_RETURN_NORMAL);
144
	}
145
	if (args_has(self->args, 'd')) {
146
		wp->flags |= PANE_INPUTOFF;
147
		return (CMD_RETURN_NORMAL);
148
	}
149
150
	if (wp == w->active)
151
		return (CMD_RETURN_NORMAL);
152
	server_unzoom_window(wp->window);
153
	if (!window_pane_visible(wp)) {
154
		cmdq_error(cmdq, "pane not visible");
155
		return (CMD_RETURN_ERROR);
156
	}
157
	window_redraw_active_switch(w, wp);
158
	if (window_set_active_pane(w, wp)) {
159
		server_status_window(w);
160
		server_redraw_window_borders(w);
161
	}
162
163
	return (CMD_RETURN_NORMAL);
164
}