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