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