xref: /openbsd-src/usr.bin/tmux/tmux.h (revision 4c1e55dc91edd6e69ccc60ce855900fbc12cf34f)
1 /* $OpenBSD: tmux.h,v 1.349 2012/07/13 06:27:41 nicm Exp $ */
2 
3 /*
4  * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
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 #ifndef TMUX_H
20 #define TMUX_H
21 
22 #define PROTOCOL_VERSION 7
23 
24 #include <sys/param.h>
25 #include <sys/time.h>
26 #include <sys/queue.h>
27 #include <sys/tree.h>
28 #include <sys/uio.h>
29 
30 #include <bitstring.h>
31 #include <event.h>
32 #include <getopt.h>
33 #include <imsg.h>
34 #include <limits.h>
35 #include <signal.h>
36 #include <stdarg.h>
37 #include <stdint.h>
38 #include <stdio.h>
39 #include <termios.h>
40 
41 #include "array.h"
42 
43 extern char    *__progname;
44 extern char   **environ;
45 
46 /* Default configuration files. */
47 #define DEFAULT_CFG ".tmux.conf"
48 #define SYSTEM_CFG "/etc/tmux.conf"
49 
50 /* Default prompt history length. */
51 #define PROMPT_HISTORY 100
52 
53 /*
54  * Minimum layout cell size, NOT including separator line. The scroll region
55  * cannot be one line in height so this must be at least two.
56  */
57 #define PANE_MINIMUM 2
58 
59 /* Automatic name refresh interval, in milliseconds. */
60 #define NAME_INTERVAL 500
61 
62 /*
63  * Maximum sizes of strings in message data. Don't forget to bump
64  * PROTOCOL_VERSION if any of these change!
65  */
66 #define COMMAND_LENGTH 2048	/* packed argv size */
67 #define TERMINAL_LENGTH 128	/* length of TERM environment variable */
68 #define ENVIRON_LENGTH 1024	/* environment variable length */
69 
70 /*
71  * UTF-8 data size. This must be big enough to hold combined characters as well
72  * as single.
73  */
74 #define UTF8_SIZE 9
75 
76 /* Fatal errors. */
77 #define fatal(msg) log_fatal("%s: %s", __func__, msg);
78 #define fatalx(msg) log_fatalx("%s: %s", __func__, msg);
79 
80 /* Definition to shut gcc up about unused arguments. */
81 #define unused __attribute__ ((unused))
82 
83 /* Attribute to make gcc check printf-like arguments. */
84 #define printflike1 __attribute__ ((format (printf, 1, 2)))
85 #define printflike2 __attribute__ ((format (printf, 2, 3)))
86 #define printflike3 __attribute__ ((format (printf, 3, 4)))
87 #define printflike4 __attribute__ ((format (printf, 4, 5)))
88 #define printflike5 __attribute__ ((format (printf, 5, 6)))
89 
90 /* Number of items in array. */
91 #ifndef nitems
92 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
93 #endif
94 
95 /* Default format templates. */
96 #define DEFAULT_BUFFER_LIST_TEMPLATE				\
97 	"#{line}: #{buffer_size} bytes: \"#{buffer_sample}\""
98 #define DEFAULT_CLIENT_TEMPLATE					\
99 	"#{client_tty}: #{session_name} "			\
100 	"[#{client_width}x#{client_height} #{client_termname}]"	\
101 	"#{?client_utf8, (utf8),} #{?client_readonly, (ro),}"
102 #define DEFAULT_DISPLAY_MESSAGE_TEMPLATE			\
103 	"[#{session_name}] #{window_index}:"			\
104 	"#{window_name}, current pane #{pane_index} "		\
105 	"- (%H:%M %d-%b-%y)"
106 #define DEFAULT_FIND_WINDOW_TEMPLATE				\
107 	"#{window_index}: #{window_name} "			\
108 	"[#{window_width}x#{window_height}] "			\
109 	"(#{window_panes} panes) #{window_find_matches}"
110 #define DEFAULT_SESSION_TEMPLATE \
111 	"#{session_name}: #{session_windows} windows "		\
112 	"(created #{session_created_string}) "			\
113 	"[#{session_width}x#{session_height}]"			\
114 	"#{?session_grouped, (group ,}"				\
115 	"#{session_group}#{?session_grouped,),}"		\
116 	"#{?session_attached, (attached),}"
117 #define DEFAULT_WINDOW_TEMPLATE					\
118 	"#{window_index}: #{window_name}#{window_flags} "	\
119 	"(#{window_panes} panes) "				\
120 	"[#{window_width}x#{window_height}]"
121 #define DEFAULT_PANE_INFO_TEMPLATE				\
122 	"#{session_name}:#{window_index}.#{pane_index}"
123 
124 /* Bell option values. */
125 #define BELL_NONE 0
126 #define BELL_ANY 1
127 #define BELL_CURRENT 2
128 
129 /* Special key codes. */
130 #define KEYC_NONE 0xfff
131 #define KEYC_BASE 0x1000
132 
133 /* Key modifier bits. */
134 #define KEYC_ESCAPE 0x2000
135 #define KEYC_CTRL 0x4000
136 #define KEYC_SHIFT 0x8000
137 #define KEYC_PREFIX 0x10000
138 
139 /* Mask to obtain key w/o modifiers. */
140 #define KEYC_MASK_MOD (KEYC_ESCAPE|KEYC_CTRL|KEYC_SHIFT|KEYC_PREFIX)
141 #define KEYC_MASK_KEY (~KEYC_MASK_MOD)
142 
143 /* Other key codes. */
144 enum key_code {
145 	/* Mouse key. */
146 	KEYC_MOUSE = KEYC_BASE,
147 
148 	/* Backspace key. */
149 	KEYC_BSPACE,
150 
151 	/* Function keys. */
152 	KEYC_F1,
153 	KEYC_F2,
154 	KEYC_F3,
155 	KEYC_F4,
156 	KEYC_F5,
157 	KEYC_F6,
158 	KEYC_F7,
159 	KEYC_F8,
160 	KEYC_F9,
161 	KEYC_F10,
162 	KEYC_F11,
163 	KEYC_F12,
164 	KEYC_F13,
165 	KEYC_F14,
166 	KEYC_F15,
167 	KEYC_F16,
168 	KEYC_F17,
169 	KEYC_F18,
170 	KEYC_F19,
171 	KEYC_F20,
172 	KEYC_IC,
173 	KEYC_DC,
174 	KEYC_HOME,
175 	KEYC_END,
176 	KEYC_NPAGE,
177 	KEYC_PPAGE,
178 	KEYC_BTAB,
179 
180 	/* Arrow keys. */
181 	KEYC_UP,
182 	KEYC_DOWN,
183 	KEYC_LEFT,
184 	KEYC_RIGHT,
185 
186 	/* Numeric keypad. */
187 	KEYC_KP_SLASH,
188 	KEYC_KP_STAR,
189 	KEYC_KP_MINUS,
190 	KEYC_KP_SEVEN,
191 	KEYC_KP_EIGHT,
192 	KEYC_KP_NINE,
193 	KEYC_KP_PLUS,
194 	KEYC_KP_FOUR,
195 	KEYC_KP_FIVE,
196 	KEYC_KP_SIX,
197 	KEYC_KP_ONE,
198 	KEYC_KP_TWO,
199 	KEYC_KP_THREE,
200 	KEYC_KP_ENTER,
201 	KEYC_KP_ZERO,
202 	KEYC_KP_PERIOD,
203 };
204 
205 /* Termcap codes. */
206 enum tty_code_code {
207 	TTYC_AX = 0,
208 	TTYC_ACSC,	/* acs_chars, ac */
209 	TTYC_BEL,	/* bell, bl */
210 	TTYC_BLINK,	/* enter_blink_mode, mb */
211 	TTYC_BOLD,	/* enter_bold_mode, md */
212 	TTYC_CC,	/* set colour cursor, Cc */
213 	TTYC_CIVIS,	/* cursor_invisible, vi */
214 	TTYC_CLEAR,	/* clear_screen, cl */
215 	TTYC_CNORM,	/* cursor_normal, ve */
216 	TTYC_COLORS,	/* max_colors, Co */
217 	TTYC_CR,	/* restore cursor colour, Cr */
218 	TTYC_CS1,	/* set cursor style, Cs */
219 	TTYC_CSR,	/* change_scroll_region, cs */
220 	TTYC_CSR1,	/* reset cursor style, Csr */
221 	TTYC_CUB,	/* parm_left_cursor, LE */
222 	TTYC_CUB1,	/* cursor_left, le */
223 	TTYC_CUD,	/* parm_down_cursor, DO */
224 	TTYC_CUD1,	/* cursor_down, do */
225 	TTYC_CUF,	/* parm_right_cursor, RI */
226 	TTYC_CUF1,	/* cursor_right, nd */
227 	TTYC_CUP,	/* cursor_address, cm */
228 	TTYC_CUU,	/* parm_up_cursor, UP */
229 	TTYC_CUU1,	/* cursor_up, up */
230 	TTYC_DCH,	/* parm_dch, DC */
231 	TTYC_DCH1,	/* delete_character, dc */
232 	TTYC_DIM,	/* enter_dim_mode, mh */
233 	TTYC_DL,	/* parm_delete_line, DL */
234 	TTYC_DL1,	/* delete_line, dl */
235 	TTYC_E3,
236 	TTYC_EL,	/* clr_eol, ce */
237 	TTYC_EL1,	/* clr_bol, cb */
238 	TTYC_ENACS,	/* ena_acs, eA */
239 	TTYC_FSL,	/* from_status_line, fsl */
240 	TTYC_HOME,	/* cursor_home, ho */
241 	TTYC_HPA,	/* column_address, ch */
242 	TTYC_ICH,	/* parm_ich, IC */
243 	TTYC_ICH1,	/* insert_character, ic */
244 	TTYC_IL,	/* parm_insert_line, IL */
245 	TTYC_IL1,	/* insert_line, il */
246 	TTYC_INVIS,	/* enter_secure_mode, mk */
247 	TTYC_IS1,	/* init_1string, i1 */
248 	TTYC_IS2,	/* init_2string, i2 */
249 	TTYC_IS3,	/* init_3string, i3 */
250 	TTYC_KCBT,	/* key_btab, kB */
251 	TTYC_KCUB1,	/* key_left, kl */
252 	TTYC_KCUD1,	/* key_down, kd */
253 	TTYC_KCUF1,	/* key_right, kr */
254 	TTYC_KCUU1,	/* key_up, ku */
255 	TTYC_KDC2,
256 	TTYC_KDC3,
257 	TTYC_KDC4,
258 	TTYC_KDC5,
259 	TTYC_KDC6,
260 	TTYC_KDC7,
261 	TTYC_KDCH1,	/* key_dc, kD */
262 	TTYC_KDN2,
263 	TTYC_KDN3,
264 	TTYC_KDN4,
265 	TTYC_KDN5,
266 	TTYC_KDN6,
267 	TTYC_KDN7,
268 	TTYC_KEND,	/* key_end, ke */
269 	TTYC_KEND2,
270 	TTYC_KEND3,
271 	TTYC_KEND4,
272 	TTYC_KEND5,
273 	TTYC_KEND6,
274 	TTYC_KEND7,
275 	TTYC_KF1,	/* key_f1, k1 */
276 	TTYC_KF10,	/* key_f10, k; */
277 	TTYC_KF11,	/* key_f11, F1 */
278 	TTYC_KF12,	/* key_f12, F2 */
279 	TTYC_KF13,	/* key_f13, F3 */
280 	TTYC_KF14,	/* key_f14, F4 */
281 	TTYC_KF15,	/* key_f15, F5 */
282 	TTYC_KF16,	/* key_f16, F6 */
283 	TTYC_KF17,	/* key_f17, F7 */
284 	TTYC_KF18,	/* key_f18, F8 */
285 	TTYC_KF19,	/* key_f19, F9 */
286 	TTYC_KF2,	/* key_f2, k2 */
287 	TTYC_KF20,	/* key_f20, F10 */
288 	TTYC_KF3,	/* key_f3, k3 */
289 	TTYC_KF4,	/* key_f4, k4 */
290 	TTYC_KF5,	/* key_f5, k5 */
291 	TTYC_KF6,	/* key_f6, k6 */
292 	TTYC_KF7,	/* key_f7, k7 */
293 	TTYC_KF8,	/* key_f8, k8 */
294 	TTYC_KF9,	/* key_f9, k9 */
295 	TTYC_KHOM2,
296 	TTYC_KHOM3,
297 	TTYC_KHOM4,
298 	TTYC_KHOM5,
299 	TTYC_KHOM6,
300 	TTYC_KHOM7,
301 	TTYC_KHOME,	/* key_home, kh */
302 	TTYC_KIC2,
303 	TTYC_KIC3,
304 	TTYC_KIC4,
305 	TTYC_KIC5,
306 	TTYC_KIC6,
307 	TTYC_KIC7,
308 	TTYC_KICH1,	/* key_ic, kI */
309 	TTYC_KLFT2,
310 	TTYC_KLFT3,
311 	TTYC_KLFT4,
312 	TTYC_KLFT5,
313 	TTYC_KLFT6,
314 	TTYC_KLFT7,
315 	TTYC_KMOUS,	/* key_mouse, Km */
316 	TTYC_KNP,	/* key_npage, kN */
317 	TTYC_KNXT2,
318 	TTYC_KNXT3,
319 	TTYC_KNXT4,
320 	TTYC_KNXT5,
321 	TTYC_KNXT6,
322 	TTYC_KNXT7,
323 	TTYC_KPP,	/* key_ppage, kP */
324 	TTYC_KPRV2,
325 	TTYC_KPRV3,
326 	TTYC_KPRV4,
327 	TTYC_KPRV5,
328 	TTYC_KPRV6,
329 	TTYC_KPRV7,
330 	TTYC_KRIT2,
331 	TTYC_KRIT3,
332 	TTYC_KRIT4,
333 	TTYC_KRIT5,
334 	TTYC_KRIT6,
335 	TTYC_KRIT7,
336 	TTYC_KUP2,
337 	TTYC_KUP3,
338 	TTYC_KUP4,
339 	TTYC_KUP5,
340 	TTYC_KUP6,
341 	TTYC_KUP7,
342 	TTYC_MS,	/* modify xterm(1) selection */
343 	TTYC_OP,	/* orig_pair, op */
344 	TTYC_REV,	/* enter_reverse_mode, mr */
345 	TTYC_RI,	/* scroll_reverse, sr */
346 	TTYC_RMACS,	/* exit_alt_charset_mode */
347 	TTYC_RMCUP,	/* exit_ca_mode, te */
348 	TTYC_RMKX,	/* keypad_local, ke */
349 	TTYC_SETAB,	/* set_a_background, AB */
350 	TTYC_SETAF,	/* set_a_foreground, AF */
351 	TTYC_SGR0,	/* exit_attribute_mode, me */
352 	TTYC_SITM,	/* enter_italics_mode, it */
353 	TTYC_SMACS,	/* enter_alt_charset_mode, as */
354 	TTYC_SMCUP,	/* enter_ca_mode, ti */
355 	TTYC_SMKX,	/* keypad_xmit, ks */
356 	TTYC_SMSO,	/* enter_standout_mode, so */
357 	TTYC_SMUL,	/* enter_underline_mode, us */
358 	TTYC_TSL,	/* to_status_line, tsl */
359 	TTYC_VPA,	/* row_address, cv */
360 	TTYC_XENL,	/* eat_newline_glitch, xn */
361 	TTYC_XT,	/* xterm(1)-compatible title, XT */
362 };
363 #define NTTYCODE (TTYC_XT + 1)
364 
365 /* Termcap types. */
366 enum tty_code_type {
367 	TTYCODE_NONE = 0,
368 	TTYCODE_STRING,
369 	TTYCODE_NUMBER,
370 	TTYCODE_FLAG,
371 };
372 
373 /* Termcap code. */
374 struct tty_code {
375 	enum tty_code_type	type;
376 	union {
377 		char	       *string;
378 		int		number;
379 		int		flag;
380 	} value;
381 };
382 
383 /* Entry in terminal code table. */
384 struct tty_term_code_entry {
385 	enum tty_code_code	code;
386 	enum tty_code_type	type;
387 	const char	       *name;
388 };
389 
390 /* Message codes. */
391 enum msgtype {
392 	MSG_COMMAND,
393 	MSG_DETACH,
394 	MSG_ERROR,
395 	MSG_EXIT,
396 	MSG_EXITED,
397 	MSG_EXITING,
398 	MSG_IDENTIFY,
399 	MSG_STDIN,
400 	MSG_READY,
401 	MSG_RESIZE,
402 	MSG_SHUTDOWN,
403 	MSG_SUSPEND,
404 	MSG_VERSION,
405 	MSG_WAKEUP,
406 	MSG_ENVIRON,
407 	MSG_UNLOCK,
408 	MSG_LOCK,
409 	MSG_SHELL,
410 	MSG_STDERR,
411 	MSG_STDOUT,
412 	MSG_DETACHKILL
413 };
414 
415 /*
416  * Message data.
417  *
418  * Don't forget to bump PROTOCOL_VERSION if any of these change!
419  */
420 struct msg_command_data {
421 	pid_t		pid;	/* PID from $TMUX or -1 */
422 	int		idx;	/* index from $TMUX or -1 */
423 
424 	int		argc;
425 	char		argv[COMMAND_LENGTH];
426 };
427 
428 struct msg_identify_data {
429 	char		cwd[MAXPATHLEN];
430 
431 	char		term[TERMINAL_LENGTH];
432 
433 #define IDENTIFY_UTF8 0x1
434 #define IDENTIFY_256COLOURS 0x2
435 #define IDENTIFY_88COLOURS 0x4
436 #define IDENTIFY_CONTROL 0x8
437 #define IDENTIFY_TERMIOS 0x10
438 	int		flags;
439 };
440 
441 struct msg_lock_data {
442 	char		cmd[COMMAND_LENGTH];
443 };
444 
445 struct msg_environ_data {
446 	char		var[ENVIRON_LENGTH];
447 };
448 
449 struct msg_shell_data {
450 	char		shell[MAXPATHLEN];
451 };
452 
453 struct msg_exit_data {
454 	int		retcode;
455 };
456 
457 struct msg_stdin_data {
458 	ssize_t	size;
459 	char	data[BUFSIZ];
460 };
461 
462 struct msg_stdout_data {
463 	ssize_t	size;
464 	char	data[BUFSIZ];
465 };
466 
467 struct msg_stderr_data {
468 	ssize_t	size;
469 	char	data[BUFSIZ];
470 };
471 
472 /* Mode key commands. */
473 enum mode_key_cmd {
474 	MODEKEY_NONE,
475 	MODEKEY_OTHER,
476 
477 	/* Editing keys. */
478 	MODEKEYEDIT_BACKSPACE,
479 	MODEKEYEDIT_CANCEL,
480 	MODEKEYEDIT_COMPLETE,
481 	MODEKEYEDIT_CURSORLEFT,
482 	MODEKEYEDIT_CURSORRIGHT,
483 	MODEKEYEDIT_DELETE,
484 	MODEKEYEDIT_DELETELINE,
485 	MODEKEYEDIT_DELETETOENDOFLINE,
486 	MODEKEYEDIT_DELETEWORD,
487 	MODEKEYEDIT_ENDOFLINE,
488 	MODEKEYEDIT_ENTER,
489 	MODEKEYEDIT_HISTORYDOWN,
490 	MODEKEYEDIT_HISTORYUP,
491 	MODEKEYEDIT_NEXTSPACE,
492 	MODEKEYEDIT_NEXTSPACEEND,
493 	MODEKEYEDIT_NEXTWORD,
494 	MODEKEYEDIT_NEXTWORDEND,
495 	MODEKEYEDIT_PASTE,
496 	MODEKEYEDIT_PREVIOUSSPACE,
497 	MODEKEYEDIT_PREVIOUSWORD,
498 	MODEKEYEDIT_STARTOFLINE,
499 	MODEKEYEDIT_SWITCHMODE,
500 	MODEKEYEDIT_SWITCHMODEAPPEND,
501 	MODEKEYEDIT_SWITCHMODEAPPENDLINE,
502 	MODEKEYEDIT_SWITCHMODEBEGINLINE,
503 	MODEKEYEDIT_TRANSPOSECHARS,
504 
505 	/* Menu (choice) keys. */
506 	MODEKEYCHOICE_CANCEL,
507 	MODEKEYCHOICE_CHOOSE,
508 	MODEKEYCHOICE_DOWN,
509 	MODEKEYCHOICE_PAGEDOWN,
510 	MODEKEYCHOICE_PAGEUP,
511 	MODEKEYCHOICE_SCROLLDOWN,
512 	MODEKEYCHOICE_SCROLLUP,
513 	MODEKEYCHOICE_UP,
514 
515 	/* Copy keys. */
516 	MODEKEYCOPY_BACKTOINDENTATION,
517 	MODEKEYCOPY_BOTTOMLINE,
518 	MODEKEYCOPY_CANCEL,
519 	MODEKEYCOPY_CLEARSELECTION,
520 	MODEKEYCOPY_COPYLINE,
521 	MODEKEYCOPY_COPYENDOFLINE,
522 	MODEKEYCOPY_COPYSELECTION,
523 	MODEKEYCOPY_DOWN,
524 	MODEKEYCOPY_ENDOFLINE,
525 	MODEKEYCOPY_GOTOLINE,
526 	MODEKEYCOPY_HALFPAGEDOWN,
527 	MODEKEYCOPY_HALFPAGEUP,
528 	MODEKEYCOPY_HISTORYBOTTOM,
529 	MODEKEYCOPY_HISTORYTOP,
530 	MODEKEYCOPY_JUMP,
531 	MODEKEYCOPY_JUMPAGAIN,
532 	MODEKEYCOPY_JUMPREVERSE,
533 	MODEKEYCOPY_JUMPBACK,
534 	MODEKEYCOPY_JUMPTO,
535 	MODEKEYCOPY_JUMPTOBACK,
536 	MODEKEYCOPY_LEFT,
537 	MODEKEYCOPY_MIDDLELINE,
538 	MODEKEYCOPY_NEXTPAGE,
539 	MODEKEYCOPY_NEXTSPACE,
540 	MODEKEYCOPY_NEXTSPACEEND,
541 	MODEKEYCOPY_NEXTWORD,
542 	MODEKEYCOPY_NEXTWORDEND,
543 	MODEKEYCOPY_PREVIOUSPAGE,
544 	MODEKEYCOPY_PREVIOUSSPACE,
545 	MODEKEYCOPY_PREVIOUSWORD,
546 	MODEKEYCOPY_RECTANGLETOGGLE,
547 	MODEKEYCOPY_RIGHT,
548 	MODEKEYCOPY_SCROLLDOWN,
549 	MODEKEYCOPY_SCROLLUP,
550 	MODEKEYCOPY_SEARCHAGAIN,
551 	MODEKEYCOPY_SEARCHDOWN,
552 	MODEKEYCOPY_SEARCHREVERSE,
553 	MODEKEYCOPY_SEARCHUP,
554 	MODEKEYCOPY_SELECTLINE,
555 	MODEKEYCOPY_STARTNUMBERPREFIX,
556 	MODEKEYCOPY_STARTOFLINE,
557 	MODEKEYCOPY_STARTSELECTION,
558 	MODEKEYCOPY_TOPLINE,
559 	MODEKEYCOPY_UP,
560 };
561 
562 /* Entry in the default mode key tables. */
563 struct mode_key_entry {
564 	int			key;
565 
566 	/*
567 	 * Editing mode for vi: 0 is edit mode, keys not in the table are
568 	 * returned as MODEKEY_OTHER; 1 is command mode, keys not in the table
569 	 * are returned as MODEKEY_NONE. This is also matched on, allowing some
570 	 * keys to be bound in edit mode.
571 	 */
572 	int			mode;
573 	enum mode_key_cmd	cmd;
574 };
575 
576 /* Data required while mode keys are in use. */
577 struct mode_key_data {
578 	struct mode_key_tree   *tree;
579 	int			mode;
580 };
581 #define MODEKEY_EMACS 0
582 #define MODEKEY_VI 1
583 
584 /* Binding between a key and a command. */
585 struct mode_key_binding {
586 	int			key;
587 
588 	int			mode;
589 	enum mode_key_cmd	cmd;
590 
591 	RB_ENTRY(mode_key_binding) entry;
592 };
593 RB_HEAD(mode_key_tree, mode_key_binding);
594 
595 /* Command to string mapping. */
596 struct mode_key_cmdstr {
597 	enum mode_key_cmd	 cmd;
598 	const char		*name;
599 };
600 
601 /* Named mode key table description. */
602 struct mode_key_table {
603 	const char			*name;
604 	const struct mode_key_cmdstr	*cmdstr;
605 	struct mode_key_tree		*tree;
606 	const struct mode_key_entry	*table;	/* default entries */
607 };
608 
609 /* Modes. */
610 #define MODE_CURSOR 0x1
611 #define MODE_INSERT 0x2
612 #define MODE_KCURSOR 0x4
613 #define MODE_KKEYPAD 0x8	/* set = application, clear = number */
614 #define MODE_WRAP 0x10		/* whether lines wrap */
615 #define MODE_MOUSE_STANDARD 0x20
616 #define MODE_MOUSE_BUTTON 0x40
617 #define MODE_MOUSE_ANY 0x80
618 #define MODE_MOUSE_UTF8 0x100
619 #define MODE_BRACKETPASTE 0x200
620 
621 #define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ANY)
622 
623 /*
624  * A single UTF-8 character.
625  *
626  * The data member in this must be UTF8_SIZE to allow screen_write_copy to
627  * reinject stored UTF-8 data back into screen_write_cell after combining (ugh
628  * XXX XXX).
629  */
630 struct utf8_data {
631 	u_char	data[UTF8_SIZE];
632 
633 	size_t	have;
634 	size_t	size;
635 
636 	u_int	width;
637 };
638 
639 /* Grid output. */
640 #if defined(DEBUG) && \
641     ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
642      (defined(__GNUC__) && __GNUC__ >= 3))
643 #define GRID_DEBUG(gd, fmt, ...) log_debug2("%s: (sx=%u, sy=%u, hsize=%u) " \
644     fmt, __func__, (gd)->sx, (gd)->sy, (gd)->hsize, ## __VA_ARGS__)
645 #else
646 #define GRID_DEBUG(...)
647 #endif
648 
649 /* Grid attributes. */
650 #define GRID_ATTR_BRIGHT 0x1
651 #define GRID_ATTR_DIM 0x2
652 #define GRID_ATTR_UNDERSCORE 0x4
653 #define GRID_ATTR_BLINK 0x8
654 #define GRID_ATTR_REVERSE 0x10
655 #define GRID_ATTR_HIDDEN 0x20
656 #define GRID_ATTR_ITALICS 0x40
657 #define GRID_ATTR_CHARSET 0x80	/* alternative character set */
658 
659 /* Grid flags. */
660 #define GRID_FLAG_FG256 0x1
661 #define GRID_FLAG_BG256 0x2
662 #define GRID_FLAG_PADDING 0x4
663 #define GRID_FLAG_UTF8 0x8
664 
665 /* Grid line flags. */
666 #define GRID_LINE_WRAPPED 0x1
667 
668 /* Grid cell data. */
669 struct grid_cell {
670 	u_char	attr;
671 	u_char	flags;
672 	u_char	fg;
673 	u_char	bg;
674 	u_char	data;
675 } __packed;
676 
677 /* Grid cell UTF-8 data. Used instead of data in grid_cell for UTF-8 cells. */
678 struct grid_utf8 {
679 	u_char	width;
680 	u_char	data[UTF8_SIZE];
681 } __packed;
682 
683 /* Grid line. */
684 struct grid_line {
685 	u_int	cellsize;
686 	struct grid_cell *celldata;
687 
688 	u_int	utf8size;
689 	struct grid_utf8 *utf8data;
690 
691 	int	flags;
692 } __packed;
693 
694 /* Entire grid of cells. */
695 struct grid {
696 	int	flags;
697 #define GRID_HISTORY 0x1	/* scroll lines into history */
698 
699 	u_int	sx;
700 	u_int	sy;
701 
702 	u_int	hsize;
703 	u_int	hlimit;
704 
705 	struct grid_line *linedata;
706 };
707 
708 /* Option data structures. */
709 struct options_entry {
710 	char		*name;
711 
712 	enum {
713 		OPTIONS_STRING,
714 		OPTIONS_NUMBER,
715 		OPTIONS_DATA,
716 	} type;
717 
718 	char		*str;
719 	long long	 num;
720 
721 	RB_ENTRY(options_entry) entry;
722 };
723 
724 struct options {
725 	RB_HEAD(options_tree, options_entry) tree;
726 	struct options	*parent;
727 };
728 
729 /* Scheduled job. */
730 struct job {
731 	char		*cmd;
732 	pid_t		 pid;
733 	int		 status;
734 
735 	int		 fd;
736 	struct bufferevent *event;
737 
738 	void		(*callbackfn)(struct job *);
739 	void		(*freefn)(void *);
740 	void		*data;
741 
742 	LIST_ENTRY(job)	 lentry;
743 };
744 LIST_HEAD(joblist, job);
745 
746 /* Screen selection. */
747 struct screen_sel {
748 	int		 flag;
749 	int		 rectflag;
750 
751 	u_int		 sx;
752 	u_int		 sy;
753 
754 	u_int		 ex;
755 	u_int		 ey;
756 
757 	struct grid_cell cell;
758 };
759 
760 /* Virtual screen. */
761 struct screen {
762 	char		*title;
763 
764 	struct grid	*grid;		/* grid data */
765 
766 	u_int		 cx;		/* cursor x */
767 	u_int		 cy;		/* cursor y */
768 
769 	u_int		 cstyle;	/* cursor style */
770 	char		*ccolour;	/* cursor colour string */
771 
772 	u_int		 rupper;	/* scroll region top */
773 	u_int		 rlower;	/* scroll region bottom */
774 
775 	int		 mode;
776 
777 	bitstr_t	*tabs;
778 
779 	struct screen_sel sel;
780 };
781 
782 /* Screen write context. */
783 struct screen_write_ctx {
784 	struct window_pane *wp;
785 	struct screen	*s;
786 };
787 
788 /* Screen size. */
789 #define screen_size_x(s) ((s)->grid->sx)
790 #define screen_size_y(s) ((s)->grid->sy)
791 #define screen_hsize(s) ((s)->grid->hsize)
792 #define screen_hlimit(s) ((s)->grid->hlimit)
793 
794 /* Input parser context. */
795 struct input_ctx {
796 	struct window_pane     *wp;
797 	struct screen_write_ctx ctx;
798 
799 	struct grid_cell	cell;
800 
801 	struct grid_cell	old_cell;
802 	u_int 			old_cx;
803 	u_int			old_cy;
804 
805 	u_char			interm_buf[4];
806 	size_t			interm_len;
807 
808 	u_char			param_buf[64];
809 	size_t			param_len;
810 
811 	u_char			input_buf[256];
812 	size_t			input_len;
813 
814 	int			param_list[24];	/* -1 not present */
815 	u_int			param_list_len;
816 
817 	struct utf8_data	utf8data;
818 
819 	int			ch;
820 	int			flags;
821 #define INPUT_DISCARD 0x1
822 
823 	const struct input_state *state;
824 
825 	/*
826 	 * All input received since we were last in the ground state. Sent to
827 	 * control clients on connection.
828 	 */
829 	struct evbuffer	 	*since_ground;
830 };
831 
832 /*
833  * Window mode. Windows can be in several modes and this is used to call the
834  * right function to handle input and output.
835  */
836 struct session;
837 struct window;
838 struct mouse_event;
839 struct window_mode {
840 	struct screen *(*init)(struct window_pane *);
841 	void	(*free)(struct window_pane *);
842 	void	(*resize)(struct window_pane *, u_int, u_int);
843 	void	(*key)(struct window_pane *, struct session *, int);
844 	void	(*mouse)(struct window_pane *,
845 		    struct session *, struct mouse_event *);
846 	void	(*timer)(struct window_pane *);
847 };
848 
849 /* Structures for choose mode. */
850 struct window_choose_data {
851 	struct client		*client;
852 	struct session		*session;
853 	struct format_tree	*ft;
854 	char		        *ft_template;
855 	char			*command;
856 	u_int			 idx;
857 };
858 
859 struct window_choose_mode_item {
860     struct window_choose_data   *wcd;
861     char                        *name;
862 };
863 
864 /* Child window structure. */
865 struct window_pane {
866 	u_int		 id;
867 
868 	struct window	*window;
869 	struct layout_cell *layout_cell;
870 
871 	u_int		 sx;
872 	u_int		 sy;
873 
874 	u_int		 xoff;
875 	u_int		 yoff;
876 
877 	int		 flags;
878 #define PANE_REDRAW 0x1
879 #define PANE_DROP 0x2
880 
881 	char		*cmd;
882 	char		*shell;
883 	char		*cwd;
884 
885 	pid_t		 pid;
886 	char		 tty[TTY_NAME_MAX];
887 
888 	u_int		 changes;
889 	struct event	 changes_timer;
890 	u_int		 changes_redraw;
891 
892 	int		 fd;
893 	struct bufferevent *event;
894 
895 	struct input_ctx ictx;
896 
897 	int		 pipe_fd;
898 	struct bufferevent *pipe_event;
899 	size_t		 pipe_off;
900 
901 	struct screen	*screen;
902 	struct screen	 base;
903 
904 	/* Saved in alternative screen mode. */
905 	u_int		 saved_cx;
906 	u_int		 saved_cy;
907 	struct grid	*saved_grid;
908 	struct grid_cell saved_cell;
909 
910 	const struct window_mode *mode;
911 	void		*modedata;
912 
913 	TAILQ_ENTRY(window_pane) entry;
914 	RB_ENTRY(window_pane) tree_entry;
915 };
916 TAILQ_HEAD(window_panes, window_pane);
917 RB_HEAD(window_pane_tree, window_pane);
918 
919 /* Window last layout. */
920 struct last_layout {
921 	char	*layout;
922 
923 	TAILQ_ENTRY(last_layout) entry;
924 };
925 
926 /* Window structure. */
927 struct window {
928 	u_int		 id;
929 	char		*name;
930 	struct event	 name_timer;
931 	struct timeval   silence_timer;
932 
933 	struct window_pane *active;
934 	struct window_pane *last;
935 	struct window_panes panes;
936 
937 	int		 lastlayout;
938 	struct layout_cell *layout_root;
939 	TAILQ_HEAD(last_layouts, last_layout) layout_list;
940 	u_int		 layout_list_size;
941 	struct last_layout *layout_list_last;
942 
943 	u_int		 sx;
944 	u_int		 sy;
945 
946 	int		 flags;
947 #define WINDOW_BELL 0x1
948 #define WINDOW_ACTIVITY 0x2
949 #define WINDOW_REDRAW 0x4
950 #define WINDOW_SILENCE 0x8
951 
952 	struct options	 options;
953 
954 	u_int		 references;
955 };
956 ARRAY_DECL(windows, struct window *);
957 
958 /* Entry on local window list. */
959 struct winlink {
960 	int		 idx;
961 	struct window	*window;
962 
963 	size_t		 status_width;
964 	struct grid_cell status_cell;
965 	char		*status_text;
966 
967 	int              flags;
968 #define WINLINK_BELL 0x1
969 #define WINLINK_ACTIVITY 0x2
970 #define WINLINK_CONTENT 0x4
971 #define WINLINK_SILENCE 0x8
972 #define WINLINK_ALERTFLAGS \
973     (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_CONTENT|WINLINK_SILENCE)
974 
975 	RB_ENTRY(winlink) entry;
976 	TAILQ_ENTRY(winlink) sentry;
977 };
978 RB_HEAD(winlinks, winlink);
979 TAILQ_HEAD(winlink_stack, winlink);
980 
981 /* Layout direction. */
982 enum layout_type {
983 	LAYOUT_LEFTRIGHT,
984 	LAYOUT_TOPBOTTOM,
985 	LAYOUT_WINDOWPANE
986 };
987 
988 /* Layout cells queue. */
989 TAILQ_HEAD(layout_cells, layout_cell);
990 
991 /* Layout cell. */
992 struct layout_cell {
993 	enum layout_type type;
994 
995 	struct layout_cell *parent;
996 
997 	u_int		 sx;
998 	u_int		 sy;
999 
1000 	u_int		 xoff;
1001 	u_int		 yoff;
1002 
1003 	struct window_pane *wp;
1004 	struct layout_cells cells;
1005 
1006 	TAILQ_ENTRY(layout_cell) entry;
1007 };
1008 
1009 /* Paste buffer. */
1010 struct paste_buffer {
1011 	char		*data;
1012 	size_t		 size;
1013 };
1014 ARRAY_DECL(paste_stack, struct paste_buffer *);
1015 
1016 /* Environment variable. */
1017 struct environ_entry {
1018 	char		*name;
1019 	char		*value;
1020 
1021 	RB_ENTRY(environ_entry) entry;
1022 };
1023 RB_HEAD(environ, environ_entry);
1024 
1025 /* Client session. */
1026 struct session_group {
1027 	TAILQ_HEAD(, session) sessions;
1028 
1029 	TAILQ_ENTRY(session_group) entry;
1030 };
1031 TAILQ_HEAD(session_groups, session_group);
1032 
1033 struct session {
1034 	u_int		 idx;
1035 
1036 	char		*name;
1037 	char		*cwd;
1038 
1039 	struct timeval	 creation_time;
1040 	struct timeval	 activity_time;
1041 
1042 	u_int		 sx;
1043 	u_int		 sy;
1044 
1045 	struct winlink	*curw;
1046 	struct winlink_stack lastw;
1047 	struct winlinks	 windows;
1048 
1049 	struct options	 options;
1050 
1051 #define SESSION_UNATTACHED 0x1	/* not attached to any clients */
1052 	int		 flags;
1053 
1054 	struct termios	*tio;
1055 
1056 	struct environ	 environ;
1057 
1058 	int		 references;
1059 
1060 	TAILQ_ENTRY(session) gentry;
1061 	RB_ENTRY(session)    entry;
1062 };
1063 RB_HEAD(sessions, session);
1064 ARRAY_DECL(sessionslist, struct session *);
1065 
1066 /*
1067  * Mouse input. xterm mouse mode is fairly silly. Buttons are in the bottom two
1068  * bits: 0 = button 1; 1 = button 2; 2 = button 3; 3 = buttons released. Bits
1069  * 3, 4 and 5 are for keys. Bit 6 is set for dragging and 7 for mouse buttons 4
1070  * and 5.
1071  */
1072 struct mouse_event {
1073 	u_int	b;
1074 #define MOUSE_1 0
1075 #define MOUSE_2 1
1076 #define MOUSE_3 2
1077 #define MOUSE_UP 3
1078 #define MOUSE_BUTTON 3
1079 #define MOUSE_SHIFT 4
1080 #define MOUSE_ESCAPE 8
1081 #define MOUSE_CTRL 16
1082 #define MOUSE_DRAG 32
1083 #define MOUSE_45 64
1084 #define MOUSE_RESIZE_PANE 128 /* marker for resizing */
1085 	u_int	x;
1086 	u_int	y;
1087 };
1088 
1089 /* TTY information. */
1090 struct tty_key {
1091 	char		 ch;
1092 	int		 key;
1093 
1094 	struct tty_key	*left;
1095 	struct tty_key	*right;
1096 
1097 	struct tty_key	*next;
1098 };
1099 
1100 struct tty_term {
1101 	char		*name;
1102 	u_int		 references;
1103 
1104 	char		 acs[UCHAR_MAX + 1][2];
1105 
1106 	struct tty_code	 codes[NTTYCODE];
1107 
1108 #define TERM_256COLOURS 0x1
1109 #define TERM_88COLOURS 0x2
1110 #define TERM_EARLYWRAP 0x4
1111 	int		 flags;
1112 
1113 	LIST_ENTRY(tty_term) entry;
1114 };
1115 LIST_HEAD(tty_terms, tty_term);
1116 
1117 struct tty {
1118 	struct client	*client;
1119 
1120 	char		*path;
1121 	u_int		 xterm_version;
1122 
1123 	u_int		 sx;
1124 	u_int		 sy;
1125 
1126 	u_int		 cx;
1127 	u_int		 cy;
1128 	u_int		 cstyle;
1129 	char		*ccolour;
1130 
1131 	int		 mode;
1132 
1133 	u_int		 rlower;
1134 	u_int		 rupper;
1135 
1136 	char		*termname;
1137 	struct tty_term	*term;
1138 
1139 	int		 fd;
1140 	struct bufferevent *event;
1141 
1142 	int		 log_fd;
1143 
1144 	struct termios	 tio;
1145 
1146 	struct grid_cell cell;
1147 
1148 #define TTY_NOCURSOR 0x1
1149 #define TTY_FREEZE 0x2
1150 #define TTY_ESCAPE 0x4
1151 #define TTY_UTF8 0x8
1152 #define TTY_STARTED 0x10
1153 #define TTY_OPENED 0x20
1154 	int		 flags;
1155 
1156 	int		 term_flags;
1157 
1158 	struct mouse_event mouse;
1159 
1160 	struct event	 key_timer;
1161 	struct tty_key	*key_tree;
1162 };
1163 
1164 /* TTY command context and function pointer. */
1165 struct tty_ctx {
1166 	struct window_pane *wp;
1167 
1168 	const struct grid_cell *cell;
1169 	const struct grid_utf8 *utf8;
1170 
1171 	u_int		 num;
1172 	void		*ptr;
1173 
1174 	/*
1175 	 * Cursor and region position before the screen was updated - this is
1176 	 * where the command should be applied; the values in the screen have
1177 	 * already been updated.
1178 	 */
1179 	u_int		 ocx;
1180 	u_int		 ocy;
1181 
1182 	u_int		 orupper;
1183 	u_int		 orlower;
1184 
1185 	u_int		 xoff;
1186 	u_int		 yoff;
1187 
1188 	/* Saved last cell on line. */
1189 	struct grid_cell last_cell;
1190 	struct grid_utf8 last_utf8;
1191 	u_int		 last_width;
1192 };
1193 
1194 /* Saved message entry. */
1195 struct message_entry {
1196 	char   *msg;
1197 	time_t	msg_time;
1198 };
1199 
1200 /* Status output data from a job. */
1201 struct status_out {
1202 	char   *cmd;
1203 	char   *out;
1204 
1205 	RB_ENTRY(status_out) entry;
1206 };
1207 RB_HEAD(status_out_tree, status_out);
1208 
1209 /* Client connection. */
1210 struct client {
1211 	struct imsgbuf	 ibuf;
1212 	struct event	 event;
1213 	int		 retcode;
1214 
1215 	struct timeval	 creation_time;
1216 	struct timeval	 activity_time;
1217 
1218 	struct environ	 environ;
1219 
1220 	char		*title;
1221 	char		*cwd;
1222 
1223 	struct tty	 tty;
1224 
1225 	void		(*stdin_callback)(struct client *, int, void *);
1226 	void		*stdin_callback_data;
1227 	struct evbuffer	*stdin_data;
1228 	int              stdin_closed;
1229 	struct evbuffer	*stdout_data;
1230 	struct evbuffer	*stderr_data;
1231 
1232 	struct event	 repeat_timer;
1233 
1234 	struct status_out_tree status_old;
1235 	struct status_out_tree status_new;
1236 	struct timeval	 status_timer;
1237 	struct screen	 status;
1238 
1239 #define CLIENT_TERMINAL 0x1
1240 #define CLIENT_PREFIX 0x2
1241 #define CLIENT_EXIT 0x4
1242 #define CLIENT_REDRAW 0x8
1243 #define CLIENT_STATUS 0x10
1244 #define CLIENT_REPEAT 0x20 /* allow command to repeat within repeat time */
1245 #define CLIENT_SUSPENDED 0x40
1246 #define CLIENT_BAD 0x80
1247 #define CLIENT_IDENTIFY 0x100
1248 #define CLIENT_DEAD 0x200
1249 #define CLIENT_BORDERS 0x400
1250 #define CLIENT_READONLY 0x800
1251 #define CLIENT_REDRAWWINDOW 0x1000
1252 #define CLIENT_CONTROL 0x2000
1253 	int		 flags;
1254 
1255 	struct event	 identify_timer;
1256 
1257 	char		*message_string;
1258 	struct event	 message_timer;
1259 	ARRAY_DECL(, struct message_entry) message_log;
1260 
1261 	char		*prompt_string;
1262 	char		*prompt_buffer;
1263 	size_t		 prompt_index;
1264 	int		 (*prompt_callbackfn)(void *, const char *);
1265 	void		 (*prompt_freefn)(void *);
1266 	void		*prompt_data;
1267 	u_int            prompt_hindex;
1268 
1269 #define PROMPT_SINGLE 0x1
1270 	int		 prompt_flags;
1271 
1272 	struct mode_key_data prompt_mdata;
1273 
1274 	struct session	*session;
1275 	struct session	*last_session;
1276 
1277 	struct mouse_event last_mouse;
1278 
1279 	int		 wlmouse;
1280 
1281 	int		 references;
1282 };
1283 ARRAY_DECL(clients, struct client *);
1284 
1285 /* Parsed arguments. */
1286 struct args {
1287 	bitstr_t	*flags;
1288 	char		*values[SCHAR_MAX]; /* XXX This is awfully big. */
1289 
1290 	int		 argc;
1291 	char	       **argv;
1292 };
1293 
1294 /* Key/command line command. */
1295 struct cmd_ctx {
1296 	/*
1297 	 * curclient is the client where this command was executed if inside
1298 	 * tmux. This is NULL if the command came from the command-line.
1299 	 *
1300 	 * cmdclient is the client which sent the MSG_COMMAND to the server, if
1301 	 * any. This is NULL unless the command came from the command-line.
1302 	 *
1303 	 * cmdclient and curclient may both be NULL if the command is in the
1304 	 * configuration file.
1305 	 */
1306 	struct client  *curclient;
1307 	struct client  *cmdclient;
1308 
1309 	struct msg_command_data	*msgdata;
1310 
1311 	/* gcc2 doesn't understand attributes on function pointers... */
1312 #if defined(__GNUC__) && __GNUC__ >= 3
1313 	void printflike2 (*print)(struct cmd_ctx *, const char *, ...);
1314 	void printflike2 (*info)(struct cmd_ctx *, const char *, ...);
1315 	void printflike2 (*error)(struct cmd_ctx *, const char *, ...);
1316 #else
1317 	void (*print)(struct cmd_ctx *, const char *, ...);
1318 	void (*info)(struct cmd_ctx *, const char *, ...);
1319 	void (*error)(struct cmd_ctx *, const char *, ...);
1320 #endif
1321 };
1322 
1323 struct cmd {
1324 	const struct cmd_entry	*entry;
1325 	struct args		*args;
1326 
1327 	TAILQ_ENTRY(cmd)	 qentry;
1328 };
1329 struct cmd_list {
1330 	int		 	 references;
1331 	TAILQ_HEAD(, cmd) 	 list;
1332 };
1333 
1334 enum cmd_retval {
1335 	CMD_RETURN_ERROR = -1,
1336 	CMD_RETURN_NORMAL = 0,
1337 	CMD_RETURN_YIELD,
1338 	CMD_RETURN_ATTACH
1339 };
1340 
1341 struct cmd_entry {
1342 	const char	*name;
1343 	const char	*alias;
1344 
1345 	const char	*args_template;
1346 	int		 args_lower;
1347 	int		 args_upper;
1348 
1349 	const char	*usage;
1350 
1351 #define CMD_STARTSERVER 0x1
1352 #define CMD_CANTNEST 0x2
1353 #define CMD_SENDENVIRON 0x4
1354 #define CMD_READONLY 0x8
1355 	int		 flags;
1356 
1357 	void		 (*key_binding)(struct cmd *, int);
1358 	int		 (*check)(struct args *);
1359 	enum cmd_retval	 (*exec)(struct cmd *, struct cmd_ctx *);
1360 };
1361 
1362 /* Key binding. */
1363 struct key_binding {
1364 	int		 key;
1365 	struct cmd_list	*cmdlist;
1366 	int		 can_repeat;
1367 
1368 	RB_ENTRY(key_binding) entry;
1369 };
1370 RB_HEAD(key_bindings, key_binding);
1371 
1372 /*
1373  * Option table entries. The option table is the user-visible part of the
1374  * option, as opposed to the internal options (struct option) which are just
1375  * number or string.
1376  */
1377 enum options_table_type {
1378 	OPTIONS_TABLE_STRING,
1379 	OPTIONS_TABLE_NUMBER,
1380 	OPTIONS_TABLE_KEY,
1381 	OPTIONS_TABLE_COLOUR,
1382 	OPTIONS_TABLE_ATTRIBUTES,
1383 	OPTIONS_TABLE_FLAG,
1384 	OPTIONS_TABLE_CHOICE
1385 };
1386 
1387 struct options_table_entry {
1388 	const char	       *name;
1389 	enum options_table_type	type;
1390 
1391 	u_int		 	minimum;
1392 	u_int		 	maximum;
1393 	const char	      **choices;
1394 
1395 	const char	       *default_str;
1396 	long long		default_num;
1397 };
1398 
1399 /* Tree of format entries. */
1400 struct format_entry {
1401 	char		       *key;
1402 	char		       *value;
1403 
1404 	RB_ENTRY(format_entry)	entry;
1405 };
1406 RB_HEAD(format_tree, format_entry);
1407 
1408 /* List of configuration causes. */
1409 ARRAY_DECL(causelist, char *);
1410 
1411 /* Common command usages. */
1412 #define CMD_TARGET_PANE_USAGE "[-t target-pane]"
1413 #define CMD_TARGET_WINDOW_USAGE "[-t target-window]"
1414 #define CMD_TARGET_SESSION_USAGE "[-t target-session]"
1415 #define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
1416 #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]"
1417 #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
1418 #define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]"
1419 #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
1420 #define CMD_BUFFER_USAGE "[-b buffer-index]"
1421 
1422 /* tmux.c */
1423 extern struct options global_options;
1424 extern struct options global_s_options;
1425 extern struct options global_w_options;
1426 extern struct environ global_environ;
1427 extern struct event_base *ev_base;
1428 extern char	*cfg_file;
1429 extern char	*shell_cmd;
1430 extern int	 debug_level;
1431 extern time_t	 start_time;
1432 extern char	 socket_path[MAXPATHLEN];
1433 extern int	 login_shell;
1434 extern char	*environ_path;
1435 extern pid_t	 environ_pid;
1436 extern int	 environ_idx;
1437 void		 logfile(const char *);
1438 const char	*getshell(void);
1439 int		 checkshell(const char *);
1440 int		 areshell(const char *);
1441 const char*	 get_full_path(const char *, const char *);
1442 void		 setblocking(int, int);
1443 __dead void	 shell_exec(const char *, const char *);
1444 
1445 /* cfg.c */
1446 extern int       cfg_finished;
1447 extern struct causelist cfg_causes;
1448 void printflike2 cfg_add_cause(struct causelist *, const char *, ...);
1449 int		 load_cfg(const char *, struct cmd_ctx *, struct causelist *);
1450 
1451 /* format.c */
1452 int		 format_cmp(struct format_entry *, struct format_entry *);
1453 RB_PROTOTYPE(format_tree, format_entry, entry, format_cmp);
1454 struct format_tree *format_create(void);
1455 void		 format_free(struct format_tree *);
1456 void printflike3 format_add(
1457 		     struct format_tree *, const char *, const char *, ...);
1458 const char	*format_find(struct format_tree *, const char *);
1459 char		*format_expand(struct format_tree *, const char *);
1460 void		 format_session(struct format_tree *, struct session *);
1461 void		 format_client(struct format_tree *, struct client *);
1462 void		 format_winlink(
1463 		     struct format_tree *, struct session *, struct winlink *);
1464 void		 format_window_pane(struct format_tree *, struct window_pane *);
1465 void		 format_paste_buffer(struct format_tree *, struct paste_buffer *);
1466 
1467 /* mode-key.c */
1468 extern const struct mode_key_table mode_key_tables[];
1469 extern struct mode_key_tree mode_key_tree_vi_edit;
1470 extern struct mode_key_tree mode_key_tree_vi_choice;
1471 extern struct mode_key_tree mode_key_tree_vi_copy;
1472 extern struct mode_key_tree mode_key_tree_emacs_edit;
1473 extern struct mode_key_tree mode_key_tree_emacs_choice;
1474 extern struct mode_key_tree mode_key_tree_emacs_copy;
1475 int	mode_key_cmp(struct mode_key_binding *, struct mode_key_binding *);
1476 RB_PROTOTYPE(mode_key_tree, mode_key_binding, entry, mode_key_cmp);
1477 const char *mode_key_tostring(const struct mode_key_cmdstr *,
1478 	    enum mode_key_cmd);
1479 enum mode_key_cmd mode_key_fromstring(const struct mode_key_cmdstr *,
1480 	    const char *);
1481 const struct mode_key_table *mode_key_findtable(const char *);
1482 void	mode_key_init_trees(void);
1483 void	mode_key_init(struct mode_key_data *, struct mode_key_tree *);
1484 enum mode_key_cmd mode_key_lookup(struct mode_key_data *, int);
1485 
1486 /* notify.c */
1487 void	notify_enable(void);
1488 void	notify_disable(void);
1489 void	notify_window_layout_changed(struct window *);
1490 void	notify_window_unlinked(struct session *, struct window *);
1491 void	notify_window_linked(struct session *, struct window *);
1492 void	notify_window_renamed(struct window *);
1493 void	notify_attached_session_changed(struct client *);
1494 void	notify_session_renamed(struct session *);
1495 void	notify_session_created(struct session *);
1496 void	notify_session_closed(struct session *);
1497 
1498 /* options.c */
1499 int	options_cmp(struct options_entry *, struct options_entry *);
1500 RB_PROTOTYPE(options_tree, options_entry, entry, options_cmp);
1501 void	options_init(struct options *, struct options *);
1502 void	options_free(struct options *);
1503 struct options_entry *options_find1(struct options *, const char *);
1504 struct options_entry *options_find(struct options *, const char *);
1505 void	options_remove(struct options *, const char *);
1506 struct options_entry *printflike3 options_set_string(
1507 	    struct options *, const char *, const char *, ...);
1508 char   *options_get_string(struct options *, const char *);
1509 struct options_entry *options_set_number(
1510 	    struct options *, const char *, long long);
1511 long long options_get_number(struct options *, const char *);
1512 
1513 /* options-table.c */
1514 extern const struct options_table_entry server_options_table[];
1515 extern const struct options_table_entry session_options_table[];
1516 extern const struct options_table_entry window_options_table[];
1517 void	options_table_populate_tree(
1518 	    const struct options_table_entry *, struct options *);
1519 const char *options_table_print_entry(
1520 	    const struct options_table_entry *, struct options_entry *);
1521 int	options_table_find(
1522 	    const char *, const struct options_table_entry **,
1523 	    const struct options_table_entry **);
1524 
1525 /* job.c */
1526 extern struct joblist all_jobs;
1527 struct job *job_run(
1528 	    const char *, void (*)(struct job *), void (*)(void *), void *);
1529 void	job_free(struct job *);
1530 void	job_died(struct job *, int);
1531 
1532 /* environ.c */
1533 int	environ_cmp(struct environ_entry *, struct environ_entry *);
1534 RB_PROTOTYPE(environ, environ_entry, entry, environ_cmp);
1535 void	environ_init(struct environ *);
1536 void	environ_free(struct environ *);
1537 void	environ_copy(struct environ *, struct environ *);
1538 struct environ_entry *environ_find(struct environ *, const char *);
1539 void	environ_set(struct environ *, const char *, const char *);
1540 void	environ_put(struct environ *, const char *);
1541 void	environ_unset(struct environ *, const char *);
1542 void	environ_update(const char *, struct environ *, struct environ *);
1543 void	environ_push(struct environ *);
1544 
1545 /* tty.c */
1546 void	tty_init_termios(int, struct termios *, struct bufferevent *);
1547 void	tty_raw(struct tty *, const char *);
1548 void	tty_attributes(struct tty *, const struct grid_cell *);
1549 void	tty_reset(struct tty *);
1550 void	tty_region_pane(struct tty *, const struct tty_ctx *, u_int, u_int);
1551 void	tty_region(struct tty *, u_int, u_int);
1552 void	tty_cursor_pane(struct tty *, const struct tty_ctx *, u_int, u_int);
1553 void	tty_cursor(struct tty *, u_int, u_int);
1554 void	tty_putcode(struct tty *, enum tty_code_code);
1555 void	tty_putcode1(struct tty *, enum tty_code_code, int);
1556 void	tty_putcode2(struct tty *, enum tty_code_code, int, int);
1557 void	tty_putcode_ptr1(struct tty *, enum tty_code_code, const void *);
1558 void	tty_putcode_ptr2(struct tty *, enum tty_code_code, const void *, const void *);
1559 void	tty_puts(struct tty *, const char *);
1560 void	tty_putc(struct tty *, u_char);
1561 void	tty_pututf8(struct tty *, const struct grid_utf8 *);
1562 void	tty_init(struct tty *, struct client *, int, char *);
1563 int	tty_resize(struct tty *);
1564 int	tty_set_size(struct tty *, u_int, u_int);
1565 void	tty_start_tty(struct tty *);
1566 void	tty_set_version(struct tty *, u_int);
1567 void	tty_stop_tty(struct tty *);
1568 void	tty_set_title(struct tty *, const char *);
1569 void	tty_update_mode(struct tty *, int, struct screen *);
1570 void	tty_force_cursor_colour(struct tty *, const char *);
1571 void	tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int);
1572 int	tty_open(struct tty *, const char *, char **);
1573 void	tty_close(struct tty *);
1574 void	tty_free(struct tty *);
1575 void	tty_write(
1576 	    void (*)(struct tty *, const struct tty_ctx *), struct tty_ctx *);
1577 void	tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *);
1578 void	tty_cmd_cell(struct tty *, const struct tty_ctx *);
1579 void	tty_cmd_clearendofline(struct tty *, const struct tty_ctx *);
1580 void	tty_cmd_clearendofscreen(struct tty *, const struct tty_ctx *);
1581 void	tty_cmd_clearline(struct tty *, const struct tty_ctx *);
1582 void	tty_cmd_clearscreen(struct tty *, const struct tty_ctx *);
1583 void	tty_cmd_clearstartofline(struct tty *, const struct tty_ctx *);
1584 void	tty_cmd_clearstartofscreen(struct tty *, const struct tty_ctx *);
1585 void	tty_cmd_deletecharacter(struct tty *, const struct tty_ctx *);
1586 void	tty_cmd_deleteline(struct tty *, const struct tty_ctx *);
1587 void	tty_cmd_erasecharacter(struct tty *, const struct tty_ctx *);
1588 void	tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *);
1589 void	tty_cmd_insertline(struct tty *, const struct tty_ctx *);
1590 void	tty_cmd_linefeed(struct tty *, const struct tty_ctx *);
1591 void	tty_cmd_utf8character(struct tty *, const struct tty_ctx *);
1592 void	tty_cmd_reverseindex(struct tty *, const struct tty_ctx *);
1593 void	tty_cmd_setselection(struct tty *, const struct tty_ctx *);
1594 void	tty_cmd_rawstring(struct tty *, const struct tty_ctx *);
1595 void	tty_bell(struct tty *);
1596 
1597 /* tty-term.c */
1598 extern struct tty_terms tty_terms;
1599 extern const struct tty_term_code_entry tty_term_codes[NTTYCODE];
1600 struct tty_term *tty_term_find(char *, int, const char *, char **);
1601 void		 tty_term_free(struct tty_term *);
1602 int		 tty_term_has(struct tty_term *, enum tty_code_code);
1603 const char	*tty_term_string(struct tty_term *, enum tty_code_code);
1604 const char	*tty_term_string1(struct tty_term *, enum tty_code_code, int);
1605 const char	*tty_term_string2(
1606 		     struct tty_term *, enum tty_code_code, int, int);
1607 const char	*tty_term_ptr1(
1608 		     struct tty_term *, enum tty_code_code, const void *);
1609 const char	*tty_term_ptr2(
1610 		     struct tty_term *, enum tty_code_code, const void *, const void *);
1611 int		 tty_term_number(struct tty_term *, enum tty_code_code);
1612 int		 tty_term_flag(struct tty_term *, enum tty_code_code);
1613 
1614 /* tty-acs.c */
1615 const char	*tty_acs_get(struct tty *, u_char);
1616 
1617 /* tty-keys.c */
1618 void	tty_keys_init(struct tty *);
1619 void	tty_keys_free(struct tty *);
1620 int	tty_keys_next(struct tty *);
1621 
1622 /* paste.c */
1623 struct paste_buffer *paste_walk_stack(struct paste_stack *, u_int *);
1624 struct paste_buffer *paste_get_top(struct paste_stack *);
1625 struct paste_buffer *paste_get_index(struct paste_stack *, u_int);
1626 int		 paste_free_top(struct paste_stack *);
1627 int		 paste_free_index(struct paste_stack *, u_int);
1628 void		 paste_add(struct paste_stack *, char *, size_t, u_int);
1629 int		 paste_replace(struct paste_stack *, u_int, char *, size_t);
1630 char		*paste_print(struct paste_buffer *, size_t);
1631 
1632 /* clock.c */
1633 extern const char clock_table[14][5][5];
1634 void		 clock_draw(struct screen_write_ctx *, int, int);
1635 
1636 /* arguments.c */
1637 struct args	*args_create(int, ...);
1638 struct args	*args_parse(const char *, int, char **);
1639 void		 args_free(struct args *);
1640 size_t		 args_print(struct args *, char *, size_t);
1641 int		 args_has(struct args *, u_char);
1642 void		 args_set(struct args *, u_char, const char *);
1643 const char	*args_get(struct args *, u_char);
1644 long long	 args_strtonum(
1645 		    struct args *, u_char, long long, long long, char **);
1646 
1647 /* cmd.c */
1648 int		 cmd_pack_argv(int, char **, char *, size_t);
1649 int		 cmd_unpack_argv(char *, size_t, int, char ***);
1650 char	       **cmd_copy_argv(int, char *const *);
1651 void		 cmd_free_argv(int, char **);
1652 struct cmd	*cmd_parse(int, char **, char **);
1653 enum cmd_retval	 cmd_exec(struct cmd *, struct cmd_ctx *);
1654 void		 cmd_free(struct cmd *);
1655 size_t		 cmd_print(struct cmd *, char *, size_t);
1656 struct session	*cmd_current_session(struct cmd_ctx *, int);
1657 struct client	*cmd_current_client(struct cmd_ctx *);
1658 struct client	*cmd_find_client(struct cmd_ctx *, const char *);
1659 struct session	*cmd_find_session(struct cmd_ctx *, const char *, int);
1660 struct winlink	*cmd_find_window(
1661 		     struct cmd_ctx *, const char *, struct session **);
1662 int		 cmd_find_index(
1663 		     struct cmd_ctx *, const char *, struct session **);
1664 struct winlink	*cmd_find_pane(struct cmd_ctx *,
1665 		     const char *, struct session **, struct window_pane **);
1666 char		*cmd_template_replace(char *, const char *, int);
1667 const char     	*cmd_get_default_path(struct cmd_ctx *, const char *);
1668 extern const struct cmd_entry *cmd_table[];
1669 extern const struct cmd_entry cmd_attach_session_entry;
1670 extern const struct cmd_entry cmd_bind_key_entry;
1671 extern const struct cmd_entry cmd_break_pane_entry;
1672 extern const struct cmd_entry cmd_capture_pane_entry;
1673 extern const struct cmd_entry cmd_choose_buffer_entry;
1674 extern const struct cmd_entry cmd_choose_client_entry;
1675 extern const struct cmd_entry cmd_choose_session_entry;
1676 extern const struct cmd_entry cmd_choose_tree_entry;
1677 extern const struct cmd_entry cmd_choose_window_entry;
1678 extern const struct cmd_entry cmd_clear_history_entry;
1679 extern const struct cmd_entry cmd_clock_mode_entry;
1680 extern const struct cmd_entry cmd_command_prompt_entry;
1681 extern const struct cmd_entry cmd_confirm_before_entry;
1682 extern const struct cmd_entry cmd_copy_mode_entry;
1683 extern const struct cmd_entry cmd_delete_buffer_entry;
1684 extern const struct cmd_entry cmd_detach_client_entry;
1685 extern const struct cmd_entry cmd_display_message_entry;
1686 extern const struct cmd_entry cmd_display_panes_entry;
1687 extern const struct cmd_entry cmd_down_pane_entry;
1688 extern const struct cmd_entry cmd_find_window_entry;
1689 extern const struct cmd_entry cmd_has_session_entry;
1690 extern const struct cmd_entry cmd_if_shell_entry;
1691 extern const struct cmd_entry cmd_join_pane_entry;
1692 extern const struct cmd_entry cmd_kill_pane_entry;
1693 extern const struct cmd_entry cmd_kill_server_entry;
1694 extern const struct cmd_entry cmd_kill_session_entry;
1695 extern const struct cmd_entry cmd_kill_window_entry;
1696 extern const struct cmd_entry cmd_last_pane_entry;
1697 extern const struct cmd_entry cmd_last_window_entry;
1698 extern const struct cmd_entry cmd_link_window_entry;
1699 extern const struct cmd_entry cmd_list_buffers_entry;
1700 extern const struct cmd_entry cmd_list_clients_entry;
1701 extern const struct cmd_entry cmd_list_commands_entry;
1702 extern const struct cmd_entry cmd_list_keys_entry;
1703 extern const struct cmd_entry cmd_list_panes_entry;
1704 extern const struct cmd_entry cmd_list_sessions_entry;
1705 extern const struct cmd_entry cmd_list_windows_entry;
1706 extern const struct cmd_entry cmd_load_buffer_entry;
1707 extern const struct cmd_entry cmd_lock_client_entry;
1708 extern const struct cmd_entry cmd_lock_server_entry;
1709 extern const struct cmd_entry cmd_lock_session_entry;
1710 extern const struct cmd_entry cmd_move_pane_entry;
1711 extern const struct cmd_entry cmd_move_window_entry;
1712 extern const struct cmd_entry cmd_new_session_entry;
1713 extern const struct cmd_entry cmd_new_window_entry;
1714 extern const struct cmd_entry cmd_next_layout_entry;
1715 extern const struct cmd_entry cmd_next_window_entry;
1716 extern const struct cmd_entry cmd_paste_buffer_entry;
1717 extern const struct cmd_entry cmd_pipe_pane_entry;
1718 extern const struct cmd_entry cmd_previous_layout_entry;
1719 extern const struct cmd_entry cmd_previous_window_entry;
1720 extern const struct cmd_entry cmd_refresh_client_entry;
1721 extern const struct cmd_entry cmd_rename_session_entry;
1722 extern const struct cmd_entry cmd_rename_window_entry;
1723 extern const struct cmd_entry cmd_resize_pane_entry;
1724 extern const struct cmd_entry cmd_respawn_pane_entry;
1725 extern const struct cmd_entry cmd_respawn_window_entry;
1726 extern const struct cmd_entry cmd_rotate_window_entry;
1727 extern const struct cmd_entry cmd_run_shell_entry;
1728 extern const struct cmd_entry cmd_save_buffer_entry;
1729 extern const struct cmd_entry cmd_select_layout_entry;
1730 extern const struct cmd_entry cmd_select_pane_entry;
1731 extern const struct cmd_entry cmd_select_window_entry;
1732 extern const struct cmd_entry cmd_send_keys_entry;
1733 extern const struct cmd_entry cmd_send_prefix_entry;
1734 extern const struct cmd_entry cmd_server_info_entry;
1735 extern const struct cmd_entry cmd_set_buffer_entry;
1736 extern const struct cmd_entry cmd_set_environment_entry;
1737 extern const struct cmd_entry cmd_set_option_entry;
1738 extern const struct cmd_entry cmd_set_window_option_entry;
1739 extern const struct cmd_entry cmd_show_buffer_entry;
1740 extern const struct cmd_entry cmd_show_environment_entry;
1741 extern const struct cmd_entry cmd_show_messages_entry;
1742 extern const struct cmd_entry cmd_show_options_entry;
1743 extern const struct cmd_entry cmd_show_window_options_entry;
1744 extern const struct cmd_entry cmd_source_file_entry;
1745 extern const struct cmd_entry cmd_split_window_entry;
1746 extern const struct cmd_entry cmd_start_server_entry;
1747 extern const struct cmd_entry cmd_suspend_client_entry;
1748 extern const struct cmd_entry cmd_swap_pane_entry;
1749 extern const struct cmd_entry cmd_swap_window_entry;
1750 extern const struct cmd_entry cmd_switch_client_entry;
1751 extern const struct cmd_entry cmd_unbind_key_entry;
1752 extern const struct cmd_entry cmd_unlink_window_entry;
1753 extern const struct cmd_entry cmd_up_pane_entry;
1754 
1755 /* cmd-list.c */
1756 struct cmd_list	*cmd_list_parse(int, char **, char **);
1757 enum cmd_retval	 cmd_list_exec(struct cmd_list *, struct cmd_ctx *);
1758 void		 cmd_list_free(struct cmd_list *);
1759 size_t		 cmd_list_print(struct cmd_list *, char *, size_t);
1760 
1761 /* cmd-string.c */
1762 int	cmd_string_parse(const char *, struct cmd_list **, char **);
1763 
1764 /* client.c */
1765 int	client_main(int, char **, int);
1766 
1767 /* key-bindings.c */
1768 extern struct key_bindings key_bindings;
1769 int	 key_bindings_cmp(struct key_binding *, struct key_binding *);
1770 RB_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp);
1771 struct key_binding *key_bindings_lookup(int);
1772 void	 key_bindings_add(int, int, struct cmd_list *);
1773 void	 key_bindings_remove(int);
1774 void	 key_bindings_clean(void);
1775 void	 key_bindings_init(void);
1776 void	 key_bindings_dispatch(struct key_binding *, struct client *);
1777 void printflike2 key_bindings_error(struct cmd_ctx *, const char *, ...);
1778 void printflike2 key_bindings_print(struct cmd_ctx *, const char *, ...);
1779 void printflike2 key_bindings_info(struct cmd_ctx *, const char *, ...);
1780 
1781 /* key-string.c */
1782 int	 key_string_lookup_string(const char *);
1783 const char *key_string_lookup_key(int);
1784 
1785 /* server.c */
1786 extern struct clients clients;
1787 extern struct clients dead_clients;
1788 extern struct paste_stack global_buffers;
1789 int	 server_start(int, char *);
1790 void	 server_update_socket(void);
1791 void	 server_add_accept(int);
1792 
1793 /* server-client.c */
1794 void	 server_client_handle_key(struct client *, int);
1795 void	 server_client_create(int);
1796 int      server_client_open(struct client *, struct session *, char **);
1797 void	 server_client_lost(struct client *);
1798 void	 server_client_callback(int, short, void *);
1799 void	 server_client_status_timer(void);
1800 void	 server_client_loop(void);
1801 
1802 /* server-window.c */
1803 void	 server_window_loop(void);
1804 
1805 /* server-fn.c */
1806 void	 server_fill_environ(struct session *, struct environ *);
1807 void	 server_write_ready(struct client *);
1808 int	 server_write_client(
1809 	     struct client *, enum msgtype, const void *, size_t);
1810 void	 server_write_session(
1811 	     struct session *, enum msgtype, const void *, size_t);
1812 void	 server_redraw_client(struct client *);
1813 void	 server_status_client(struct client *);
1814 void	 server_redraw_session(struct session *);
1815 void	 server_redraw_session_group(struct session *);
1816 void	 server_status_session(struct session *);
1817 void	 server_status_session_group(struct session *);
1818 void	 server_redraw_window(struct window *);
1819 void	 server_redraw_window_borders(struct window *);
1820 void	 server_status_window(struct window *);
1821 void	 server_lock(void);
1822 void	 server_lock_session(struct session *);
1823 void	 server_lock_client(struct client *);
1824 int	 server_unlock(const char *);
1825 void	 server_kill_window(struct window *);
1826 int	 server_link_window(struct session *,
1827 	     struct winlink *, struct session *, int, int, int, char **);
1828 void	 server_unlink_window(struct session *, struct winlink *);
1829 void	 server_destroy_pane(struct window_pane *);
1830 void	 server_destroy_session_group(struct session *);
1831 void	 server_destroy_session(struct session *);
1832 void	 server_check_unattached (void);
1833 void	 server_set_identify(struct client *);
1834 void	 server_clear_identify(struct client *);
1835 void	 server_update_event(struct client *);
1836 void	 server_push_stdout(struct client *);
1837 void	 server_push_stderr(struct client *);
1838 int	 server_set_stdin_callback(struct client *, void (*)(struct client *,
1839 	     int, void *), void *, char **);
1840 
1841 /* status.c */
1842 int	 status_out_cmp(struct status_out *, struct status_out *);
1843 RB_PROTOTYPE(status_out_tree, status_out, entry, status_out_cmp);
1844 int	 status_at_line(struct client *);
1845 void	 status_free_jobs(struct status_out_tree *);
1846 void	 status_update_jobs(struct client *);
1847 void	 status_set_window_at(struct client *, u_int);
1848 int	 status_redraw(struct client *);
1849 char	*status_replace(struct client *, struct session *,
1850 	     struct winlink *, struct window_pane *, const char *, time_t, int);
1851 void printflike2 status_message_set(struct client *, const char *, ...);
1852 void	 status_message_clear(struct client *);
1853 int	 status_message_redraw(struct client *);
1854 void	 status_prompt_set(struct client *, const char *, const char *,
1855 	     int (*)(void *, const char *), void (*)(void *), void *, int);
1856 void	 status_prompt_clear(struct client *);
1857 int	 status_prompt_redraw(struct client *);
1858 void	 status_prompt_key(struct client *, int);
1859 void	 status_prompt_update(struct client *, const char *, const char *);
1860 
1861 /* resize.c */
1862 void	 recalculate_sizes(void);
1863 
1864 /* input.c */
1865 void	 input_init(struct window_pane *);
1866 void	 input_free(struct window_pane *);
1867 void	 input_parse(struct window_pane *);
1868 
1869 /* input-key.c */
1870 void	 input_key(struct window_pane *, int);
1871 void	 input_mouse(struct window_pane *, struct mouse_event *);
1872 
1873 /* xterm-keys.c */
1874 char	*xterm_keys_lookup(int);
1875 int	 xterm_keys_find(const char *, size_t, size_t *, int *);
1876 
1877 /* colour.c */
1878 void	 colour_set_fg(struct grid_cell *, int);
1879 void	 colour_set_bg(struct grid_cell *, int);
1880 const char *colour_tostring(int);
1881 int	 colour_fromstring(const char *);
1882 u_char	 colour_256to16(u_char);
1883 u_char	 colour_256to88(u_char);
1884 
1885 /* attributes.c */
1886 const char *attributes_tostring(u_char);
1887 int	 attributes_fromstring(const char *);
1888 
1889 /* grid.c */
1890 extern const struct grid_cell grid_default_cell;
1891 extern const struct grid_cell grid_marker_cell;
1892 struct grid *grid_create(u_int, u_int, u_int);
1893 void	 grid_destroy(struct grid *);
1894 int	 grid_compare(struct grid *, struct grid *);
1895 void	 grid_collect_history(struct grid *);
1896 void	 grid_scroll_history(struct grid *);
1897 void	 grid_scroll_history_region(struct grid *, u_int, u_int);
1898 void	 grid_expand_line(struct grid *, u_int, u_int);
1899 void	 grid_expand_line_utf8(struct grid *, u_int, u_int);
1900 const struct grid_cell *grid_peek_cell(struct grid *, u_int, u_int);
1901 struct grid_cell *grid_get_cell(struct grid *, u_int, u_int);
1902 void	 grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *);
1903 const struct grid_utf8 *grid_peek_utf8(struct grid *, u_int, u_int);
1904 struct grid_utf8 *grid_get_utf8(struct grid *, u_int, u_int);
1905 void	 grid_set_utf8(struct grid *, u_int, u_int, const struct grid_utf8 *);
1906 void	 grid_clear(struct grid *, u_int, u_int, u_int, u_int);
1907 void	 grid_clear_lines(struct grid *, u_int, u_int);
1908 void	 grid_move_lines(struct grid *, u_int, u_int, u_int);
1909 void	 grid_move_cells(struct grid *, u_int, u_int, u_int, u_int);
1910 char	*grid_string_cells(struct grid *, u_int, u_int, u_int);
1911 void	 grid_duplicate_lines(
1912 	     struct grid *, u_int, struct grid *, u_int, u_int);
1913 
1914 /* grid-utf8.c */
1915 size_t	 grid_utf8_size(const struct grid_utf8 *);
1916 size_t	 grid_utf8_copy(const struct grid_utf8 *, char *, size_t);
1917 void	 grid_utf8_set(struct grid_utf8 *, const struct utf8_data *);
1918 int	 grid_utf8_append(struct grid_utf8 *, const struct utf8_data *);
1919 int	 grid_utf8_compare(const struct grid_utf8 *, const struct grid_utf8 *);
1920 
1921 /* grid-view.c */
1922 const struct grid_cell *grid_view_peek_cell(struct grid *, u_int, u_int);
1923 struct grid_cell *grid_view_get_cell(struct grid *, u_int, u_int);
1924 void	 grid_view_set_cell(
1925 	     struct grid *, u_int, u_int, const struct grid_cell *);
1926 const struct grid_utf8 *grid_view_peek_utf8(struct grid *, u_int, u_int);
1927 struct grid_utf8 *grid_view_get_utf8(struct grid *, u_int, u_int);
1928 void	 grid_view_set_utf8(
1929 	     struct grid *, u_int, u_int, const struct grid_utf8 *);
1930 void	 grid_view_clear_history(struct grid *);
1931 void	 grid_view_clear(struct grid *, u_int, u_int, u_int, u_int);
1932 void	 grid_view_scroll_region_up(struct grid *, u_int, u_int);
1933 void	 grid_view_scroll_region_down(struct grid *, u_int, u_int);
1934 void	 grid_view_insert_lines(struct grid *, u_int, u_int);
1935 void	 grid_view_insert_lines_region(struct grid *, u_int, u_int, u_int);
1936 void	 grid_view_delete_lines(struct grid *, u_int, u_int);
1937 void	 grid_view_delete_lines_region(struct grid *, u_int, u_int, u_int);
1938 void	 grid_view_insert_cells(struct grid *, u_int, u_int, u_int);
1939 void	 grid_view_delete_cells(struct grid *, u_int, u_int, u_int);
1940 char	*grid_view_string_cells(struct grid *, u_int, u_int, u_int);
1941 
1942 /* screen-write.c */
1943 void	 screen_write_start(
1944 	     struct screen_write_ctx *, struct window_pane *, struct screen *);
1945 void	 screen_write_stop(struct screen_write_ctx *);
1946 void	 screen_write_reset(struct screen_write_ctx *);
1947 size_t printflike2 screen_write_cstrlen(int, const char *, ...);
1948 void printflike5 screen_write_cnputs(struct screen_write_ctx *,
1949 	     ssize_t, struct grid_cell *, int, const char *, ...);
1950 size_t printflike2 screen_write_strlen(int, const char *, ...);
1951 void printflike3 screen_write_puts(struct screen_write_ctx *,
1952 	     struct grid_cell *, const char *, ...);
1953 void printflike5 screen_write_nputs(struct screen_write_ctx *,
1954 	     ssize_t, struct grid_cell *, int, const char *, ...);
1955 void	 screen_write_vnputs(struct screen_write_ctx *,
1956 	     ssize_t, struct grid_cell *, int, const char *, va_list);
1957 void	 screen_write_parsestyle(
1958 	     struct grid_cell *, struct grid_cell *, const char *);
1959 void	 screen_write_putc(
1960 	     struct screen_write_ctx *, struct grid_cell *, u_char);
1961 void	 screen_write_copy(struct screen_write_ctx *,
1962 	     struct screen *, u_int, u_int, u_int, u_int);
1963 void	 screen_write_backspace(struct screen_write_ctx *);
1964 void	 screen_write_cursorup(struct screen_write_ctx *, u_int);
1965 void	 screen_write_cursordown(struct screen_write_ctx *, u_int);
1966 void	 screen_write_cursorright(struct screen_write_ctx *, u_int);
1967 void	 screen_write_cursorleft(struct screen_write_ctx *, u_int);
1968 void	 screen_write_alignmenttest(struct screen_write_ctx *);
1969 void	 screen_write_insertcharacter(struct screen_write_ctx *, u_int);
1970 void	 screen_write_deletecharacter(struct screen_write_ctx *, u_int);
1971 void	 screen_write_insertline(struct screen_write_ctx *, u_int);
1972 void	 screen_write_deleteline(struct screen_write_ctx *, u_int);
1973 void	 screen_write_clearline(struct screen_write_ctx *);
1974 void	 screen_write_clearendofline(struct screen_write_ctx *);
1975 void	 screen_write_clearstartofline(struct screen_write_ctx *);
1976 void	 screen_write_cursormove(struct screen_write_ctx *, u_int, u_int);
1977 void	 screen_write_cursormode(struct screen_write_ctx *, int);
1978 void	 screen_write_reverseindex(struct screen_write_ctx *);
1979 void	 screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int);
1980 void	 screen_write_insertmode(struct screen_write_ctx *, int);
1981 void	 screen_write_utf8mousemode(struct screen_write_ctx *, int);
1982 void	 screen_write_mousemode_on(struct screen_write_ctx *, int);
1983 void	 screen_write_mousemode_off(struct screen_write_ctx *);
1984 void	 screen_write_linefeed(struct screen_write_ctx *, int);
1985 void	 screen_write_linefeedscreen(struct screen_write_ctx *, int);
1986 void	 screen_write_carriagereturn(struct screen_write_ctx *);
1987 void	 screen_write_kcursormode(struct screen_write_ctx *, int);
1988 void	 screen_write_kkeypadmode(struct screen_write_ctx *, int);
1989 void	 screen_write_clearendofscreen(struct screen_write_ctx *);
1990 void	 screen_write_clearstartofscreen(struct screen_write_ctx *);
1991 void	 screen_write_clearscreen(struct screen_write_ctx *);
1992 void	 screen_write_clearhistory(struct screen_write_ctx *);
1993 void	 screen_write_cell(struct screen_write_ctx *,
1994 	     const struct grid_cell *, const struct utf8_data *);
1995 void	 screen_write_setselection(struct screen_write_ctx *, u_char *, u_int);
1996 void	 screen_write_rawstring(struct screen_write_ctx *, u_char *, u_int);
1997 void	 screen_write_bracketpaste(struct screen_write_ctx *, int);
1998 
1999 /* screen-redraw.c */
2000 void	 screen_redraw_screen(struct client *, int, int);
2001 void	 screen_redraw_pane(struct client *, struct window_pane *);
2002 
2003 /* screen.c */
2004 void	 screen_init(struct screen *, u_int, u_int, u_int);
2005 void	 screen_reinit(struct screen *);
2006 void	 screen_free(struct screen *);
2007 void	 screen_reset_tabs(struct screen *);
2008 void	 screen_set_cursor_style(struct screen *, u_int);
2009 void	 screen_set_cursor_colour(struct screen *, const char *);
2010 void	 screen_set_title(struct screen *, const char *);
2011 void	 screen_resize(struct screen *, u_int, u_int);
2012 void	 screen_set_selection(struct screen *,
2013 	     u_int, u_int, u_int, u_int, u_int, struct grid_cell *);
2014 void	 screen_clear_selection(struct screen *);
2015 int	 screen_check_selection(struct screen *, u_int, u_int);
2016 
2017 /* window.c */
2018 extern struct windows windows;
2019 extern struct window_pane_tree all_window_panes;
2020 int		 winlink_cmp(struct winlink *, struct winlink *);
2021 RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
2022 int		 window_pane_cmp(struct window_pane *, struct window_pane *);
2023 RB_PROTOTYPE(window_pane_tree, window_pane, tree_entry, window_pane_cmp);
2024 struct winlink	*winlink_find_by_index(struct winlinks *, int);
2025 struct winlink	*winlink_find_by_window(struct winlinks *, struct window *);
2026 struct winlink	*winlink_find_by_window_id(struct winlinks *, u_int);
2027 int		 winlink_next_index(struct winlinks *, int);
2028 u_int		 winlink_count(struct winlinks *);
2029 struct winlink	*winlink_add(struct winlinks *, int);
2030 void		 winlink_set_window(struct winlink *, struct window *);
2031 void		 winlink_remove(struct winlinks *, struct winlink *);
2032 struct winlink	*winlink_next(struct winlink *);
2033 struct winlink	*winlink_previous(struct winlink *);
2034 struct winlink	*winlink_next_by_number(struct winlink *, struct session *,
2035 		     int);
2036 struct winlink	*winlink_previous_by_number(struct winlink *, struct session *,
2037 		     int);
2038 void		 winlink_stack_push(struct winlink_stack *, struct winlink *);
2039 void		 winlink_stack_remove(struct winlink_stack *, struct winlink *);
2040 int		 window_index(struct window *, u_int *);
2041 struct window	*window_find_by_id(u_int);
2042 struct window	*window_create1(u_int, u_int);
2043 struct window	*window_create(const char *, const char *, const char *,
2044 		     const char *, struct environ *, struct termios *,
2045 		     u_int, u_int, u_int, char **);
2046 void		 window_destroy(struct window *);
2047 struct window_pane *window_get_active_at(struct window *, u_int, u_int);
2048 void		 window_set_active_at(struct window *, u_int, u_int);
2049 struct window_pane *window_find_string(struct window *, const char *);
2050 void		 window_set_active_pane(struct window *, struct window_pane *);
2051 struct window_pane *window_add_pane(struct window *, u_int);
2052 void		 window_resize(struct window *, u_int, u_int);
2053 void		 window_remove_pane(struct window *, struct window_pane *);
2054 struct window_pane *window_pane_at_index(struct window *, u_int);
2055 struct window_pane *window_pane_next_by_number(struct window *,
2056 		        struct window_pane *, u_int);
2057 struct window_pane *window_pane_previous_by_number(struct window *,
2058 		        struct window_pane *, u_int);
2059 int		 window_pane_index(struct window_pane *, u_int *);
2060 u_int		 window_count_panes(struct window *);
2061 void		 window_destroy_panes(struct window *);
2062 struct window_pane *window_pane_find_by_id(u_int);
2063 struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int);
2064 void		 window_pane_destroy(struct window_pane *);
2065 void		 window_pane_timer_start(struct window_pane *);
2066 int		 window_pane_spawn(struct window_pane *, const char *,
2067 		     const char *, const char *, struct environ *,
2068 		     struct termios *, char **);
2069 void		 window_pane_resize(struct window_pane *, u_int, u_int);
2070 void		 window_pane_alternate_on(
2071 		     struct window_pane *, struct grid_cell *);
2072 void		 window_pane_alternate_off(
2073 		     struct window_pane *, struct grid_cell *);
2074 int		 window_pane_set_mode(
2075 		     struct window_pane *, const struct window_mode *);
2076 void		 window_pane_reset_mode(struct window_pane *);
2077 void		 window_pane_key(struct window_pane *, struct session *, int);
2078 void		 window_pane_mouse(struct window_pane *,
2079 		     struct session *, struct mouse_event *);
2080 int		 window_pane_visible(struct window_pane *);
2081 char		*window_pane_search(
2082 		     struct window_pane *, const char *, u_int *);
2083 char		*window_printable_flags(struct session *, struct winlink *);
2084 struct window_pane *window_pane_find_up(struct window_pane *);
2085 struct window_pane *window_pane_find_down(struct window_pane *);
2086 struct window_pane *window_pane_find_left(struct window_pane *);
2087 struct window_pane *window_pane_find_right(struct window_pane *);
2088 void		 window_set_name(struct window *, const char *);
2089 void		 winlink_clear_flags(struct winlink *);
2090 
2091 /* layout.c */
2092 u_int		 layout_count_cells(struct layout_cell *);
2093 struct layout_cell *layout_create_cell(struct layout_cell *);
2094 void		 layout_free_cell(struct layout_cell *);
2095 void		 layout_print_cell(struct layout_cell *, const char *, u_int);
2096 void		 layout_destroy_cell(
2097 		     struct layout_cell *, struct layout_cell **);
2098 void		 layout_set_size(
2099 		     struct layout_cell *, u_int, u_int, u_int, u_int);
2100 void		 layout_make_leaf(
2101 		     struct layout_cell *, struct window_pane *);
2102 void		 layout_make_node(struct layout_cell *, enum layout_type);
2103 void		 layout_fix_offsets(struct layout_cell *);
2104 void		 layout_fix_panes(struct window *, u_int, u_int);
2105 u_int		 layout_resize_check(struct layout_cell *, enum layout_type);
2106 void		 layout_resize_adjust(
2107 		     struct layout_cell *, enum layout_type, int);
2108 void		 layout_init(struct window *);
2109 void		 layout_free(struct window *);
2110 void		 layout_resize(struct window *, u_int, u_int);
2111 void		 layout_resize_pane(
2112 		     struct window_pane *, enum layout_type, int);
2113 void		 layout_resize_pane_mouse(
2114 		     struct client *c, struct mouse_event *mouse);
2115 void		 layout_assign_pane(struct layout_cell *, struct window_pane *);
2116 struct layout_cell *layout_split_pane(
2117 		     struct window_pane *, enum layout_type, int, int);
2118 void		 layout_close_pane(struct window_pane *);
2119 void		 layout_list_add(struct window *);
2120 const char	*layout_list_redo(struct window *);
2121 const char	*layout_list_undo(struct window *);
2122 
2123 /* layout-custom.c */
2124 char		*layout_dump(struct window *);
2125 int		 layout_parse(struct window *, const char *);
2126 
2127 /* layout-set.c */
2128 const char	*layout_set_name(u_int);
2129 int		 layout_set_lookup(const char *);
2130 u_int		 layout_set_select(struct window *, u_int);
2131 u_int		 layout_set_next(struct window *);
2132 u_int		 layout_set_previous(struct window *);
2133 void		 layout_set_active_changed(struct window *);
2134 
2135 /* window-clock.c */
2136 extern const struct window_mode window_clock_mode;
2137 
2138 /* window-copy.c */
2139 extern const struct window_mode window_copy_mode;
2140 void		 window_copy_init_from_pane(struct window_pane *);
2141 void		 window_copy_init_for_output(struct window_pane *);
2142 void printflike2 window_copy_add(struct window_pane *, const char *, ...);
2143 void		 window_copy_vadd(struct window_pane *, const char *, va_list);
2144 void		 window_copy_pageup(struct window_pane *);
2145 
2146 /* window-choose.c */
2147 extern const struct window_mode window_choose_mode;
2148 void		 window_choose_add(struct window_pane *,
2149 			 struct window_choose_data *);
2150 void		 window_choose_ready(struct window_pane *,
2151 		     u_int, void (*)(struct window_choose_data *),
2152 		     void (*)(struct window_choose_data *));
2153 struct window_choose_data	*window_choose_data_create(struct cmd_ctx *);
2154 void		 window_choose_ctx(struct window_choose_data *);
2155 struct window_choose_data	*window_choose_add_window(struct window_pane *,
2156 			struct cmd_ctx *, struct session *, struct winlink *,
2157 			const char *, char *, u_int);
2158 struct window_choose_data	*window_choose_add_session(struct window_pane *,
2159 			struct cmd_ctx *, struct session *, const char *,
2160 			char *, u_int);
2161 
2162 /* names.c */
2163 void		 queue_window_name(struct window *);
2164 char		*default_window_name(struct window *);
2165 
2166 /* signal.c */
2167 void	set_signals(void(*)(int, short, void *));
2168 void	clear_signals(int);
2169 
2170 /* control.c */
2171 void	control_callback(struct client *, int, void*);
2172 
2173 /* session.c */
2174 extern struct sessions sessions;
2175 extern struct sessions dead_sessions;
2176 extern struct session_groups session_groups;
2177 int	session_cmp(struct session *, struct session *);
2178 RB_PROTOTYPE(sessions, session, entry, session_cmp);
2179 int		 session_alive(struct session *);
2180 struct session	*session_find(const char *);
2181 struct session	*session_find_by_index(u_int);
2182 struct session	*session_create(const char *, const char *, const char *,
2183 		     struct environ *, struct termios *, int, u_int, u_int,
2184 		     char **);
2185 void		 session_destroy(struct session *);
2186 int		 session_check_name(const char *);
2187 void		 session_update_activity(struct session *);
2188 struct session	*session_next_session(struct session *);
2189 struct session	*session_previous_session(struct session *);
2190 struct winlink	*session_new(struct session *,
2191 		     const char *, const char *, const char *, int, char **);
2192 struct winlink	*session_attach(
2193 		     struct session *, struct window *, int, char **);
2194 int		 session_detach(struct session *, struct winlink *);
2195 struct winlink*	 session_has(struct session *, struct window *);
2196 int		 session_next(struct session *, int);
2197 int		 session_previous(struct session *, int);
2198 int		 session_select(struct session *, int);
2199 int		 session_last(struct session *);
2200 struct session_group *session_group_find(struct session *);
2201 u_int		 session_group_index(struct session_group *);
2202 void		 session_group_add(struct session *, struct session *);
2203 void		 session_group_remove(struct session *);
2204 void		 session_group_synchronize_to(struct session *);
2205 void		 session_group_synchronize_from(struct session *);
2206 void		 session_group_synchronize1(struct session *, struct session *);
2207 void		 session_renumber_windows(struct session *);
2208 
2209 /* utf8.c */
2210 void	utf8_build(void);
2211 int	utf8_open(struct utf8_data *, u_char);
2212 int	utf8_append(struct utf8_data *, u_char);
2213 u_int	utf8_combine(const struct utf8_data *);
2214 u_int	utf8_split2(u_int, u_char *);
2215 
2216 /* procname.c */
2217 char   *get_proc_name(int, char *);
2218 char   *get_proc_cwd(pid_t);
2219 
2220 /* log.c */
2221 void		 log_open(int, const char *);
2222 void		 log_close(void);
2223 void printflike1 log_warn(const char *, ...);
2224 void printflike1 log_warnx(const char *, ...);
2225 void printflike1 log_info(const char *, ...);
2226 void printflike1 log_debug(const char *, ...);
2227 void printflike1 log_debug2(const char *, ...);
2228 __dead void printflike1 log_fatal(const char *, ...);
2229 __dead void printflike1 log_fatalx(const char *, ...);
2230 
2231 /* xmalloc.c */
2232 char		*xstrdup(const char *);
2233 void		*xcalloc(size_t, size_t);
2234 void		*xmalloc(size_t);
2235 void		*xrealloc(void *, size_t, size_t);
2236 int printflike2	 xasprintf(char **, const char *, ...);
2237 int		 xvasprintf(char **, const char *, va_list);
2238 int printflike3	 xsnprintf(char *, size_t, const char *, ...);
2239 int		 xvsnprintf(char *, size_t, const char *, va_list);
2240 
2241 #endif /* TMUX_H */
2242