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