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