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