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 #include <sys/time.h>
23 #include <sys/uio.h>
24 
25 #include <limits.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <termios.h>
29 
30 #ifdef HAVE_UTEMPTER
31 #include <utempter.h>
32 #endif
33 
34 #include "compat.h"
35 #include "xmalloc.h"
36 
37 extern char   **environ;
38 
39 struct args;
40 struct args_value;
41 struct client;
42 struct cmd;
43 struct cmd_find_state;
44 struct cmdq_item;
45 struct cmdq_list;
46 struct cmdq_state;
47 struct cmds;
48 struct control_state;
49 struct environ;
50 struct format_job_tree;
51 struct format_tree;
52 struct input_ctx;
53 struct job;
54 struct mode_tree_data;
55 struct mouse_event;
56 struct options;
57 struct options_array_item;
58 struct options_entry;
59 struct screen_write_citem;
60 struct screen_write_cline;
61 struct screen_write_ctx;
62 struct session;
63 struct tty_ctx;
64 struct tmuxpeer;
65 struct tmuxproc;
66 struct winlink;
67 
68 /* Client-server protocol version. */
69 #define PROTOCOL_VERSION 8
70 
71 /* Default configuration files and socket paths. */
72 #ifndef TMUX_CONF
73 #define TMUX_CONF "/usr/local/etc/tmux.conf:~/.tmux.conf"
74 #endif
75 #ifndef TMUX_SOCK
76 #define TMUX_SOCK "$TMUX_TMPDIR:" _PATH_TMP
77 #endif
78 
79 /* Minimum layout cell size, NOT including border lines. */
80 #define PANE_MINIMUM 1
81 
82 /* Minimum and maximum window size. */
83 #define WINDOW_MINIMUM PANE_MINIMUM
84 #define WINDOW_MAXIMUM 10000
85 
86 /* Automatic name refresh interval, in microseconds. Must be < 1 second. */
87 #define NAME_INTERVAL 500000
88 
89 /* Default pixel cell sizes. */
90 #define DEFAULT_XPIXEL 16
91 #define DEFAULT_YPIXEL 32
92 
93 /* Attribute to make GCC check printf-like arguments. */
94 #define printflike(a, b) __attribute__ ((format (printf, a, b)))
95 
96 /* Number of items in array. */
97 #ifndef nitems
98 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
99 #endif
100 
101 /* Alert option values. */
102 #define ALERT_NONE 0
103 #define ALERT_ANY 1
104 #define ALERT_CURRENT 2
105 #define ALERT_OTHER 3
106 
107 /* Visual option values. */
108 #define VISUAL_OFF 0
109 #define VISUAL_ON 1
110 #define VISUAL_BOTH 2
111 
112 /* No key or unknown key. */
113 #define KEYC_NONE            0x000ff000000000ULL
114 #define KEYC_UNKNOWN         0x000fe000000000ULL
115 
116 /*
117  * Base for special (that is, not Unicode) keys. An enum must be at most a
118  * signed int, so these are based in the highest Unicode PUA.
119  */
120 #define KEYC_BASE            0x0000000010e000ULL
121 #define KEYC_USER            0x0000000010f000ULL
122 
123 /* Key modifier bits. */
124 #define KEYC_META            0x00100000000000ULL
125 #define KEYC_CTRL            0x00200000000000ULL
126 #define KEYC_SHIFT           0x00400000000000ULL
127 
128 /* Key flag bits. */
129 #define KEYC_LITERAL         0x01000000000000ULL
130 #define KEYC_KEYPAD          0x02000000000000ULL
131 #define KEYC_CURSOR          0x04000000000000ULL
132 #define KEYC_IMPLIED_META    0x08000000000000ULL
133 #define KEYC_BUILD_MODIFIERS 0x10000000000000ULL
134 
135 /* Masks for key bits. */
136 #define KEYC_MASK_MODIFIERS  0x00f00000000000ULL
137 #define KEYC_MASK_FLAGS      0xff000000000000ULL
138 #define KEYC_MASK_KEY        0x000fffffffffffULL
139 
140 /* Available user keys. */
141 #define KEYC_NUSER 1000
142 
143 /* Is this a mouse key? */
144 #define KEYC_IS_MOUSE(key) \
145 	(((key) & KEYC_MASK_KEY) >= KEYC_MOUSE && \
146 	 ((key) & KEYC_MASK_KEY) < KEYC_BSPACE)
147 
148 /* Is this a Unicode key? */
149 #define KEYC_IS_UNICODE(key) \
150 	(((key) & KEYC_MASK_KEY) > 0x7f && \
151 	 (((key) & KEYC_MASK_KEY) < KEYC_BASE || \
152 	  ((key) & KEYC_MASK_KEY) >= KEYC_BASE_END))
153 
154 /* Multiple click timeout. */
155 #define KEYC_CLICK_TIMEOUT 300
156 
157 /* Mouse key codes. */
158 #define KEYC_MOUSE_KEY(name)					\
159 	KEYC_ ## name ## _PANE,					\
160 	KEYC_ ## name ## _STATUS,				\
161 	KEYC_ ## name ## _STATUS_LEFT,				\
162 	KEYC_ ## name ## _STATUS_RIGHT,				\
163 	KEYC_ ## name ## _STATUS_DEFAULT,			\
164 	KEYC_ ## name ## _BORDER
165 #define KEYC_MOUSE_STRING(name, s)				\
166 	{ #s "Pane", KEYC_ ## name ## _PANE },			\
167 	{ #s "Status", KEYC_ ## name ## _STATUS },		\
168 	{ #s "StatusLeft", KEYC_ ## name ## _STATUS_LEFT },	\
169 	{ #s "StatusRight", KEYC_ ## name ## _STATUS_RIGHT },	\
170 	{ #s "StatusDefault", KEYC_ ## name ## _STATUS_DEFAULT }, \
171 	{ #s "Border", KEYC_ ## name ## _BORDER }
172 
173 /*
174  * A single key. This can be ASCII or Unicode or one of the keys between
175  * KEYC_BASE and KEYC_BASE_END.
176  */
177 typedef unsigned long long key_code;
178 
179 /* Special key codes. */
180 enum {
181 	/* Focus events. */
182 	KEYC_FOCUS_IN = KEYC_BASE,
183 	KEYC_FOCUS_OUT,
184 
185 	/* "Any" key, used if not found in key table. */
186 	KEYC_ANY,
187 
188 	/* Paste brackets. */
189 	KEYC_PASTE_START,
190 	KEYC_PASTE_END,
191 
192 	/* Mouse keys. */
193 	KEYC_MOUSE, /* unclassified mouse event */
194 	KEYC_DRAGGING, /* dragging in progress */
195 	KEYC_DOUBLECLICK, /* double click complete */
196 	KEYC_MOUSE_KEY(MOUSEMOVE),
197 	KEYC_MOUSE_KEY(MOUSEDOWN1),
198 	KEYC_MOUSE_KEY(MOUSEDOWN2),
199 	KEYC_MOUSE_KEY(MOUSEDOWN3),
200 	KEYC_MOUSE_KEY(MOUSEUP1),
201 	KEYC_MOUSE_KEY(MOUSEUP2),
202 	KEYC_MOUSE_KEY(MOUSEUP3),
203 	KEYC_MOUSE_KEY(MOUSEDRAG1),
204 	KEYC_MOUSE_KEY(MOUSEDRAG2),
205 	KEYC_MOUSE_KEY(MOUSEDRAG3),
206 	KEYC_MOUSE_KEY(MOUSEDRAGEND1),
207 	KEYC_MOUSE_KEY(MOUSEDRAGEND2),
208 	KEYC_MOUSE_KEY(MOUSEDRAGEND3),
209 	KEYC_MOUSE_KEY(WHEELUP),
210 	KEYC_MOUSE_KEY(WHEELDOWN),
211 	KEYC_MOUSE_KEY(SECONDCLICK1),
212 	KEYC_MOUSE_KEY(SECONDCLICK2),
213 	KEYC_MOUSE_KEY(SECONDCLICK3),
214 	KEYC_MOUSE_KEY(DOUBLECLICK1),
215 	KEYC_MOUSE_KEY(DOUBLECLICK2),
216 	KEYC_MOUSE_KEY(DOUBLECLICK3),
217 	KEYC_MOUSE_KEY(TRIPLECLICK1),
218 	KEYC_MOUSE_KEY(TRIPLECLICK2),
219 	KEYC_MOUSE_KEY(TRIPLECLICK3),
220 
221 	/* Backspace key. */
222 	KEYC_BSPACE,
223 
224 	/* Function keys. */
225 	KEYC_F1,
226 	KEYC_F2,
227 	KEYC_F3,
228 	KEYC_F4,
229 	KEYC_F5,
230 	KEYC_F6,
231 	KEYC_F7,
232 	KEYC_F8,
233 	KEYC_F9,
234 	KEYC_F10,
235 	KEYC_F11,
236 	KEYC_F12,
237 	KEYC_IC,
238 	KEYC_DC,
239 	KEYC_HOME,
240 	KEYC_END,
241 	KEYC_NPAGE,
242 	KEYC_PPAGE,
243 	KEYC_BTAB,
244 
245 	/* Arrow keys. */
246 	KEYC_UP,
247 	KEYC_DOWN,
248 	KEYC_LEFT,
249 	KEYC_RIGHT,
250 
251 	/* Numeric keypad. */
252 	KEYC_KP_SLASH,
253 	KEYC_KP_STAR,
254 	KEYC_KP_MINUS,
255 	KEYC_KP_SEVEN,
256 	KEYC_KP_EIGHT,
257 	KEYC_KP_NINE,
258 	KEYC_KP_PLUS,
259 	KEYC_KP_FOUR,
260 	KEYC_KP_FIVE,
261 	KEYC_KP_SIX,
262 	KEYC_KP_ONE,
263 	KEYC_KP_TWO,
264 	KEYC_KP_THREE,
265 	KEYC_KP_ENTER,
266 	KEYC_KP_ZERO,
267 	KEYC_KP_PERIOD,
268 
269 	/* End of special keys. */
270 	KEYC_BASE_END
271 };
272 
273 /* Termcap codes. */
274 enum tty_code_code {
275 	TTYC_ACSC,
276 	TTYC_AM,
277 	TTYC_AX,
278 	TTYC_BCE,
279 	TTYC_BEL,
280 	TTYC_BIDI,
281 	TTYC_BLINK,
282 	TTYC_BOLD,
283 	TTYC_CIVIS,
284 	TTYC_CLEAR,
285 	TTYC_CLMG,
286 	TTYC_CMG,
287 	TTYC_CNORM,
288 	TTYC_COLORS,
289 	TTYC_CR,
290 	TTYC_CS,
291 	TTYC_CSR,
292 	TTYC_CUB,
293 	TTYC_CUB1,
294 	TTYC_CUD,
295 	TTYC_CUD1,
296 	TTYC_CUF,
297 	TTYC_CUF1,
298 	TTYC_CUP,
299 	TTYC_CUU,
300 	TTYC_CUU1,
301 	TTYC_CVVIS,
302 	TTYC_DCH,
303 	TTYC_DCH1,
304 	TTYC_DIM,
305 	TTYC_DL,
306 	TTYC_DL1,
307 	TTYC_DSBP,
308 	TTYC_DSEKS,
309 	TTYC_DSFCS,
310 	TTYC_DSMG,
311 	TTYC_E3,
312 	TTYC_ECH,
313 	TTYC_ED,
314 	TTYC_EL,
315 	TTYC_EL1,
316 	TTYC_ENACS,
317 	TTYC_ENBP,
318 	TTYC_ENEKS,
319 	TTYC_ENFCS,
320 	TTYC_ENMG,
321 	TTYC_FSL,
322 	TTYC_HOME,
323 	TTYC_HPA,
324 	TTYC_ICH,
325 	TTYC_ICH1,
326 	TTYC_IL,
327 	TTYC_IL1,
328 	TTYC_INDN,
329 	TTYC_INVIS,
330 	TTYC_KCBT,
331 	TTYC_KCUB1,
332 	TTYC_KCUD1,
333 	TTYC_KCUF1,
334 	TTYC_KCUU1,
335 	TTYC_KDC2,
336 	TTYC_KDC3,
337 	TTYC_KDC4,
338 	TTYC_KDC5,
339 	TTYC_KDC6,
340 	TTYC_KDC7,
341 	TTYC_KDCH1,
342 	TTYC_KDN2,
343 	TTYC_KDN3,
344 	TTYC_KDN4,
345 	TTYC_KDN5,
346 	TTYC_KDN6,
347 	TTYC_KDN7,
348 	TTYC_KEND,
349 	TTYC_KEND2,
350 	TTYC_KEND3,
351 	TTYC_KEND4,
352 	TTYC_KEND5,
353 	TTYC_KEND6,
354 	TTYC_KEND7,
355 	TTYC_KF1,
356 	TTYC_KF10,
357 	TTYC_KF11,
358 	TTYC_KF12,
359 	TTYC_KF13,
360 	TTYC_KF14,
361 	TTYC_KF15,
362 	TTYC_KF16,
363 	TTYC_KF17,
364 	TTYC_KF18,
365 	TTYC_KF19,
366 	TTYC_KF2,
367 	TTYC_KF20,
368 	TTYC_KF21,
369 	TTYC_KF22,
370 	TTYC_KF23,
371 	TTYC_KF24,
372 	TTYC_KF25,
373 	TTYC_KF26,
374 	TTYC_KF27,
375 	TTYC_KF28,
376 	TTYC_KF29,
377 	TTYC_KF3,
378 	TTYC_KF30,
379 	TTYC_KF31,
380 	TTYC_KF32,
381 	TTYC_KF33,
382 	TTYC_KF34,
383 	TTYC_KF35,
384 	TTYC_KF36,
385 	TTYC_KF37,
386 	TTYC_KF38,
387 	TTYC_KF39,
388 	TTYC_KF4,
389 	TTYC_KF40,
390 	TTYC_KF41,
391 	TTYC_KF42,
392 	TTYC_KF43,
393 	TTYC_KF44,
394 	TTYC_KF45,
395 	TTYC_KF46,
396 	TTYC_KF47,
397 	TTYC_KF48,
398 	TTYC_KF49,
399 	TTYC_KF5,
400 	TTYC_KF50,
401 	TTYC_KF51,
402 	TTYC_KF52,
403 	TTYC_KF53,
404 	TTYC_KF54,
405 	TTYC_KF55,
406 	TTYC_KF56,
407 	TTYC_KF57,
408 	TTYC_KF58,
409 	TTYC_KF59,
410 	TTYC_KF6,
411 	TTYC_KF60,
412 	TTYC_KF61,
413 	TTYC_KF62,
414 	TTYC_KF63,
415 	TTYC_KF7,
416 	TTYC_KF8,
417 	TTYC_KF9,
418 	TTYC_KHOM2,
419 	TTYC_KHOM3,
420 	TTYC_KHOM4,
421 	TTYC_KHOM5,
422 	TTYC_KHOM6,
423 	TTYC_KHOM7,
424 	TTYC_KHOME,
425 	TTYC_KIC2,
426 	TTYC_KIC3,
427 	TTYC_KIC4,
428 	TTYC_KIC5,
429 	TTYC_KIC6,
430 	TTYC_KIC7,
431 	TTYC_KICH1,
432 	TTYC_KIND,
433 	TTYC_KLFT2,
434 	TTYC_KLFT3,
435 	TTYC_KLFT4,
436 	TTYC_KLFT5,
437 	TTYC_KLFT6,
438 	TTYC_KLFT7,
439 	TTYC_KMOUS,
440 	TTYC_KNP,
441 	TTYC_KNXT2,
442 	TTYC_KNXT3,
443 	TTYC_KNXT4,
444 	TTYC_KNXT5,
445 	TTYC_KNXT6,
446 	TTYC_KNXT7,
447 	TTYC_KPP,
448 	TTYC_KPRV2,
449 	TTYC_KPRV3,
450 	TTYC_KPRV4,
451 	TTYC_KPRV5,
452 	TTYC_KPRV6,
453 	TTYC_KPRV7,
454 	TTYC_KRI,
455 	TTYC_KRIT2,
456 	TTYC_KRIT3,
457 	TTYC_KRIT4,
458 	TTYC_KRIT5,
459 	TTYC_KRIT6,
460 	TTYC_KRIT7,
461 	TTYC_KUP2,
462 	TTYC_KUP3,
463 	TTYC_KUP4,
464 	TTYC_KUP5,
465 	TTYC_KUP6,
466 	TTYC_KUP7,
467 	TTYC_MS,
468 	TTYC_OL,
469 	TTYC_OP,
470 	TTYC_RECT,
471 	TTYC_REV,
472 	TTYC_RGB,
473 	TTYC_RI,
474 	TTYC_RIN,
475 	TTYC_RMACS,
476 	TTYC_RMCUP,
477 	TTYC_RMKX,
478 	TTYC_SE,
479 	TTYC_SETAB,
480 	TTYC_SETAF,
481 	TTYC_SETAL,
482 	TTYC_SETRGBB,
483 	TTYC_SETRGBF,
484 	TTYC_SETULC,
485 	TTYC_SGR0,
486 	TTYC_SITM,
487 	TTYC_SMACS,
488 	TTYC_SMCUP,
489 	TTYC_SMKX,
490 	TTYC_SMOL,
491 	TTYC_SMSO,
492 	TTYC_SMUL,
493 	TTYC_SMULX,
494 	TTYC_SMXX,
495 	TTYC_SS,
496 	TTYC_SYNC,
497 	TTYC_TC,
498 	TTYC_TSL,
499 	TTYC_U8,
500 	TTYC_VPA,
501 	TTYC_XT
502 };
503 
504 /* Message codes. */
505 enum msgtype {
506 	MSG_VERSION = 12,
507 
508 	MSG_IDENTIFY_FLAGS = 100,
509 	MSG_IDENTIFY_TERM,
510 	MSG_IDENTIFY_TTYNAME,
511 	MSG_IDENTIFY_OLDCWD, /* unused */
512 	MSG_IDENTIFY_STDIN,
513 	MSG_IDENTIFY_ENVIRON,
514 	MSG_IDENTIFY_DONE,
515 	MSG_IDENTIFY_CLIENTPID,
516 	MSG_IDENTIFY_CWD,
517 	MSG_IDENTIFY_FEATURES,
518 	MSG_IDENTIFY_STDOUT,
519 	MSG_IDENTIFY_LONGFLAGS,
520 	MSG_IDENTIFY_TERMINFO,
521 
522 	MSG_COMMAND = 200,
523 	MSG_DETACH,
524 	MSG_DETACHKILL,
525 	MSG_EXIT,
526 	MSG_EXITED,
527 	MSG_EXITING,
528 	MSG_LOCK,
529 	MSG_READY,
530 	MSG_RESIZE,
531 	MSG_SHELL,
532 	MSG_SHUTDOWN,
533 	MSG_OLDSTDERR, /* unused */
534 	MSG_OLDSTDIN, /* unused */
535 	MSG_OLDSTDOUT, /* unused */
536 	MSG_SUSPEND,
537 	MSG_UNLOCK,
538 	MSG_WAKEUP,
539 	MSG_EXEC,
540 	MSG_FLAGS,
541 
542 	MSG_READ_OPEN = 300,
543 	MSG_READ,
544 	MSG_READ_DONE,
545 	MSG_WRITE_OPEN,
546 	MSG_WRITE,
547 	MSG_WRITE_READY,
548 	MSG_WRITE_CLOSE
549 };
550 
551 /*
552  * Message data.
553  *
554  * Don't forget to bump PROTOCOL_VERSION if any of these change!
555  */
556 struct msg_command {
557 	int	argc;
558 }; /* followed by packed argv */
559 
560 struct msg_read_open {
561 	int	stream;
562 	int	fd;
563 }; /* followed by path */
564 
565 struct msg_read_data {
566 	int	stream;
567 };
568 
569 struct msg_read_done {
570 	int	stream;
571 	int	error;
572 };
573 
574 struct msg_write_open {
575 	int	stream;
576 	int	fd;
577 	int	flags;
578 }; /* followed by path */
579 
580 struct msg_write_data {
581 	int	stream;
582 }; /* followed by data */
583 
584 struct msg_write_ready {
585 	int	stream;
586 	int	error;
587 };
588 
589 struct msg_write_close {
590 	int	stream;
591 };
592 
593 /* Mode keys. */
594 #define MODEKEY_EMACS 0
595 #define MODEKEY_VI 1
596 
597 /* Modes. */
598 #define MODE_CURSOR 0x1
599 #define MODE_INSERT 0x2
600 #define MODE_KCURSOR 0x4
601 #define MODE_KKEYPAD 0x8
602 #define MODE_WRAP 0x10
603 #define MODE_MOUSE_STANDARD 0x20
604 #define MODE_MOUSE_BUTTON 0x40
605 #define MODE_BLINKING 0x80
606 #define MODE_MOUSE_UTF8 0x100
607 #define MODE_MOUSE_SGR 0x200
608 #define MODE_BRACKETPASTE 0x400
609 #define MODE_FOCUSON 0x800
610 #define MODE_MOUSE_ALL 0x1000
611 #define MODE_ORIGIN 0x2000
612 #define MODE_CRLF 0x4000
613 #define MODE_KEXTENDED 0x8000
614 
615 #define ALL_MODES 0xffffff
616 #define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ALL)
617 #define MOTION_MOUSE_MODES (MODE_MOUSE_BUTTON|MODE_MOUSE_ALL)
618 
619 /* A single UTF-8 character. */
620 typedef u_int utf8_char;
621 
622 /*
623  * An expanded UTF-8 character. UTF8_SIZE must be big enough to hold combining
624  * characters as well. It can't be more than 32 bytes without changes to how
625  * characters are stored.
626  */
627 #define UTF8_SIZE 21
628 struct utf8_data {
629 	u_char	data[UTF8_SIZE];
630 
631 	u_char	have;
632 	u_char	size;
633 
634 	u_char	width;	/* 0xff if invalid */
635 };
636 enum utf8_state {
637 	UTF8_MORE,
638 	UTF8_DONE,
639 	UTF8_ERROR
640 };
641 
642 /* Colour flags. */
643 #define COLOUR_FLAG_256 0x01000000
644 #define COLOUR_FLAG_RGB 0x02000000
645 
646 /* Special colours. */
647 #define COLOUR_DEFAULT(c) ((c) == 8 || (c) == 9)
648 
649 /* Grid attributes. Anything above 0xff is stored in an extended cell. */
650 #define GRID_ATTR_BRIGHT 0x1
651 #define GRID_ATTR_DIM 0x2
652 #define GRID_ATTR_UNDERSCORE 0x4
653 #define GRID_ATTR_BLINK 0x8
654 #define GRID_ATTR_REVERSE 0x10
655 #define GRID_ATTR_HIDDEN 0x20
656 #define GRID_ATTR_ITALICS 0x40
657 #define GRID_ATTR_CHARSET 0x80	/* alternative character set */
658 #define GRID_ATTR_STRIKETHROUGH 0x100
659 #define GRID_ATTR_UNDERSCORE_2 0x200
660 #define GRID_ATTR_UNDERSCORE_3 0x400
661 #define GRID_ATTR_UNDERSCORE_4 0x800
662 #define GRID_ATTR_UNDERSCORE_5 0x1000
663 #define GRID_ATTR_OVERLINE 0x2000
664 
665 /* All underscore attributes. */
666 #define GRID_ATTR_ALL_UNDERSCORE \
667 	(GRID_ATTR_UNDERSCORE|	 \
668 	 GRID_ATTR_UNDERSCORE_2| \
669 	 GRID_ATTR_UNDERSCORE_3| \
670 	 GRID_ATTR_UNDERSCORE_4| \
671 	 GRID_ATTR_UNDERSCORE_5)
672 
673 /* Grid flags. */
674 #define GRID_FLAG_FG256 0x1
675 #define GRID_FLAG_BG256 0x2
676 #define GRID_FLAG_PADDING 0x4
677 #define GRID_FLAG_EXTENDED 0x8
678 #define GRID_FLAG_SELECTED 0x10
679 #define GRID_FLAG_NOPALETTE 0x20
680 #define GRID_FLAG_CLEARED 0x40
681 
682 /* Grid line flags. */
683 #define GRID_LINE_WRAPPED 0x1
684 #define GRID_LINE_EXTENDED 0x2
685 #define GRID_LINE_DEAD 0x4
686 
687 /* Grid cell data. */
688 struct grid_cell {
689 	struct utf8_data	data;
690 	u_short			attr;
691 	u_char			flags;
692 	int			fg;
693 	int			bg;
694 	int			us;
695 };
696 
697 /* Grid extended cell entry. */
698 struct grid_extd_entry {
699 	utf8_char		data;
700 	u_short			attr;
701 	u_char			flags;
702 	int			fg;
703 	int			bg;
704 	int			us;
705 } __packed;
706 
707 /* Grid cell entry. */
708 struct grid_cell_entry {
709 	u_char			flags;
710 	union {
711 		u_int		offset;
712 		struct {
713 			u_char	attr;
714 			u_char	fg;
715 			u_char	bg;
716 			u_char	data;
717 		} data;
718 	};
719 } __packed;
720 
721 /* Grid line. */
722 struct grid_line {
723 	u_int			 cellused;
724 	u_int			 cellsize;
725 	struct grid_cell_entry	*celldata;
726 
727 	u_int			 extdsize;
728 	struct grid_extd_entry	*extddata;
729 
730 	int			 flags;
731 } __packed;
732 
733 /* Entire grid of cells. */
734 struct grid {
735 	int			 flags;
736 #define GRID_HISTORY 0x1 /* scroll lines into history */
737 
738 	u_int			 sx;
739 	u_int			 sy;
740 
741 	u_int			 hscrolled;
742 	u_int			 hsize;
743 	u_int			 hlimit;
744 
745 	struct grid_line	*linedata;
746 };
747 
748 /* Virtual cursor in a grid. */
749 struct grid_reader {
750 	struct grid	*gd;
751 	u_int		 cx;
752 	u_int		 cy;
753 };
754 
755 /* Style alignment. */
756 enum style_align {
757 	STYLE_ALIGN_DEFAULT,
758 	STYLE_ALIGN_LEFT,
759 	STYLE_ALIGN_CENTRE,
760 	STYLE_ALIGN_RIGHT,
761 	STYLE_ALIGN_ABSOLUTE_CENTRE
762 };
763 
764 /* Style list. */
765 enum style_list {
766 	STYLE_LIST_OFF,
767 	STYLE_LIST_ON,
768 	STYLE_LIST_FOCUS,
769 	STYLE_LIST_LEFT_MARKER,
770 	STYLE_LIST_RIGHT_MARKER,
771 };
772 
773 /* Style range. */
774 enum style_range_type {
775 	STYLE_RANGE_NONE,
776 	STYLE_RANGE_LEFT,
777 	STYLE_RANGE_RIGHT,
778 	STYLE_RANGE_WINDOW
779 };
780 struct style_range {
781 	enum style_range_type	 type;
782 	u_int			 argument;
783 
784 	u_int			 start;
785 	u_int			 end; /* not included */
786 
787 	TAILQ_ENTRY(style_range) entry;
788 };
789 TAILQ_HEAD(style_ranges, style_range);
790 
791 /* Style default. */
792 enum style_default_type {
793 	STYLE_DEFAULT_BASE,
794 	STYLE_DEFAULT_PUSH,
795 	STYLE_DEFAULT_POP
796 };
797 
798 /* Style option. */
799 struct style {
800 	struct grid_cell	gc;
801 	int			ignore;
802 
803 	int			fill;
804 	enum style_align	align;
805 	enum style_list		list;
806 
807 	enum style_range_type	range_type;
808 	u_int			range_argument;
809 
810 	enum style_default_type	default_type;
811 };
812 
813 /* Virtual screen. */
814 struct screen_sel;
815 struct screen_titles;
816 struct screen {
817 	char				*title;
818 	char				*path;
819 	struct screen_titles		*titles;
820 
821 	struct grid			*grid;	  /* grid data */
822 
823 	u_int				 cx;	  /* cursor x */
824 	u_int				 cy;	  /* cursor y */
825 
826 	u_int				 cstyle;  /* cursor style */
827 	char				*ccolour; /* cursor colour string */
828 
829 	u_int				 rupper;  /* scroll region top */
830 	u_int				 rlower;  /* scroll region bottom */
831 
832 	int				 mode;
833 
834 	u_int				 saved_cx;
835 	u_int				 saved_cy;
836 	struct grid			*saved_grid;
837 	struct grid_cell		 saved_cell;
838 	int				 saved_flags;
839 
840 	bitstr_t			*tabs;
841 	struct screen_sel		*sel;
842 
843 	struct screen_write_cline	*write_list;
844 };
845 
846 /* Screen write context. */
847 typedef void (*screen_write_init_ctx_cb)(struct screen_write_ctx *,
848     struct tty_ctx *);
849 struct screen_write_ctx {
850 	struct window_pane		*wp;
851 	struct screen			*s;
852 
853 	int				 flags;
854 #define SCREEN_WRITE_SYNC 0x1
855 
856 	screen_write_init_ctx_cb	 init_ctx_cb;
857 	void				*arg;
858 
859 	struct screen_write_citem	*item;
860 	u_int				 scrolled;
861 	u_int				 bg;
862 };
863 
864 /* Screen redraw context. */
865 struct screen_redraw_ctx {
866 	struct client	*c;
867 
868 	u_int		 statuslines;
869 	int		 statustop;
870 
871 	int		 pane_status;
872 	int		 pane_lines;
873 
874 	u_int		 sx;
875 	u_int		 sy;
876 	u_int		 ox;
877 	u_int		 oy;
878 };
879 
880 /* Screen size. */
881 #define screen_size_x(s) ((s)->grid->sx)
882 #define screen_size_y(s) ((s)->grid->sy)
883 #define screen_hsize(s) ((s)->grid->hsize)
884 #define screen_hlimit(s) ((s)->grid->hlimit)
885 
886 /* Menu. */
887 struct menu_item {
888 	const char	*name;
889 	key_code	 key;
890 	const char	*command;
891 };
892 struct menu {
893 	const char		*title;
894 	struct menu_item	*items;
895 	u_int			 count;
896 	u_int			 width;
897 };
898 typedef void (*menu_choice_cb)(struct menu *, u_int, key_code, void *);
899 
900 /*
901  * Window mode. Windows can be in several modes and this is used to call the
902  * right function to handle input and output.
903  */
904 struct window_mode_entry;
905 struct window_mode {
906 	const char	*name;
907 	const char	*default_format;
908 
909 	struct screen	*(*init)(struct window_mode_entry *,
910 			     struct cmd_find_state *, struct args *);
911 	void		 (*free)(struct window_mode_entry *);
912 	void		 (*resize)(struct window_mode_entry *, u_int, u_int);
913 	void		 (*update)(struct window_mode_entry *);
914 	void		 (*key)(struct window_mode_entry *, struct client *,
915 			     struct session *, struct winlink *, key_code,
916 			     struct mouse_event *);
917 
918 	const char	*(*key_table)(struct window_mode_entry *);
919 	void		 (*command)(struct window_mode_entry *, struct client *,
920 			     struct session *, struct winlink *, struct args *,
921 			     struct mouse_event *);
922 	void		 (*formats)(struct window_mode_entry *,
923 			     struct format_tree *);
924 };
925 
926 /* Active window mode. */
927 struct window_mode_entry {
928 	struct window_pane		*wp;
929 	struct window_pane		*swp;
930 
931 	const struct window_mode	*mode;
932 	void				*data;
933 
934 	struct screen			*screen;
935 	u_int				 prefix;
936 
937 	TAILQ_ENTRY(window_mode_entry)	 entry;
938 };
939 
940 /* Offsets into pane buffer. */
941 struct window_pane_offset {
942 	size_t	used;
943 };
944 
945 /* Queued pane resize. */
946 struct window_pane_resize {
947 	u_int				sx;
948 	u_int				sy;
949 
950 	u_int				osx;
951 	u_int				osy;
952 
953 	TAILQ_ENTRY(window_pane_resize)	entry;
954 };
955 TAILQ_HEAD(window_pane_resizes, window_pane_resize);
956 
957 /* Child window structure. */
958 struct window_pane {
959 	u_int		 id;
960 	u_int		 active_point;
961 
962 	struct window	*window;
963 	struct options	*options;
964 
965 	struct layout_cell *layout_cell;
966 	struct layout_cell *saved_layout_cell;
967 
968 	u_int		 sx;
969 	u_int		 sy;
970 
971 	u_int		 xoff;
972 	u_int		 yoff;
973 
974 	int		 fg;
975 	int		 bg;
976 
977 	int		 flags;
978 #define PANE_REDRAW 0x1
979 #define PANE_DROP 0x2
980 #define PANE_FOCUSED 0x4
981 /* 0x8 unused */
982 /* 0x10 unused */
983 #define PANE_FOCUSPUSH 0x20
984 #define PANE_INPUTOFF 0x40
985 #define PANE_CHANGED 0x80
986 #define PANE_EXITED 0x100
987 #define PANE_STATUSREADY 0x200
988 #define PANE_STATUSDRAWN 0x400
989 #define PANE_EMPTY 0x800
990 #define PANE_STYLECHANGED 0x1000
991 
992 	int		 argc;
993 	char	       **argv;
994 	char		*shell;
995 	char		*cwd;
996 
997 	pid_t		 pid;
998 	char		 tty[TTY_NAME_MAX];
999 	int		 status;
1000 
1001 	int		 fd;
1002 	struct bufferevent *event;
1003 
1004 	struct window_pane_offset offset;
1005 	size_t		 base_offset;
1006 
1007 	struct window_pane_resizes resize_queue;
1008 	struct event	 resize_timer;
1009 
1010 	struct input_ctx *ictx;
1011 
1012 	struct grid_cell cached_gc;
1013 	struct grid_cell cached_active_gc;
1014 	int		*palette;
1015 
1016 	int		 pipe_fd;
1017 	struct bufferevent *pipe_event;
1018 	struct window_pane_offset pipe_offset;
1019 
1020 	struct screen	*screen;
1021 	struct screen	 base;
1022 
1023 	struct screen	 status_screen;
1024 	size_t		 status_size;
1025 
1026 	TAILQ_HEAD(, window_mode_entry) modes;
1027 
1028 	char		*searchstr;
1029 	int		 searchregex;
1030 
1031 	int		 border_gc_set;
1032 	struct grid_cell border_gc;
1033 
1034 	TAILQ_ENTRY(window_pane) entry;
1035 	RB_ENTRY(window_pane) tree_entry;
1036 };
1037 TAILQ_HEAD(window_panes, window_pane);
1038 RB_HEAD(window_pane_tree, window_pane);
1039 
1040 /* Window structure. */
1041 struct window {
1042 	u_int		 id;
1043 	void		*latest;
1044 
1045 	char		*name;
1046 	struct event	 name_event;
1047 	struct timeval	 name_time;
1048 
1049 	struct event	 alerts_timer;
1050 	struct event	 offset_timer;
1051 
1052 	struct timeval	 activity_time;
1053 
1054 	struct window_pane *active;
1055 	struct window_pane *last;
1056 	struct window_panes panes;
1057 
1058 	int		 lastlayout;
1059 	struct layout_cell *layout_root;
1060 	struct layout_cell *saved_layout_root;
1061 	char		*old_layout;
1062 
1063 	u_int		 sx;
1064 	u_int		 sy;
1065 	u_int		 xpixel;
1066 	u_int		 ypixel;
1067 
1068 	u_int		 new_sx;
1069 	u_int		 new_sy;
1070 	u_int		 new_xpixel;
1071 	u_int		 new_ypixel;
1072 
1073 	int		 flags;
1074 #define WINDOW_BELL 0x1
1075 #define WINDOW_ACTIVITY 0x2
1076 #define WINDOW_SILENCE 0x4
1077 #define WINDOW_ZOOMED 0x8
1078 #define WINDOW_WASZOOMED 0x10
1079 #define WINDOW_RESIZE 0x20
1080 #define WINDOW_ALERTFLAGS (WINDOW_BELL|WINDOW_ACTIVITY|WINDOW_SILENCE)
1081 
1082 	int		 alerts_queued;
1083 	TAILQ_ENTRY(window) alerts_entry;
1084 
1085 	struct options	*options;
1086 
1087 	u_int		 references;
1088 	TAILQ_HEAD(, winlink) winlinks;
1089 
1090 	RB_ENTRY(window) entry;
1091 };
1092 RB_HEAD(windows, window);
1093 
1094 /* Entry on local window list. */
1095 struct winlink {
1096 	int		 idx;
1097 	struct session	*session;
1098 	struct window	*window;
1099 
1100 	int		 flags;
1101 #define WINLINK_BELL 0x1
1102 #define WINLINK_ACTIVITY 0x2
1103 #define WINLINK_SILENCE 0x4
1104 #define WINLINK_ALERTFLAGS (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_SILENCE)
1105 
1106 	RB_ENTRY(winlink) entry;
1107 	TAILQ_ENTRY(winlink) wentry;
1108 	TAILQ_ENTRY(winlink) sentry;
1109 };
1110 RB_HEAD(winlinks, winlink);
1111 TAILQ_HEAD(winlink_stack, winlink);
1112 
1113 /* Window size option. */
1114 #define WINDOW_SIZE_LARGEST 0
1115 #define WINDOW_SIZE_SMALLEST 1
1116 #define WINDOW_SIZE_MANUAL 2
1117 #define WINDOW_SIZE_LATEST 3
1118 
1119 /* Pane border status option. */
1120 #define PANE_STATUS_OFF 0
1121 #define PANE_STATUS_TOP 1
1122 #define PANE_STATUS_BOTTOM 2
1123 
1124 /* Pane border lines option. */
1125 #define PANE_LINES_SINGLE 0
1126 #define PANE_LINES_DOUBLE 1
1127 #define PANE_LINES_HEAVY 2
1128 #define PANE_LINES_SIMPLE 3
1129 #define PANE_LINES_NUMBER 4
1130 
1131 /* Layout direction. */
1132 enum layout_type {
1133 	LAYOUT_LEFTRIGHT,
1134 	LAYOUT_TOPBOTTOM,
1135 	LAYOUT_WINDOWPANE
1136 };
1137 
1138 /* Layout cells queue. */
1139 TAILQ_HEAD(layout_cells, layout_cell);
1140 
1141 /* Layout cell. */
1142 struct layout_cell {
1143 	enum layout_type type;
1144 
1145 	struct layout_cell *parent;
1146 
1147 	u_int		 sx;
1148 	u_int		 sy;
1149 
1150 	u_int		 xoff;
1151 	u_int		 yoff;
1152 
1153 	struct window_pane *wp;
1154 	struct layout_cells cells;
1155 
1156 	TAILQ_ENTRY(layout_cell) entry;
1157 };
1158 
1159 /* Environment variable. */
1160 struct environ_entry {
1161 	char		*name;
1162 	char		*value;
1163 
1164 	int		 flags;
1165 #define ENVIRON_HIDDEN 0x1
1166 
1167 	RB_ENTRY(environ_entry) entry;
1168 };
1169 
1170 /* Client session. */
1171 struct session_group {
1172 	const char		*name;
1173 	TAILQ_HEAD(, session)	 sessions;
1174 
1175 	RB_ENTRY(session_group)	 entry;
1176 };
1177 RB_HEAD(session_groups, session_group);
1178 
1179 struct session {
1180 	u_int		 id;
1181 
1182 	char		*name;
1183 	const char	*cwd;
1184 
1185 	struct timeval	 creation_time;
1186 	struct timeval	 last_attached_time;
1187 	struct timeval	 activity_time;
1188 	struct timeval	 last_activity_time;
1189 
1190 	struct event	 lock_timer;
1191 
1192 	struct winlink	*curw;
1193 	struct winlink_stack lastw;
1194 	struct winlinks	 windows;
1195 
1196 	int		 statusat;
1197 	u_int		 statuslines;
1198 
1199 	struct options	*options;
1200 
1201 #define SESSION_PASTING 0x1
1202 #define SESSION_ALERTED 0x2
1203 	int		 flags;
1204 
1205 	u_int		 attached;
1206 
1207 	struct termios	*tio;
1208 
1209 	struct environ	*environ;
1210 
1211 	int		 references;
1212 
1213 	TAILQ_ENTRY(session) gentry;
1214 	RB_ENTRY(session)    entry;
1215 };
1216 RB_HEAD(sessions, session);
1217 
1218 /* Mouse button masks. */
1219 #define MOUSE_MASK_BUTTONS 3
1220 #define MOUSE_MASK_SHIFT 4
1221 #define MOUSE_MASK_META 8
1222 #define MOUSE_MASK_CTRL 16
1223 #define MOUSE_MASK_DRAG 32
1224 #define MOUSE_MASK_WHEEL 64
1225 
1226 /* Mouse wheel states. */
1227 #define MOUSE_WHEEL_UP 0
1228 #define MOUSE_WHEEL_DOWN 1
1229 
1230 /* Mouse helpers. */
1231 #define MOUSE_BUTTONS(b) ((b) & MOUSE_MASK_BUTTONS)
1232 #define MOUSE_WHEEL(b) ((b) & MOUSE_MASK_WHEEL)
1233 #define MOUSE_DRAG(b) ((b) & MOUSE_MASK_DRAG)
1234 #define MOUSE_RELEASE(b) (((b) & MOUSE_MASK_BUTTONS) == 3)
1235 
1236 /* Mouse input. */
1237 struct mouse_event {
1238 	int		valid;
1239 	int		ignore;
1240 
1241 	key_code	key;
1242 
1243 	int		statusat;
1244 	u_int		statuslines;
1245 
1246 	u_int		x;
1247 	u_int		y;
1248 	u_int		b;
1249 
1250 	u_int		lx;
1251 	u_int		ly;
1252 	u_int		lb;
1253 
1254 	u_int		ox;
1255 	u_int		oy;
1256 
1257 	int		s;
1258 	int		w;
1259 	int		wp;
1260 
1261 	u_int		sgr_type;
1262 	u_int		sgr_b;
1263 };
1264 
1265 /* Key event. */
1266 struct key_event {
1267 	key_code		key;
1268 	struct mouse_event	m;
1269 };
1270 
1271 /* TTY information. */
1272 struct tty_key {
1273 	char		 ch;
1274 	key_code	 key;
1275 
1276 	struct tty_key	*left;
1277 	struct tty_key	*right;
1278 
1279 	struct tty_key	*next;
1280 };
1281 
1282 struct tty_code;
1283 struct tty_term {
1284 	char		*name;
1285 	struct tty	*tty;
1286 	int		 features;
1287 
1288 	char		 acs[UCHAR_MAX + 1][2];
1289 
1290 	struct tty_code	*codes;
1291 
1292 #define TERM_256COLOURS 0x1
1293 #define TERM_NOAM 0x2
1294 #define TERM_DECSLRM 0x4
1295 #define TERM_DECFRA 0x8
1296 #define TERM_RGBCOLOURS 0x10
1297 #define TERM_VT100LIKE 0x20
1298 	int		 flags;
1299 
1300 	LIST_ENTRY(tty_term) entry;
1301 };
1302 LIST_HEAD(tty_terms, tty_term);
1303 
1304 struct tty {
1305 	struct client	*client;
1306 	struct event	 start_timer;
1307 
1308 	u_int		 sx;
1309 	u_int		 sy;
1310 	u_int		 xpixel;
1311 	u_int		 ypixel;
1312 
1313 	u_int		 cx;
1314 	u_int		 cy;
1315 	u_int		 cstyle;
1316 	char		*ccolour;
1317 
1318 	int		 oflag;
1319 	u_int		 oox;
1320 	u_int		 ooy;
1321 	u_int		 osx;
1322 	u_int		 osy;
1323 
1324 	int		 mode;
1325 
1326 	u_int		 rlower;
1327 	u_int		 rupper;
1328 
1329 	u_int		 rleft;
1330 	u_int		 rright;
1331 
1332 	struct event	 event_in;
1333 	struct evbuffer	*in;
1334 	struct event	 event_out;
1335 	struct evbuffer	*out;
1336 	struct event	 timer;
1337 	size_t		 discarded;
1338 
1339 	struct termios	 tio;
1340 
1341 	struct grid_cell cell;
1342 	struct grid_cell last_cell;
1343 
1344 #define TTY_NOCURSOR 0x1
1345 #define TTY_FREEZE 0x2
1346 #define TTY_TIMER 0x4
1347 /* 0x8 unused */
1348 #define TTY_STARTED 0x10
1349 #define TTY_OPENED 0x20
1350 /* 0x40 unused */
1351 #define TTY_BLOCK 0x80
1352 #define TTY_HAVEDA 0x100
1353 #define TTY_HAVEXDA 0x200
1354 #define TTY_SYNCING 0x400
1355 	int		 flags;
1356 
1357 	struct tty_term	*term;
1358 
1359 	u_int		 mouse_last_x;
1360 	u_int		 mouse_last_y;
1361 	u_int		 mouse_last_b;
1362 	int		 mouse_drag_flag;
1363 	void		(*mouse_drag_update)(struct client *,
1364 			    struct mouse_event *);
1365 	void		(*mouse_drag_release)(struct client *,
1366 			    struct mouse_event *);
1367 
1368 	struct event	 key_timer;
1369 	struct tty_key	*key_tree;
1370 };
1371 
1372 /* TTY command context. */
1373 typedef void (*tty_ctx_redraw_cb)(const struct tty_ctx *);
1374 typedef int (*tty_ctx_set_client_cb)(struct tty_ctx *, struct client *);
1375 struct tty_ctx {
1376 	struct screen		*s;
1377 
1378 	tty_ctx_redraw_cb	 redraw_cb;
1379 	tty_ctx_set_client_cb	 set_client_cb;
1380 	void			*arg;
1381 
1382 	const struct grid_cell	*cell;
1383 	int			 wrapped;
1384 
1385 	u_int			 num;
1386 	void			*ptr;
1387 
1388 	/*
1389 	 * Cursor and region position before the screen was updated - this is
1390 	 * where the command should be applied; the values in the screen have
1391 	 * already been updated.
1392 	 */
1393 	u_int		 ocx;
1394 	u_int		 ocy;
1395 
1396 	u_int		 orupper;
1397 	u_int		 orlower;
1398 
1399 	/* Target region (usually pane) offset and size. */
1400 	u_int		 xoff;
1401 	u_int		 yoff;
1402 	u_int		 rxoff;
1403 	u_int		 ryoff;
1404 	u_int		 sx;
1405 	u_int		 sy;
1406 
1407 	/* The background colour used for clearing (erasing). */
1408 	u_int		 bg;
1409 
1410 	/* The default colours and palette. */
1411 	struct grid_cell defaults;
1412 	int		*palette;
1413 
1414 	/* Containing region (usually window) offset and size. */
1415 	int		 bigger;
1416 	u_int		 wox;
1417 	u_int		 woy;
1418 	u_int		 wsx;
1419 	u_int		 wsy;
1420 };
1421 
1422 /* Saved message entry. */
1423 struct message_entry {
1424 	char				*msg;
1425 	u_int				 msg_num;
1426 	struct timeval			 msg_time;
1427 
1428 	TAILQ_ENTRY(message_entry)	 entry;
1429 };
1430 TAILQ_HEAD(message_list, message_entry);
1431 
1432 /* Parsed arguments structures. */
1433 struct args_entry;
1434 RB_HEAD(args_tree, args_entry);
1435 struct args {
1436 	struct args_tree	  tree;
1437 	int			  argc;
1438 	char			**argv;
1439 };
1440 
1441 /* Command find structures. */
1442 enum cmd_find_type {
1443 	CMD_FIND_PANE,
1444 	CMD_FIND_WINDOW,
1445 	CMD_FIND_SESSION,
1446 };
1447 struct cmd_find_state {
1448 	int			 flags;
1449 	struct cmd_find_state	*current;
1450 
1451 	struct session		*s;
1452 	struct winlink		*wl;
1453 	struct window		*w;
1454 	struct window_pane	*wp;
1455 	int			 idx;
1456 };
1457 
1458 /* Command find flags. */
1459 #define CMD_FIND_PREFER_UNATTACHED 0x1
1460 #define CMD_FIND_QUIET 0x2
1461 #define CMD_FIND_WINDOW_INDEX 0x4
1462 #define CMD_FIND_DEFAULT_MARKED 0x8
1463 #define CMD_FIND_EXACT_SESSION 0x10
1464 #define CMD_FIND_EXACT_WINDOW 0x20
1465 #define CMD_FIND_CANFAIL 0x40
1466 
1467 /* List of commands. */
1468 struct cmd_list {
1469 	int		 references;
1470 	u_int		 group;
1471 	struct cmds	*list;
1472 };
1473 
1474 /* Command return values. */
1475 enum cmd_retval {
1476 	CMD_RETURN_ERROR = -1,
1477 	CMD_RETURN_NORMAL = 0,
1478 	CMD_RETURN_WAIT,
1479 	CMD_RETURN_STOP
1480 };
1481 
1482 /* Command parse result. */
1483 enum cmd_parse_status {
1484 	CMD_PARSE_EMPTY,
1485 	CMD_PARSE_ERROR,
1486 	CMD_PARSE_SUCCESS
1487 };
1488 struct cmd_parse_result {
1489 	enum cmd_parse_status	 status;
1490 	struct cmd_list		*cmdlist;
1491 	char			*error;
1492 };
1493 struct cmd_parse_input {
1494 	int			 flags;
1495 #define CMD_PARSE_QUIET 0x1
1496 #define CMD_PARSE_PARSEONLY 0x2
1497 #define CMD_PARSE_NOALIAS 0x4
1498 #define CMD_PARSE_VERBOSE 0x8
1499 #define CMD_PARSE_ONEGROUP 0x10
1500 
1501 	const char		*file;
1502 	u_int			 line;
1503 
1504 	struct cmdq_item	*item;
1505 	struct client		*c;
1506 	struct cmd_find_state	 fs;
1507 };
1508 
1509 /* Command queue flags. */
1510 #define CMDQ_STATE_REPEAT 0x1
1511 #define CMDQ_STATE_CONTROL 0x2
1512 #define CMDQ_STATE_NOHOOKS 0x4
1513 
1514 /* Command queue callback. */
1515 typedef enum cmd_retval (*cmdq_cb) (struct cmdq_item *, void *);
1516 
1517 /* Command definition flag. */
1518 struct cmd_entry_flag {
1519 	char			 flag;
1520 	enum cmd_find_type	 type;
1521 	int			 flags;
1522 };
1523 
1524 /* Command definition. */
1525 struct cmd_entry {
1526 	const char		*name;
1527 	const char		*alias;
1528 
1529 	struct {
1530 		const char	*template;
1531 		int		 lower;
1532 		int		 upper;
1533 	} args;
1534 	const char		*usage;
1535 
1536 	struct cmd_entry_flag	 source;
1537 	struct cmd_entry_flag	 target;
1538 
1539 #define CMD_STARTSERVER 0x1
1540 #define CMD_READONLY 0x2
1541 #define CMD_AFTERHOOK 0x4
1542 #define CMD_CLIENT_CFLAG 0x8
1543 #define CMD_CLIENT_TFLAG 0x10
1544 #define CMD_CLIENT_CANFAIL 0x20
1545 	int		 flags;
1546 
1547 	enum cmd_retval	 (*exec)(struct cmd *, struct cmdq_item *);
1548 };
1549 
1550 /* Status line. */
1551 #define STATUS_LINES_LIMIT 5
1552 struct status_line_entry {
1553 	char			*expanded;
1554 	struct style_ranges	 ranges;
1555 };
1556 struct status_line {
1557 	struct event		 timer;
1558 
1559 	struct screen		 screen;
1560 	struct screen		*active;
1561 	int			 references;
1562 
1563 	struct grid_cell	 style;
1564 	struct status_line_entry entries[STATUS_LINES_LIMIT];
1565 };
1566 
1567 /* File in client. */
1568 typedef void (*client_file_cb) (struct client *, const char *, int, int,
1569     struct evbuffer *, void *);
1570 struct client_file {
1571 	struct client			*c;
1572 	struct tmuxpeer			*peer;
1573 	struct client_files		*tree;
1574 	int				 references;
1575 	int				 stream;
1576 
1577 	char				*path;
1578 	struct evbuffer			*buffer;
1579 	struct bufferevent		*event;
1580 
1581 	int				 fd;
1582 	int				 error;
1583 	int				 closed;
1584 
1585 	client_file_cb			 cb;
1586 	void				*data;
1587 
1588 	RB_ENTRY(client_file)		 entry;
1589 };
1590 RB_HEAD(client_files, client_file);
1591 
1592 /* Client window. */
1593 struct client_window {
1594 	u_int			 window;
1595 	struct window_pane	*pane;
1596 	RB_ENTRY(client_window)	 entry;
1597 };
1598 RB_HEAD(client_windows, client_window);
1599 
1600 /* Client connection. */
1601 typedef int (*prompt_input_cb)(struct client *, void *, const char *, int);
1602 typedef void (*prompt_free_cb)(void *);
1603 typedef int (*overlay_check_cb)(struct client *, u_int, u_int);
1604 typedef struct screen *(*overlay_mode_cb)(struct client *, u_int *, u_int *);
1605 typedef void (*overlay_draw_cb)(struct client *, struct screen_redraw_ctx *);
1606 typedef int (*overlay_key_cb)(struct client *, struct key_event *);
1607 typedef void (*overlay_free_cb)(struct client *);
1608 struct client {
1609 	const char	*name;
1610 	struct tmuxpeer	*peer;
1611 	struct cmdq_list *queue;
1612 
1613 	struct client_windows windows;
1614 
1615 	struct control_state *control_state;
1616 	u_int		 pause_age;
1617 
1618 	pid_t		 pid;
1619 	int		 fd;
1620 	int		 out_fd;
1621 	struct event	 event;
1622 	int		 retval;
1623 
1624 	struct timeval	 creation_time;
1625 	struct timeval	 activity_time;
1626 
1627 	struct environ	*environ;
1628 	struct format_job_tree	*jobs;
1629 
1630 	char		*title;
1631 	const char	*cwd;
1632 
1633 	char		*term_name;
1634 	int		 term_features;
1635 	char		*term_type;
1636 	char	       **term_caps;
1637 	u_int		 term_ncaps;
1638 
1639 	char		*ttyname;
1640 	struct tty	 tty;
1641 
1642 	size_t		 written;
1643 	size_t		 discarded;
1644 	size_t		 redraw;
1645 
1646 	struct event	 repeat_timer;
1647 
1648 	struct event	 click_timer;
1649 	u_int		 click_button;
1650 	struct mouse_event click_event;
1651 
1652 	struct status_line status;
1653 
1654 #define CLIENT_TERMINAL 0x1
1655 #define CLIENT_LOGIN 0x2
1656 #define CLIENT_EXIT 0x4
1657 #define CLIENT_REDRAWWINDOW 0x8
1658 #define CLIENT_REDRAWSTATUS 0x10
1659 #define CLIENT_REPEAT 0x20
1660 #define CLIENT_SUSPENDED 0x40
1661 #define CLIENT_ATTACHED 0x80
1662 #define CLIENT_EXITED 0x100
1663 #define CLIENT_DEAD 0x200
1664 #define CLIENT_REDRAWBORDERS 0x400
1665 #define CLIENT_READONLY 0x800
1666 #define CLIENT_NOSTARTSERVER 0x1000
1667 #define CLIENT_CONTROL 0x2000
1668 #define CLIENT_CONTROLCONTROL 0x4000
1669 #define CLIENT_FOCUSED 0x8000
1670 #define CLIENT_UTF8 0x10000
1671 #define CLIENT_IGNORESIZE 0x20000
1672 #define CLIENT_IDENTIFIED 0x40000
1673 #define CLIENT_STATUSFORCE 0x80000
1674 #define CLIENT_DOUBLECLICK 0x100000
1675 #define CLIENT_TRIPLECLICK 0x200000
1676 #define CLIENT_SIZECHANGED 0x400000
1677 #define CLIENT_STATUSOFF 0x800000
1678 #define CLIENT_REDRAWSTATUSALWAYS 0x1000000
1679 #define CLIENT_REDRAWOVERLAY 0x2000000
1680 #define CLIENT_CONTROL_NOOUTPUT 0x4000000
1681 #define CLIENT_DEFAULTSOCKET 0x8000000
1682 #define CLIENT_STARTSERVER 0x10000000
1683 #define CLIENT_REDRAWPANES 0x20000000
1684 #define CLIENT_NOFORK 0x40000000
1685 #define CLIENT_ACTIVEPANE 0x80000000ULL
1686 #define CLIENT_CONTROL_PAUSEAFTER 0x100000000ULL
1687 #define CLIENT_CONTROL_WAITEXIT 0x200000000ULL
1688 #define CLIENT_ALLREDRAWFLAGS		\
1689 	(CLIENT_REDRAWWINDOW|		\
1690 	 CLIENT_REDRAWSTATUS|		\
1691 	 CLIENT_REDRAWSTATUSALWAYS|	\
1692 	 CLIENT_REDRAWBORDERS|		\
1693 	 CLIENT_REDRAWOVERLAY|		\
1694 	 CLIENT_REDRAWPANES)
1695 #define CLIENT_UNATTACHEDFLAGS	\
1696 	(CLIENT_DEAD|		\
1697 	 CLIENT_SUSPENDED|	\
1698 	 CLIENT_EXIT)
1699 #define CLIENT_NOSIZEFLAGS	\
1700 	(CLIENT_DEAD|		\
1701 	 CLIENT_SUSPENDED|	\
1702 	 CLIENT_EXIT)
1703 	uint64_t	 flags;
1704 
1705 	enum {
1706 		CLIENT_EXIT_RETURN,
1707 		CLIENT_EXIT_SHUTDOWN,
1708 		CLIENT_EXIT_DETACH
1709 	}		 exit_type;
1710 	enum msgtype	 exit_msgtype;
1711 	char		*exit_session;
1712 	char		*exit_message;
1713 
1714 	struct key_table *keytable;
1715 
1716 	uint64_t	 redraw_panes;
1717 
1718 	int		 message_ignore_keys;
1719 	int		 message_ignore_styles;
1720 	char		*message_string;
1721 	struct event	 message_timer;
1722 
1723 	char		*prompt_string;
1724 	struct utf8_data *prompt_buffer;
1725 	char		*prompt_last;
1726 	size_t		 prompt_index;
1727 	prompt_input_cb	 prompt_inputcb;
1728 	prompt_free_cb	 prompt_freecb;
1729 	void		*prompt_data;
1730 	u_int		 prompt_hindex;
1731 	enum { PROMPT_ENTRY, PROMPT_COMMAND } prompt_mode;
1732 	struct utf8_data *prompt_saved;
1733 
1734 #define PROMPT_SINGLE 0x1
1735 #define PROMPT_NUMERIC 0x2
1736 #define PROMPT_INCREMENTAL 0x4
1737 #define PROMPT_NOFORMAT 0x8
1738 #define PROMPT_KEY 0x10
1739 #define PROMPT_WINDOW 0x20
1740 #define PROMPT_TARGET 0x40
1741 	int		 prompt_flags;
1742 
1743 	struct session	*session;
1744 	struct session	*last_session;
1745 
1746 	int		 references;
1747 
1748 	void		*pan_window;
1749 	u_int		 pan_ox;
1750 	u_int		 pan_oy;
1751 
1752 	overlay_check_cb overlay_check;
1753 	overlay_mode_cb	 overlay_mode;
1754 	overlay_draw_cb	 overlay_draw;
1755 	overlay_key_cb	 overlay_key;
1756 	overlay_free_cb	 overlay_free;
1757 	void		*overlay_data;
1758 	struct event	 overlay_timer;
1759 
1760 	struct client_files files;
1761 
1762 	TAILQ_ENTRY(client) entry;
1763 };
1764 TAILQ_HEAD(clients, client);
1765 
1766 /* Control mode subscription type. */
1767 enum control_sub_type {
1768 	CONTROL_SUB_SESSION,
1769 	CONTROL_SUB_PANE,
1770 	CONTROL_SUB_ALL_PANES,
1771 	CONTROL_SUB_WINDOW,
1772 	CONTROL_SUB_ALL_WINDOWS
1773 };
1774 
1775 /* Key binding and key table. */
1776 struct key_binding {
1777 	key_code		 key;
1778 	struct cmd_list		*cmdlist;
1779 	const char		*note;
1780 
1781 	int			 flags;
1782 #define KEY_BINDING_REPEAT 0x1
1783 
1784 	RB_ENTRY(key_binding)	 entry;
1785 };
1786 RB_HEAD(key_bindings, key_binding);
1787 
1788 struct key_table {
1789 	const char		*name;
1790 	struct key_bindings	 key_bindings;
1791 	struct key_bindings	 default_key_bindings;
1792 
1793 	u_int			 references;
1794 
1795 	RB_ENTRY(key_table)	 entry;
1796 };
1797 RB_HEAD(key_tables, key_table);
1798 
1799 /* Option data. */
1800 RB_HEAD(options_array, options_array_item);
1801 union options_value {
1802 	char				 *string;
1803 	long long			  number;
1804 	struct style			  style;
1805 	struct options_array		  array;
1806 	struct cmd_list			 *cmdlist;
1807 };
1808 
1809 /* Option table entries. */
1810 enum options_table_type {
1811 	OPTIONS_TABLE_STRING,
1812 	OPTIONS_TABLE_NUMBER,
1813 	OPTIONS_TABLE_KEY,
1814 	OPTIONS_TABLE_COLOUR,
1815 	OPTIONS_TABLE_FLAG,
1816 	OPTIONS_TABLE_CHOICE,
1817 	OPTIONS_TABLE_COMMAND
1818 };
1819 
1820 #define OPTIONS_TABLE_NONE 0
1821 #define OPTIONS_TABLE_SERVER 0x1
1822 #define OPTIONS_TABLE_SESSION 0x2
1823 #define OPTIONS_TABLE_WINDOW 0x4
1824 #define OPTIONS_TABLE_PANE 0x8
1825 
1826 #define OPTIONS_TABLE_IS_ARRAY 0x1
1827 #define OPTIONS_TABLE_IS_HOOK 0x2
1828 #define OPTIONS_TABLE_IS_STYLE 0x4
1829 
1830 struct options_table_entry {
1831 	const char		 *name;
1832 	const char		 *alternative_name;
1833 	enum options_table_type	  type;
1834 	int			  scope;
1835 	int			  flags;
1836 
1837 	u_int			  minimum;
1838 	u_int			  maximum;
1839 	const char		**choices;
1840 
1841 	const char		 *default_str;
1842 	long long		  default_num;
1843 	const char		**default_arr;
1844 
1845 	const char		 *separator;
1846 	const char		 *pattern;
1847 
1848 	const char		 *text;
1849 	const char		 *unit;
1850 };
1851 
1852 struct options_name_map {
1853 	const char		*from;
1854 	const char		*to;
1855 };
1856 
1857 /* Common command usages. */
1858 #define CMD_TARGET_PANE_USAGE "[-t target-pane]"
1859 #define CMD_TARGET_WINDOW_USAGE "[-t target-window]"
1860 #define CMD_TARGET_SESSION_USAGE "[-t target-session]"
1861 #define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
1862 #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]"
1863 #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
1864 #define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]"
1865 #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
1866 #define CMD_BUFFER_USAGE "[-b buffer-name]"
1867 
1868 /* Spawn common context. */
1869 struct spawn_context {
1870 	struct cmdq_item	 *item;
1871 
1872 	struct session		 *s;
1873 	struct winlink		 *wl;
1874 	struct client		 *tc;
1875 
1876 	struct window_pane	 *wp0;
1877 	struct layout_cell	 *lc;
1878 
1879 	const char		 *name;
1880 	char			**argv;
1881 	int			  argc;
1882 	struct environ		 *environ;
1883 
1884 	int			  idx;
1885 	const char		 *cwd;
1886 
1887 	int			  flags;
1888 #define SPAWN_KILL 0x1
1889 #define SPAWN_DETACHED 0x2
1890 #define SPAWN_RESPAWN 0x4
1891 #define SPAWN_BEFORE 0x8
1892 #define SPAWN_NONOTIFY 0x10
1893 #define SPAWN_FULLSIZE 0x20
1894 #define SPAWN_EMPTY 0x40
1895 #define SPAWN_ZOOM 0x80
1896 };
1897 
1898 /* Mode tree sort order. */
1899 struct mode_tree_sort_criteria {
1900 	u_int	field;
1901 	int	reversed;
1902 };
1903 
1904 /* tmux.c */
1905 extern struct options	*global_options;
1906 extern struct options	*global_s_options;
1907 extern struct options	*global_w_options;
1908 extern struct environ	*global_environ;
1909 extern struct timeval	 start_time;
1910 extern const char	*socket_path;
1911 extern const char	*shell_command;
1912 extern int		 ptm_fd;
1913 extern const char	*shell_command;
1914 int		 checkshell(const char *);
1915 void		 setblocking(int, int);
1916 uint64_t	 get_timer(void);
1917 const char	*sig2name(int);
1918 const char	*find_cwd(void);
1919 const char	*find_home(void);
1920 const char	*getversion(void);
1921 
1922 /* proc.c */
1923 struct imsg;
1924 int	proc_send(struct tmuxpeer *, enum msgtype, int, const void *, size_t);
1925 struct tmuxproc *proc_start(const char *);
1926 void	proc_loop(struct tmuxproc *, int (*)(void));
1927 void	proc_exit(struct tmuxproc *);
1928 void	proc_set_signals(struct tmuxproc *, void(*)(int));
1929 void	proc_clear_signals(struct tmuxproc *, int);
1930 struct tmuxpeer *proc_add_peer(struct tmuxproc *, int,
1931 	    void (*)(struct imsg *, void *), void *);
1932 void	proc_remove_peer(struct tmuxpeer *);
1933 void	proc_kill_peer(struct tmuxpeer *);
1934 void	proc_toggle_log(struct tmuxproc *);
1935 pid_t	proc_fork_and_daemon(int *);
1936 
1937 /* cfg.c */
1938 extern int cfg_finished;
1939 extern struct client *cfg_client;
1940 extern char **cfg_files;
1941 extern u_int cfg_nfiles;
1942 extern int cfg_quiet;
1943 void	start_cfg(void);
1944 int	load_cfg(const char *, struct client *, struct cmdq_item *, int,
1945 	    struct cmdq_item **);
1946 int	load_cfg_from_buffer(const void *, size_t, const char *,
1947 	    struct client *, struct cmdq_item *, int, struct cmdq_item **);
1948 void printflike(1, 2) cfg_add_cause(const char *, ...);
1949 void	cfg_print_causes(struct cmdq_item *);
1950 void	cfg_show_causes(struct session *);
1951 
1952 /* paste.c */
1953 struct paste_buffer;
1954 const char	*paste_buffer_name(struct paste_buffer *);
1955 u_int		 paste_buffer_order(struct paste_buffer *);
1956 time_t		 paste_buffer_created(struct paste_buffer *);
1957 const char	*paste_buffer_data(struct paste_buffer *, size_t *);
1958 struct paste_buffer *paste_walk(struct paste_buffer *);
1959 struct paste_buffer *paste_get_top(const char **);
1960 struct paste_buffer *paste_get_name(const char *);
1961 void		 paste_free(struct paste_buffer *);
1962 void		 paste_add(const char *, char *, size_t);
1963 int		 paste_rename(const char *, const char *, char **);
1964 int		 paste_set(char *, size_t, const char *, char **);
1965 void		 paste_replace(struct paste_buffer *, char *, size_t);
1966 char		*paste_make_sample(struct paste_buffer *);
1967 
1968 /* format.c */
1969 #define FORMAT_STATUS 0x1
1970 #define FORMAT_FORCE 0x2
1971 #define FORMAT_NOJOBS 0x4
1972 #define FORMAT_VERBOSE 0x8
1973 #define FORMAT_NONE 0
1974 #define FORMAT_PANE 0x80000000U
1975 #define FORMAT_WINDOW 0x40000000U
1976 struct format_tree;
1977 struct format_modifier;
1978 typedef void *(*format_cb)(struct format_tree *);
1979 void		 format_tidy_jobs(void);
1980 const char	*format_skip(const char *, const char *);
1981 int		 format_true(const char *);
1982 struct format_tree *format_create(struct client *, struct cmdq_item *, int,
1983 		     int);
1984 void		 format_free(struct format_tree *);
1985 void		 format_merge(struct format_tree *, struct format_tree *);
1986 struct window_pane *format_get_pane(struct format_tree *);
1987 void printflike(3, 4) format_add(struct format_tree *, const char *,
1988 		     const char *, ...);
1989 void		 format_add_tv(struct format_tree *, const char *,
1990 		     struct timeval *);
1991 void		 format_add_cb(struct format_tree *, const char *, format_cb);
1992 void		 format_each(struct format_tree *, void (*)(const char *,
1993 		     const char *, void *), void *);
1994 char		*format_expand_time(struct format_tree *, const char *);
1995 char		*format_expand(struct format_tree *, const char *);
1996 char		*format_single(struct cmdq_item *, const char *,
1997 		     struct client *, struct session *, struct winlink *,
1998 		     struct window_pane *);
1999 char		*format_single_from_state(struct cmdq_item *, const char *,
2000 		    struct client *, struct cmd_find_state *);
2001 char		*format_single_from_target(struct cmdq_item *, const char *);
2002 struct format_tree *format_create_defaults(struct cmdq_item *, struct client *,
2003 		     struct session *, struct winlink *, struct window_pane *);
2004 struct format_tree *format_create_from_state(struct cmdq_item *,
2005 		     struct client *, struct cmd_find_state *);
2006 struct format_tree *format_create_from_target(struct cmdq_item *);
2007 void		 format_defaults(struct format_tree *, struct client *,
2008 		     struct session *, struct winlink *, struct window_pane *);
2009 void		 format_defaults_window(struct format_tree *, struct window *);
2010 void		 format_defaults_pane(struct format_tree *,
2011 		     struct window_pane *);
2012 void		 format_defaults_paste_buffer(struct format_tree *,
2013 		     struct paste_buffer *);
2014 void		 format_lost_client(struct client *);
2015 char		*format_grid_word(struct grid *, u_int, u_int);
2016 char		*format_grid_line(struct grid *, u_int);
2017 
2018 /* format-draw.c */
2019 void		 format_draw(struct screen_write_ctx *,
2020 		     const struct grid_cell *, u_int, const char *,
2021 		     struct style_ranges *);
2022 u_int		 format_width(const char *);
2023 char		*format_trim_left(const char *, u_int);
2024 char		*format_trim_right(const char *, u_int);
2025 
2026 /* notify.c */
2027 void	notify_hook(struct cmdq_item *, const char *);
2028 void	notify_client(const char *, struct client *);
2029 void	notify_session(const char *, struct session *);
2030 void	notify_winlink(const char *, struct winlink *);
2031 void	notify_session_window(const char *, struct session *, struct window *);
2032 void	notify_window(const char *, struct window *);
2033 void	notify_pane(const char *, struct window_pane *);
2034 
2035 /* options.c */
2036 struct options	*options_create(struct options *);
2037 void		 options_free(struct options *);
2038 struct options	*options_get_parent(struct options *);
2039 void		 options_set_parent(struct options *, struct options *);
2040 struct options_entry *options_first(struct options *);
2041 struct options_entry *options_next(struct options_entry *);
2042 struct options_entry *options_empty(struct options *,
2043 		     const struct options_table_entry *);
2044 struct options_entry *options_default(struct options *,
2045 		     const struct options_table_entry *);
2046 char		*options_default_to_string(const struct options_table_entry *);
2047 const char	*options_name(struct options_entry *);
2048 struct options	*options_owner(struct options_entry *);
2049 const struct options_table_entry *options_table_entry(struct options_entry *);
2050 struct options_entry *options_get_only(struct options *, const char *);
2051 struct options_entry *options_get(struct options *, const char *);
2052 void		 options_array_clear(struct options_entry *);
2053 union options_value *options_array_get(struct options_entry *, u_int);
2054 int		 options_array_set(struct options_entry *, u_int, const char *,
2055 		     int, char **);
2056 int		 options_array_assign(struct options_entry *, const char *,
2057 		     char **);
2058 struct options_array_item *options_array_first(struct options_entry *);
2059 struct options_array_item *options_array_next(struct options_array_item *);
2060 u_int		 options_array_item_index(struct options_array_item *);
2061 union options_value *options_array_item_value(struct options_array_item *);
2062 int		 options_is_array(struct options_entry *);
2063 int		 options_is_string(struct options_entry *);
2064 char		*options_to_string(struct options_entry *, int, int);
2065 char		*options_parse(const char *, int *);
2066 struct options_entry *options_parse_get(struct options *, const char *, int *,
2067 		     int);
2068 char		*options_match(const char *, int *, int *);
2069 struct options_entry *options_match_get(struct options *, const char *, int *,
2070 		     int, int *);
2071 const char	*options_get_string(struct options *, const char *);
2072 long long	 options_get_number(struct options *, const char *);
2073 struct options_entry * printflike(4, 5) options_set_string(struct options *,
2074 		     const char *, int, const char *, ...);
2075 struct options_entry *options_set_number(struct options *, const char *,
2076 		     long long);
2077 int		 options_scope_from_name(struct args *, int,
2078 		     const char *, struct cmd_find_state *, struct options **,
2079 		     char **);
2080 int		 options_scope_from_flags(struct args *, int,
2081 		     struct cmd_find_state *, struct options **, char **);
2082 struct style	*options_string_to_style(struct options *, const char *,
2083 		     struct format_tree *);
2084 int		 options_from_string(struct options *,
2085 		     const struct options_table_entry *, const char *,
2086 		     const char *, int, char **);
2087 void		 options_push_changes(const char *);
2088 int		 options_remove_or_default(struct options_entry *, int,
2089 		     char **);
2090 
2091 /* options-table.c */
2092 extern const struct options_table_entry	options_table[];
2093 extern const struct options_name_map	options_other_names[];
2094 
2095 /* job.c */
2096 typedef void (*job_update_cb) (struct job *);
2097 typedef void (*job_complete_cb) (struct job *);
2098 typedef void (*job_free_cb) (void *);
2099 #define JOB_NOWAIT 0x1
2100 #define JOB_KEEPWRITE 0x2
2101 #define JOB_PTY 0x4
2102 struct job	*job_run(const char *, int, char **, struct session *,
2103 		     const char *, job_update_cb, job_complete_cb, job_free_cb,
2104 		     void *, int, int, int);
2105 void		 job_free(struct job *);
2106 void		 job_resize(struct job *, u_int, u_int);
2107 void		 job_check_died(pid_t, int);
2108 int		 job_get_status(struct job *);
2109 void		*job_get_data(struct job *);
2110 struct bufferevent *job_get_event(struct job *);
2111 void		 job_kill_all(void);
2112 int		 job_still_running(void);
2113 void		 job_print_summary(struct cmdq_item *, int);
2114 
2115 /* environ.c */
2116 struct environ *environ_create(void);
2117 void	environ_free(struct environ *);
2118 struct environ_entry *environ_first(struct environ *);
2119 struct environ_entry *environ_next(struct environ_entry *);
2120 void	environ_copy(struct environ *, struct environ *);
2121 struct environ_entry *environ_find(struct environ *, const char *);
2122 void printflike(4, 5) environ_set(struct environ *, const char *, int,
2123 	    const char *, ...);
2124 void	environ_clear(struct environ *, const char *);
2125 void	environ_put(struct environ *, const char *, int);
2126 void	environ_unset(struct environ *, const char *);
2127 void	environ_update(struct options *, struct environ *, struct environ *);
2128 void	environ_push(struct environ *);
2129 void printflike(2, 3) environ_log(struct environ *, const char *, ...);
2130 struct environ *environ_for_session(struct session *, int);
2131 
2132 /* tty.c */
2133 void	tty_create_log(void);
2134 int	tty_window_bigger(struct tty *);
2135 int	tty_window_offset(struct tty *, u_int *, u_int *, u_int *, u_int *);
2136 void	tty_update_window_offset(struct window *);
2137 void	tty_update_client_offset(struct client *);
2138 void	tty_raw(struct tty *, const char *);
2139 void	tty_attributes(struct tty *, const struct grid_cell *,
2140 	    const struct grid_cell *, int *);
2141 void	tty_reset(struct tty *);
2142 void	tty_region_off(struct tty *);
2143 void	tty_margin_off(struct tty *);
2144 void	tty_cursor(struct tty *, u_int, u_int);
2145 void	tty_putcode(struct tty *, enum tty_code_code);
2146 void	tty_putcode1(struct tty *, enum tty_code_code, int);
2147 void	tty_putcode2(struct tty *, enum tty_code_code, int, int);
2148 void	tty_putcode3(struct tty *, enum tty_code_code, int, int, int);
2149 void	tty_putcode_ptr1(struct tty *, enum tty_code_code, const void *);
2150 void	tty_putcode_ptr2(struct tty *, enum tty_code_code, const void *,
2151 	    const void *);
2152 void	tty_puts(struct tty *, const char *);
2153 void	tty_putc(struct tty *, u_char);
2154 void	tty_putn(struct tty *, const void *, size_t, u_int);
2155 void	tty_cell(struct tty *, const struct grid_cell *,
2156 	    const struct grid_cell *, int *);
2157 int	tty_init(struct tty *, struct client *);
2158 void	tty_resize(struct tty *);
2159 void	tty_set_size(struct tty *, u_int, u_int, u_int, u_int);
2160 void	tty_start_tty(struct tty *);
2161 void	tty_send_requests(struct tty *);
2162 void	tty_stop_tty(struct tty *);
2163 void	tty_set_title(struct tty *, const char *);
2164 void	tty_update_mode(struct tty *, int, struct screen *);
2165 void	tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int,
2166 	    u_int, u_int, const struct grid_cell *, int *);
2167 void	tty_sync_start(struct tty *);
2168 void	tty_sync_end(struct tty *);
2169 int	tty_open(struct tty *, char **);
2170 void	tty_close(struct tty *);
2171 void	tty_free(struct tty *);
2172 void	tty_update_features(struct tty *);
2173 void	tty_set_selection(struct tty *, const char *, size_t);
2174 void	tty_write(void (*)(struct tty *, const struct tty_ctx *),
2175 	    struct tty_ctx *);
2176 void	tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *);
2177 void	tty_cmd_cell(struct tty *, const struct tty_ctx *);
2178 void	tty_cmd_cells(struct tty *, const struct tty_ctx *);
2179 void	tty_cmd_clearendofline(struct tty *, const struct tty_ctx *);
2180 void	tty_cmd_clearendofscreen(struct tty *, const struct tty_ctx *);
2181 void	tty_cmd_clearline(struct tty *, const struct tty_ctx *);
2182 void	tty_cmd_clearscreen(struct tty *, const struct tty_ctx *);
2183 void	tty_cmd_clearstartofline(struct tty *, const struct tty_ctx *);
2184 void	tty_cmd_clearstartofscreen(struct tty *, const struct tty_ctx *);
2185 void	tty_cmd_deletecharacter(struct tty *, const struct tty_ctx *);
2186 void	tty_cmd_clearcharacter(struct tty *, const struct tty_ctx *);
2187 void	tty_cmd_deleteline(struct tty *, const struct tty_ctx *);
2188 void	tty_cmd_erasecharacter(struct tty *, const struct tty_ctx *);
2189 void	tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *);
2190 void	tty_cmd_insertline(struct tty *, const struct tty_ctx *);
2191 void	tty_cmd_linefeed(struct tty *, const struct tty_ctx *);
2192 void	tty_cmd_scrollup(struct tty *, const struct tty_ctx *);
2193 void	tty_cmd_scrolldown(struct tty *, const struct tty_ctx *);
2194 void	tty_cmd_reverseindex(struct tty *, const struct tty_ctx *);
2195 void	tty_cmd_setselection(struct tty *, const struct tty_ctx *);
2196 void	tty_cmd_rawstring(struct tty *, const struct tty_ctx *);
2197 void	tty_cmd_syncstart(struct tty *, const struct tty_ctx *);
2198 void	tty_default_colours(struct grid_cell *, struct window_pane *);
2199 
2200 /* tty-term.c */
2201 extern struct tty_terms tty_terms;
2202 u_int		 tty_term_ncodes(void);
2203 void		 tty_term_apply(struct tty_term *, const char *, int);
2204 void		 tty_term_apply_overrides(struct tty_term *);
2205 struct tty_term *tty_term_create(struct tty *, char *, char **, u_int, int *,
2206 		     char **);
2207 void		 tty_term_free(struct tty_term *);
2208 int		 tty_term_read_list(const char *, int, char ***, u_int *,
2209 		     char **);
2210 void		 tty_term_free_list(char **, u_int);
2211 int		 tty_term_has(struct tty_term *, enum tty_code_code);
2212 const char	*tty_term_string(struct tty_term *, enum tty_code_code);
2213 const char	*tty_term_string1(struct tty_term *, enum tty_code_code, int);
2214 const char	*tty_term_string2(struct tty_term *, enum tty_code_code, int,
2215 		     int);
2216 const char	*tty_term_string3(struct tty_term *, enum tty_code_code, int,
2217 		     int, int);
2218 const char	*tty_term_ptr1(struct tty_term *, enum tty_code_code,
2219 		     const void *);
2220 const char	*tty_term_ptr2(struct tty_term *, enum tty_code_code,
2221 		     const void *, const void *);
2222 int		 tty_term_number(struct tty_term *, enum tty_code_code);
2223 int		 tty_term_flag(struct tty_term *, enum tty_code_code);
2224 const char	*tty_term_describe(struct tty_term *, enum tty_code_code);
2225 
2226 /* tty-features.c */
2227 void		 tty_add_features(int *, const char *, const char *);
2228 const char	*tty_get_features(int);
2229 int		 tty_apply_features(struct tty_term *, int);
2230 void		 tty_default_features(int *, const char *, u_int);
2231 
2232 /* tty-acs.c */
2233 int		 tty_acs_needed(struct tty *);
2234 const char	*tty_acs_get(struct tty *, u_char);
2235 int		 tty_acs_reverse_get(struct tty *, const char *, size_t);
2236 
2237 /* tty-keys.c */
2238 void		tty_keys_build(struct tty *);
2239 void		tty_keys_free(struct tty *);
2240 int		tty_keys_next(struct tty *);
2241 
2242 /* arguments.c */
2243 void		 args_set(struct args *, u_char, const char *);
2244 struct args	*args_parse(const char *, int, char **);
2245 void		 args_free(struct args *);
2246 char		*args_print(struct args *);
2247 char		*args_escape(const char *);
2248 int		 args_has(struct args *, u_char);
2249 const char	*args_get(struct args *, u_char);
2250 u_char		 args_first(struct args *, struct args_entry **);
2251 u_char		 args_next(struct args_entry **);
2252 const char	*args_first_value(struct args *, u_char, struct args_value **);
2253 const char	*args_next_value(struct args_value **);
2254 long long	 args_strtonum(struct args *, u_char, long long, long long,
2255 		     char **);
2256 long long	 args_percentage(struct args *, u_char, long long,
2257 		     long long, long long, char **);
2258 long long	 args_string_percentage(const char *, long long, long long,
2259 		     long long, char **);
2260 
2261 /* cmd-find.c */
2262 int		 cmd_find_target(struct cmd_find_state *, struct cmdq_item *,
2263 		     const char *, enum cmd_find_type, int);
2264 struct client	*cmd_find_best_client(struct session *);
2265 struct client	*cmd_find_client(struct cmdq_item *, const char *, int);
2266 void		 cmd_find_clear_state(struct cmd_find_state *, int);
2267 int		 cmd_find_empty_state(struct cmd_find_state *);
2268 int		 cmd_find_valid_state(struct cmd_find_state *);
2269 void		 cmd_find_copy_state(struct cmd_find_state *,
2270 		     struct cmd_find_state *);
2271 void		 cmd_find_from_session(struct cmd_find_state *,
2272 		     struct session *, int);
2273 void		 cmd_find_from_winlink(struct cmd_find_state *,
2274 		     struct winlink *, int);
2275 int		 cmd_find_from_session_window(struct cmd_find_state *,
2276 		     struct session *, struct window *, int);
2277 int		 cmd_find_from_window(struct cmd_find_state *, struct window *,
2278 		     int);
2279 void		 cmd_find_from_winlink_pane(struct cmd_find_state *,
2280 		     struct winlink *, struct window_pane *, int);
2281 int		 cmd_find_from_pane(struct cmd_find_state *,
2282 		     struct window_pane *, int);
2283 int		 cmd_find_from_client(struct cmd_find_state *, struct client *,
2284 		     int);
2285 int		 cmd_find_from_mouse(struct cmd_find_state *,
2286 		     struct mouse_event *, int);
2287 int		 cmd_find_from_nothing(struct cmd_find_state *, int);
2288 
2289 /* cmd.c */
2290 extern const struct cmd_entry *cmd_table[];
2291 void printflike(3, 4) cmd_log_argv(int, char **, const char *, ...);
2292 void		 cmd_prepend_argv(int *, char ***, char *);
2293 void		 cmd_append_argv(int *, char ***, char *);
2294 int		 cmd_pack_argv(int, char **, char *, size_t);
2295 int		 cmd_unpack_argv(char *, size_t, int, char ***);
2296 char	       **cmd_copy_argv(int, char **);
2297 void		 cmd_free_argv(int, char **);
2298 char		*cmd_stringify_argv(int, char **);
2299 char		*cmd_get_alias(const char *);
2300 const struct cmd_entry *cmd_get_entry(struct cmd *);
2301 struct args	*cmd_get_args(struct cmd *);
2302 u_int		 cmd_get_group(struct cmd *);
2303 void		 cmd_get_source(struct cmd *, const char **, u_int *);
2304 struct cmd	*cmd_parse(int, char **, const char *, u_int, char **);
2305 void		 cmd_free(struct cmd *);
2306 char		*cmd_print(struct cmd *);
2307 struct cmd_list	*cmd_list_new(void);
2308 void		 cmd_list_append(struct cmd_list *, struct cmd *);
2309 void		 cmd_list_move(struct cmd_list *, struct cmd_list *);
2310 void		 cmd_list_free(struct cmd_list *);
2311 char		*cmd_list_print(struct cmd_list *, int);
2312 struct cmd	*cmd_list_first(struct cmd_list *);
2313 struct cmd	*cmd_list_next(struct cmd *);
2314 int		 cmd_list_all_have(struct cmd_list *, int);
2315 int		 cmd_list_any_have(struct cmd_list *, int);
2316 int		 cmd_mouse_at(struct window_pane *, struct mouse_event *,
2317 		     u_int *, u_int *, int);
2318 struct winlink	*cmd_mouse_window(struct mouse_event *, struct session **);
2319 struct window_pane *cmd_mouse_pane(struct mouse_event *, struct session **,
2320 		     struct winlink **);
2321 char		*cmd_template_replace(const char *, const char *, int);
2322 
2323 /* cmd-attach-session.c */
2324 enum cmd_retval	 cmd_attach_session(struct cmdq_item *, const char *, int, int,
2325 		     int, const char *, int, const char *);
2326 
2327 /* cmd-parse.c */
2328 void		 cmd_parse_empty(struct cmd_parse_input *);
2329 struct cmd_parse_result *cmd_parse_from_file(FILE *, struct cmd_parse_input *);
2330 struct cmd_parse_result *cmd_parse_from_string(const char *,
2331 		     struct cmd_parse_input *);
2332 enum cmd_parse_status cmd_parse_and_insert(const char *,
2333 		     struct cmd_parse_input *, struct cmdq_item *,
2334 		     struct cmdq_state *, char **);
2335 enum cmd_parse_status cmd_parse_and_append(const char *,
2336 		     struct cmd_parse_input *, struct client *,
2337 		     struct cmdq_state *, char **);
2338 struct cmd_parse_result *cmd_parse_from_buffer(const void *, size_t,
2339 		     struct cmd_parse_input *);
2340 struct cmd_parse_result *cmd_parse_from_arguments(int, char **,
2341 		     struct cmd_parse_input *);
2342 
2343 /* cmd-queue.c */
2344 struct cmdq_state *cmdq_new_state(struct cmd_find_state *, struct key_event *,
2345 		     int);
2346 struct cmdq_state *cmdq_link_state(struct cmdq_state *);
2347 struct cmdq_state *cmdq_copy_state(struct cmdq_state *);
2348 void		  cmdq_free_state(struct cmdq_state *);
2349 void printflike(3, 4) cmdq_add_format(struct cmdq_state *, const char *,
2350 		     const char *, ...);
2351 void		  cmdq_merge_formats(struct cmdq_item *, struct format_tree *);
2352 struct cmdq_list *cmdq_new(void);
2353 void cmdq_free(struct cmdq_list *);
2354 const char	 *cmdq_get_name(struct cmdq_item *);
2355 struct client	 *cmdq_get_client(struct cmdq_item *);
2356 struct client	 *cmdq_get_target_client(struct cmdq_item *);
2357 struct cmdq_state *cmdq_get_state(struct cmdq_item *);
2358 struct cmd_find_state *cmdq_get_target(struct cmdq_item *);
2359 struct cmd_find_state *cmdq_get_source(struct cmdq_item *);
2360 struct key_event *cmdq_get_event(struct cmdq_item *);
2361 struct cmd_find_state *cmdq_get_current(struct cmdq_item *);
2362 int		  cmdq_get_flags(struct cmdq_item *);
2363 struct cmdq_item *cmdq_get_command(struct cmd_list *, struct cmdq_state *);
2364 #define cmdq_get_callback(cb, data) cmdq_get_callback1(#cb, cb, data)
2365 struct cmdq_item *cmdq_get_callback1(const char *, cmdq_cb, void *);
2366 struct cmdq_item *cmdq_get_error(const char *);
2367 struct cmdq_item *cmdq_insert_after(struct cmdq_item *, struct cmdq_item *);
2368 struct cmdq_item *cmdq_append(struct client *, struct cmdq_item *);
2369 void		 cmdq_insert_hook(struct session *, struct cmdq_item *,
2370 		     struct cmd_find_state *, const char *, ...);
2371 void		 cmdq_continue(struct cmdq_item *);
2372 u_int		 cmdq_next(struct client *);
2373 struct cmdq_item *cmdq_running(struct client *);
2374 void		 cmdq_guard(struct cmdq_item *, const char *, int);
2375 void printflike(2, 3) cmdq_print(struct cmdq_item *, const char *, ...);
2376 void printflike(2, 3) cmdq_error(struct cmdq_item *, const char *, ...);
2377 
2378 /* cmd-wait-for.c */
2379 void	cmd_wait_for_flush(void);
2380 
2381 /* client.c */
2382 int	client_main(struct event_base *, int, char **, uint64_t, int);
2383 
2384 /* key-bindings.c */
2385 struct key_table *key_bindings_get_table(const char *, int);
2386 struct key_table *key_bindings_first_table(void);
2387 struct key_table *key_bindings_next_table(struct key_table *);
2388 void	 key_bindings_unref_table(struct key_table *);
2389 struct key_binding *key_bindings_get(struct key_table *, key_code);
2390 struct key_binding *key_bindings_get_default(struct key_table *, key_code);
2391 struct key_binding *key_bindings_first(struct key_table *);
2392 struct key_binding *key_bindings_next(struct key_table *, struct key_binding *);
2393 void	 key_bindings_add(const char *, key_code, const char *, int,
2394 	     struct cmd_list *);
2395 void	 key_bindings_remove(const char *, key_code);
2396 void	 key_bindings_reset(const char *, key_code);
2397 void	 key_bindings_remove_table(const char *);
2398 void	 key_bindings_reset_table(const char *);
2399 void	 key_bindings_init(void);
2400 struct cmdq_item *key_bindings_dispatch(struct key_binding *,
2401 	     struct cmdq_item *, struct client *, struct key_event *,
2402 	     struct cmd_find_state *);
2403 
2404 /* key-string.c */
2405 key_code	 key_string_lookup_string(const char *);
2406 const char	*key_string_lookup_key(key_code, int);
2407 
2408 /* alerts.c */
2409 void	alerts_reset_all(void);
2410 void	alerts_queue(struct window *, int);
2411 void	alerts_check_session(struct session *);
2412 
2413 /* file.c */
2414 int	 file_cmp(struct client_file *, struct client_file *);
2415 RB_PROTOTYPE(client_files, client_file, entry, file_cmp);
2416 struct client_file *file_create_with_peer(struct tmuxpeer *,
2417 	    struct client_files *, int, client_file_cb, void *);
2418 struct client_file *file_create_with_client(struct client *, int,
2419 	    client_file_cb, void *);
2420 void	 file_free(struct client_file *);
2421 void	 file_fire_done(struct client_file *);
2422 void	 file_fire_read(struct client_file *);
2423 int	 file_can_print(struct client *);
2424 void printflike(2, 3) file_print(struct client *, const char *, ...);
2425 void	 file_vprint(struct client *, const char *, va_list);
2426 void	 file_print_buffer(struct client *, void *, size_t);
2427 void printflike(2, 3) file_error(struct client *, const char *, ...);
2428 void	 file_write(struct client *, const char *, int, const void *, size_t,
2429 	     client_file_cb, void *);
2430 void	 file_read(struct client *, const char *, client_file_cb, void *);
2431 void	 file_push(struct client_file *);
2432 int	 file_write_left(struct client_files *);
2433 void	 file_write_open(struct client_files *, struct tmuxpeer *,
2434 	     struct imsg *, int, int, client_file_cb, void *);
2435 void	 file_write_data(struct client_files *, struct imsg *);
2436 void	 file_write_close(struct client_files *, struct imsg *);
2437 void	 file_read_open(struct client_files *, struct tmuxpeer *, struct imsg *,
2438 	     int, int, client_file_cb, void *);
2439 void	 file_write_ready(struct client_files *, struct imsg *);
2440 void	 file_read_data(struct client_files *, struct imsg *);
2441 void	 file_read_done(struct client_files *, struct imsg *);
2442 
2443 /* server.c */
2444 extern struct tmuxproc *server_proc;
2445 extern struct clients clients;
2446 extern struct cmd_find_state marked_pane;
2447 extern struct message_list message_log;
2448 void	 server_set_marked(struct session *, struct winlink *,
2449 	     struct window_pane *);
2450 void	 server_clear_marked(void);
2451 int	 server_is_marked(struct session *, struct winlink *,
2452 	     struct window_pane *);
2453 int	 server_check_marked(void);
2454 int	 server_start(struct tmuxproc *, int, struct event_base *, int, char *);
2455 void	 server_update_socket(void);
2456 void	 server_add_accept(int);
2457 void printflike(1, 2) server_add_message(const char *, ...);
2458 
2459 /* server-client.c */
2460 RB_PROTOTYPE(client_windows, client_window, entry, server_client_window_cmp);
2461 u_int	 server_client_how_many(void);
2462 void	 server_client_set_overlay(struct client *, u_int, overlay_check_cb,
2463 	     overlay_mode_cb, overlay_draw_cb, overlay_key_cb,
2464 	     overlay_free_cb, void *);
2465 void	 server_client_clear_overlay(struct client *);
2466 void	 server_client_set_key_table(struct client *, const char *);
2467 const char *server_client_get_key_table(struct client *);
2468 int	 server_client_check_nested(struct client *);
2469 int	 server_client_handle_key(struct client *, struct key_event *);
2470 struct client *server_client_create(int);
2471 int	 server_client_open(struct client *, char **);
2472 void	 server_client_unref(struct client *);
2473 void	 server_client_lost(struct client *);
2474 void	 server_client_suspend(struct client *);
2475 void	 server_client_detach(struct client *, enum msgtype);
2476 void	 server_client_exec(struct client *, const char *);
2477 void	 server_client_loop(void);
2478 void	 server_client_push_stdout(struct client *);
2479 void	 server_client_push_stderr(struct client *);
2480 const char *server_client_get_cwd(struct client *, struct session *);
2481 void	 server_client_set_flags(struct client *, const char *);
2482 const char *server_client_get_flags(struct client *);
2483 struct window_pane *server_client_get_pane(struct client *);
2484 void	 server_client_set_pane(struct client *, struct window_pane *);
2485 void	 server_client_remove_pane(struct window_pane *);
2486 
2487 /* server-fn.c */
2488 void	 server_redraw_client(struct client *);
2489 void	 server_status_client(struct client *);
2490 void	 server_redraw_session(struct session *);
2491 void	 server_redraw_session_group(struct session *);
2492 void	 server_status_session(struct session *);
2493 void	 server_status_session_group(struct session *);
2494 void	 server_redraw_window(struct window *);
2495 void	 server_redraw_window_borders(struct window *);
2496 void	 server_status_window(struct window *);
2497 void	 server_lock(void);
2498 void	 server_lock_session(struct session *);
2499 void	 server_lock_client(struct client *);
2500 void	 server_kill_pane(struct window_pane *);
2501 void	 server_kill_window(struct window *, int);
2502 void	 server_renumber_session(struct session *);
2503 void	 server_renumber_all(void);
2504 int	 server_link_window(struct session *,
2505 	     struct winlink *, struct session *, int, int, int, char **);
2506 void	 server_unlink_window(struct session *, struct winlink *);
2507 void	 server_destroy_pane(struct window_pane *, int);
2508 void	 server_destroy_session(struct session *);
2509 void	 server_check_unattached(void);
2510 void	 server_unzoom_window(struct window *);
2511 
2512 /* status.c */
2513 void	 status_timer_start(struct client *);
2514 void	 status_timer_start_all(void);
2515 void	 status_update_cache(struct session *);
2516 int	 status_at_line(struct client *);
2517 u_int	 status_line_size(struct client *);
2518 struct style_range *status_get_range(struct client *, u_int, u_int);
2519 void	 status_init(struct client *);
2520 void	 status_free(struct client *);
2521 int	 status_redraw(struct client *);
2522 void status_message_set(struct client *, int, int, int, const char *, ...);
2523 void	 status_message_clear(struct client *);
2524 int	 status_message_redraw(struct client *);
2525 void	 status_prompt_set(struct client *, struct cmd_find_state *,
2526 	     const char *, const char *, prompt_input_cb, prompt_free_cb,
2527 	     void *, int);
2528 void	 status_prompt_clear(struct client *);
2529 int	 status_prompt_redraw(struct client *);
2530 int	 status_prompt_key(struct client *, key_code);
2531 void	 status_prompt_update(struct client *, const char *, const char *);
2532 void	 status_prompt_load_history(void);
2533 void	 status_prompt_save_history(void);
2534 
2535 /* resize.c */
2536 void	 resize_window(struct window *, u_int, u_int, int, int);
2537 void	 default_window_size(struct client *, struct session *, struct window *,
2538 	     u_int *, u_int *, u_int *, u_int *, int);
2539 void	 recalculate_size(struct window *, int);
2540 void	 recalculate_sizes(void);
2541 void	 recalculate_sizes_now(int);
2542 
2543 /* input.c */
2544 struct input_ctx *input_init(struct window_pane *, struct bufferevent *);
2545 void	 input_free(struct input_ctx *);
2546 void	 input_reset(struct input_ctx *, int);
2547 struct evbuffer *input_pending(struct input_ctx *);
2548 void	 input_parse_pane(struct window_pane *);
2549 void	 input_parse_buffer(struct window_pane *, u_char *, size_t);
2550 void	 input_parse_screen(struct input_ctx *, struct screen *,
2551 	     screen_write_init_ctx_cb, void *, u_char *, size_t);
2552 
2553 /* input-key.c */
2554 void	 input_key_build(void);
2555 int	 input_key_pane(struct window_pane *, key_code, struct mouse_event *);
2556 int	 input_key(struct screen *, struct bufferevent *, key_code);
2557 int	 input_key_get_mouse(struct screen *, struct mouse_event *, u_int,
2558 	     u_int, const char **, size_t *);
2559 
2560 /* colour.c */
2561 int	 colour_find_rgb(u_char, u_char, u_char);
2562 int	 colour_join_rgb(u_char, u_char, u_char);
2563 void	 colour_split_rgb(int, u_char *, u_char *, u_char *);
2564 const char *colour_tostring(int);
2565 int	 colour_fromstring(const char *s);
2566 int	 colour_256toRGB(int);
2567 int	 colour_256to16(int);
2568 int	 colour_byname(const char *);
2569 
2570 /* attributes.c */
2571 const char *attributes_tostring(int);
2572 int	 attributes_fromstring(const char *);
2573 
2574 /* grid.c */
2575 extern const struct grid_cell grid_default_cell;
2576 void	 grid_empty_line(struct grid *, u_int, u_int);
2577 int	 grid_cells_equal(const struct grid_cell *, const struct grid_cell *);
2578 int	 grid_cells_look_equal(const struct grid_cell *,
2579 	     const struct grid_cell *);
2580 struct grid *grid_create(u_int, u_int, u_int);
2581 void	 grid_destroy(struct grid *);
2582 int	 grid_compare(struct grid *, struct grid *);
2583 void	 grid_collect_history(struct grid *);
2584 void	 grid_remove_history(struct grid *, u_int );
2585 void	 grid_scroll_history(struct grid *, u_int);
2586 void	 grid_scroll_history_region(struct grid *, u_int, u_int, u_int);
2587 void	 grid_clear_history(struct grid *);
2588 const struct grid_line *grid_peek_line(struct grid *, u_int);
2589 void	 grid_get_cell(struct grid *, u_int, u_int, struct grid_cell *);
2590 void	 grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *);
2591 void	 grid_set_padding(struct grid *, u_int, u_int);
2592 void	 grid_set_cells(struct grid *, u_int, u_int, const struct grid_cell *,
2593 	     const char *, size_t);
2594 struct grid_line *grid_get_line(struct grid *, u_int);
2595 void	 grid_adjust_lines(struct grid *, u_int);
2596 void	 grid_clear(struct grid *, u_int, u_int, u_int, u_int, u_int);
2597 void	 grid_clear_lines(struct grid *, u_int, u_int, u_int);
2598 void	 grid_move_lines(struct grid *, u_int, u_int, u_int, u_int);
2599 void	 grid_move_cells(struct grid *, u_int, u_int, u_int, u_int, u_int);
2600 char	*grid_string_cells(struct grid *, u_int, u_int, u_int,
2601 	     struct grid_cell **, int, int, int);
2602 void	 grid_duplicate_lines(struct grid *, u_int, struct grid *, u_int,
2603 	     u_int);
2604 void	 grid_reflow(struct grid *, u_int);
2605 void	 grid_wrap_position(struct grid *, u_int, u_int, u_int *, u_int *);
2606 void	 grid_unwrap_position(struct grid *, u_int *, u_int *, u_int, u_int);
2607 u_int	 grid_line_length(struct grid *, u_int);
2608 
2609 /* grid-reader.c */
2610 void	 grid_reader_start(struct grid_reader *, struct grid *, u_int, u_int);
2611 void	 grid_reader_get_cursor(struct grid_reader *, u_int *, u_int *);
2612 u_int	 grid_reader_line_length(struct grid_reader *);
2613 int	 grid_reader_in_set(struct grid_reader *, const char *);
2614 void	 grid_reader_cursor_right(struct grid_reader *, int, int);
2615 void	 grid_reader_cursor_left(struct grid_reader *, int);
2616 void	 grid_reader_cursor_down(struct grid_reader *);
2617 void	 grid_reader_cursor_up(struct grid_reader *);
2618 void	 grid_reader_cursor_start_of_line(struct grid_reader *, int);
2619 void	 grid_reader_cursor_end_of_line(struct grid_reader *, int, int);
2620 void	 grid_reader_cursor_next_word(struct grid_reader *, const char *);
2621 void	 grid_reader_cursor_next_word_end(struct grid_reader *, const char *);
2622 void	 grid_reader_cursor_previous_word(struct grid_reader *, const char *,
2623 	     int);
2624 int	 grid_reader_cursor_jump(struct grid_reader *,
2625 	     const struct utf8_data *);
2626 int	 grid_reader_cursor_jump_back(struct grid_reader *,
2627 	     const struct utf8_data *);
2628 void	 grid_reader_cursor_back_to_indentation(struct grid_reader *);
2629 
2630 /* grid-view.c */
2631 void	 grid_view_get_cell(struct grid *, u_int, u_int, struct grid_cell *);
2632 void	 grid_view_set_cell(struct grid *, u_int, u_int,
2633 	     const struct grid_cell *);
2634 void	 grid_view_set_padding(struct grid *, u_int, u_int);
2635 void	 grid_view_set_cells(struct grid *, u_int, u_int,
2636 	     const struct grid_cell *, const char *, size_t);
2637 void	 grid_view_clear_history(struct grid *, u_int);
2638 void	 grid_view_clear(struct grid *, u_int, u_int, u_int, u_int, u_int);
2639 void	 grid_view_scroll_region_up(struct grid *, u_int, u_int, u_int);
2640 void	 grid_view_scroll_region_down(struct grid *, u_int, u_int, u_int);
2641 void	 grid_view_insert_lines(struct grid *, u_int, u_int, u_int);
2642 void	 grid_view_insert_lines_region(struct grid *, u_int, u_int, u_int,
2643 	     u_int);
2644 void	 grid_view_delete_lines(struct grid *, u_int, u_int, u_int);
2645 void	 grid_view_delete_lines_region(struct grid *, u_int, u_int, u_int,
2646 	     u_int);
2647 void	 grid_view_insert_cells(struct grid *, u_int, u_int, u_int, u_int);
2648 void	 grid_view_delete_cells(struct grid *, u_int, u_int, u_int, u_int);
2649 char	*grid_view_string_cells(struct grid *, u_int, u_int, u_int);
2650 
2651 /* screen-write.c */
2652 void	 screen_write_make_list(struct screen *);
2653 void	 screen_write_free_list(struct screen *);
2654 void	 screen_write_start_pane(struct screen_write_ctx *,
2655 	     struct window_pane *, struct screen *);
2656 void	 screen_write_start(struct screen_write_ctx *, struct screen *);
2657 void	 screen_write_start_callback(struct screen_write_ctx *, struct screen *,
2658 	     screen_write_init_ctx_cb, void *);
2659 void	 screen_write_stop(struct screen_write_ctx *);
2660 void	 screen_write_reset(struct screen_write_ctx *);
2661 size_t printflike(1, 2) screen_write_strlen(const char *, ...);
2662 int printflike(7, 8) screen_write_text(struct screen_write_ctx *, u_int, u_int,
2663 	     u_int, int, const struct grid_cell *, const char *, ...);
2664 void printflike(3, 4) screen_write_puts(struct screen_write_ctx *,
2665 	     const struct grid_cell *, const char *, ...);
2666 void printflike(4, 5) screen_write_nputs(struct screen_write_ctx *,
2667 	     ssize_t, const struct grid_cell *, const char *, ...);
2668 void	 screen_write_vnputs(struct screen_write_ctx *, ssize_t,
2669 	     const struct grid_cell *, const char *, va_list);
2670 void	 screen_write_putc(struct screen_write_ctx *, const struct grid_cell *,
2671 	     u_char);
2672 void	 screen_write_fast_copy(struct screen_write_ctx *, struct screen *,
2673 	     u_int, u_int, u_int, u_int);
2674 void	 screen_write_hline(struct screen_write_ctx *, u_int, int, int);
2675 void	 screen_write_vline(struct screen_write_ctx *, u_int, int, int);
2676 void	 screen_write_menu(struct screen_write_ctx *, struct menu *, int,
2677 	     const struct grid_cell *);
2678 void	 screen_write_box(struct screen_write_ctx *, u_int, u_int);
2679 void	 screen_write_preview(struct screen_write_ctx *, struct screen *, u_int,
2680 	     u_int);
2681 void	 screen_write_backspace(struct screen_write_ctx *);
2682 void	 screen_write_mode_set(struct screen_write_ctx *, int);
2683 void	 screen_write_mode_clear(struct screen_write_ctx *, int);
2684 void	 screen_write_cursorup(struct screen_write_ctx *, u_int);
2685 void	 screen_write_cursordown(struct screen_write_ctx *, u_int);
2686 void	 screen_write_cursorright(struct screen_write_ctx *, u_int);
2687 void	 screen_write_cursorleft(struct screen_write_ctx *, u_int);
2688 void	 screen_write_alignmenttest(struct screen_write_ctx *);
2689 void	 screen_write_insertcharacter(struct screen_write_ctx *, u_int, u_int);
2690 void	 screen_write_deletecharacter(struct screen_write_ctx *, u_int, u_int);
2691 void	 screen_write_clearcharacter(struct screen_write_ctx *, u_int, u_int);
2692 void	 screen_write_insertline(struct screen_write_ctx *, u_int, u_int);
2693 void	 screen_write_deleteline(struct screen_write_ctx *, u_int, u_int);
2694 void	 screen_write_clearline(struct screen_write_ctx *, u_int);
2695 void	 screen_write_clearendofline(struct screen_write_ctx *, u_int);
2696 void	 screen_write_clearstartofline(struct screen_write_ctx *, u_int);
2697 void	 screen_write_cursormove(struct screen_write_ctx *, int, int, int);
2698 void	 screen_write_reverseindex(struct screen_write_ctx *, u_int);
2699 void	 screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int);
2700 void	 screen_write_linefeed(struct screen_write_ctx *, int, u_int);
2701 void	 screen_write_scrollup(struct screen_write_ctx *, u_int, u_int);
2702 void	 screen_write_scrolldown(struct screen_write_ctx *, u_int, u_int);
2703 void	 screen_write_carriagereturn(struct screen_write_ctx *);
2704 void	 screen_write_clearendofscreen(struct screen_write_ctx *, u_int);
2705 void	 screen_write_clearstartofscreen(struct screen_write_ctx *, u_int);
2706 void	 screen_write_clearscreen(struct screen_write_ctx *, u_int);
2707 void	 screen_write_clearhistory(struct screen_write_ctx *);
2708 void	 screen_write_collect_end(struct screen_write_ctx *);
2709 void	 screen_write_collect_add(struct screen_write_ctx *,
2710 	     const struct grid_cell *);
2711 void	 screen_write_cell(struct screen_write_ctx *, const struct grid_cell *);
2712 void	 screen_write_setselection(struct screen_write_ctx *, u_char *, u_int);
2713 void	 screen_write_rawstring(struct screen_write_ctx *, u_char *, u_int);
2714 void	 screen_write_alternateon(struct screen_write_ctx *,
2715 	     struct grid_cell *, int);
2716 void	 screen_write_alternateoff(struct screen_write_ctx *,
2717 	     struct grid_cell *, int);
2718 
2719 /* screen-redraw.c */
2720 void	 screen_redraw_screen(struct client *);
2721 void	 screen_redraw_pane(struct client *, struct window_pane *);
2722 
2723 /* screen.c */
2724 void	 screen_init(struct screen *, u_int, u_int, u_int);
2725 void	 screen_reinit(struct screen *);
2726 void	 screen_free(struct screen *);
2727 void	 screen_reset_tabs(struct screen *);
2728 void	 screen_set_cursor_style(struct screen *, u_int);
2729 void	 screen_set_cursor_colour(struct screen *, const char *);
2730 int	 screen_set_title(struct screen *, const char *);
2731 void	 screen_set_path(struct screen *, const char *);
2732 void	 screen_push_title(struct screen *);
2733 void	 screen_pop_title(struct screen *);
2734 void	 screen_resize(struct screen *, u_int, u_int, int);
2735 void	 screen_resize_cursor(struct screen *, u_int, u_int, int, int, int);
2736 void	 screen_set_selection(struct screen *, u_int, u_int, u_int, u_int,
2737 	     u_int, int, struct grid_cell *);
2738 void	 screen_clear_selection(struct screen *);
2739 void	 screen_hide_selection(struct screen *);
2740 int	 screen_check_selection(struct screen *, u_int, u_int);
2741 void	 screen_select_cell(struct screen *, struct grid_cell *,
2742 	     const struct grid_cell *);
2743 void	 screen_alternate_on(struct screen *, struct grid_cell *, int);
2744 void	 screen_alternate_off(struct screen *, struct grid_cell *, int);
2745 
2746 /* window.c */
2747 extern struct windows windows;
2748 extern struct window_pane_tree all_window_panes;
2749 int		 window_cmp(struct window *, struct window *);
2750 RB_PROTOTYPE(windows, window, entry, window_cmp);
2751 int		 winlink_cmp(struct winlink *, struct winlink *);
2752 RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
2753 int		 window_pane_cmp(struct window_pane *, struct window_pane *);
2754 RB_PROTOTYPE(window_pane_tree, window_pane, tree_entry, window_pane_cmp);
2755 struct winlink	*winlink_find_by_index(struct winlinks *, int);
2756 struct winlink	*winlink_find_by_window(struct winlinks *, struct window *);
2757 struct winlink	*winlink_find_by_window_id(struct winlinks *, u_int);
2758 u_int		 winlink_count(struct winlinks *);
2759 struct winlink	*winlink_add(struct winlinks *, int);
2760 void		 winlink_set_window(struct winlink *, struct window *);
2761 void		 winlink_remove(struct winlinks *, struct winlink *);
2762 struct winlink	*winlink_next(struct winlink *);
2763 struct winlink	*winlink_previous(struct winlink *);
2764 struct winlink	*winlink_next_by_number(struct winlink *, struct session *,
2765 		     int);
2766 struct winlink	*winlink_previous_by_number(struct winlink *, struct session *,
2767 		     int);
2768 void		 winlink_stack_push(struct winlink_stack *, struct winlink *);
2769 void		 winlink_stack_remove(struct winlink_stack *, struct winlink *);
2770 struct window	*window_find_by_id_str(const char *);
2771 struct window	*window_find_by_id(u_int);
2772 void		 window_update_activity(struct window *);
2773 struct window	*window_create(u_int, u_int, u_int, u_int);
2774 void		 window_pane_set_event(struct window_pane *);
2775 struct window_pane *window_get_active_at(struct window *, u_int, u_int);
2776 struct window_pane *window_find_string(struct window *, const char *);
2777 int		 window_has_pane(struct window *, struct window_pane *);
2778 int		 window_set_active_pane(struct window *, struct window_pane *,
2779 		     int);
2780 void		 window_redraw_active_switch(struct window *,
2781 		     struct window_pane *);
2782 struct window_pane *window_add_pane(struct window *, struct window_pane *,
2783 		     u_int, int);
2784 void		 window_resize(struct window *, u_int, u_int, int, int);
2785 void		 window_pane_send_resize(struct window_pane *, u_int, u_int);
2786 int		 window_zoom(struct window_pane *);
2787 int		 window_unzoom(struct window *);
2788 int		 window_push_zoom(struct window *, int, int);
2789 int		 window_pop_zoom(struct window *);
2790 void		 window_lost_pane(struct window *, struct window_pane *);
2791 void		 window_remove_pane(struct window *, struct window_pane *);
2792 struct window_pane *window_pane_at_index(struct window *, u_int);
2793 struct window_pane *window_pane_next_by_number(struct window *,
2794 			struct window_pane *, u_int);
2795 struct window_pane *window_pane_previous_by_number(struct window *,
2796 			struct window_pane *, u_int);
2797 int		 window_pane_index(struct window_pane *, u_int *);
2798 u_int		 window_count_panes(struct window *);
2799 void		 window_destroy_panes(struct window *);
2800 struct window_pane *window_pane_find_by_id_str(const char *);
2801 struct window_pane *window_pane_find_by_id(u_int);
2802 int		 window_pane_destroy_ready(struct window_pane *);
2803 void		 window_pane_resize(struct window_pane *, u_int, u_int);
2804 void		 window_pane_set_palette(struct window_pane *, u_int, int);
2805 void		 window_pane_unset_palette(struct window_pane *, u_int);
2806 void		 window_pane_reset_palette(struct window_pane *);
2807 int		 window_pane_get_palette(struct window_pane *, int);
2808 int		 window_pane_set_mode(struct window_pane *,
2809 		     struct window_pane *, const struct window_mode *,
2810 		     struct cmd_find_state *, struct args *);
2811 void		 window_pane_reset_mode(struct window_pane *);
2812 void		 window_pane_reset_mode_all(struct window_pane *);
2813 int		 window_pane_key(struct window_pane *, struct client *,
2814 		     struct session *, struct winlink *, key_code,
2815 		     struct mouse_event *);
2816 int		 window_pane_visible(struct window_pane *);
2817 u_int		 window_pane_search(struct window_pane *, const char *, int,
2818 		     int);
2819 const char	*window_printable_flags(struct winlink *, int);
2820 struct window_pane *window_pane_find_up(struct window_pane *);
2821 struct window_pane *window_pane_find_down(struct window_pane *);
2822 struct window_pane *window_pane_find_left(struct window_pane *);
2823 struct window_pane *window_pane_find_right(struct window_pane *);
2824 void		 window_set_name(struct window *, const char *);
2825 void		 window_add_ref(struct window *, const char *);
2826 void		 window_remove_ref(struct window *, const char *);
2827 void		 winlink_clear_flags(struct winlink *);
2828 int		 winlink_shuffle_up(struct session *, struct winlink *, int);
2829 int		 window_pane_start_input(struct window_pane *,
2830 		     struct cmdq_item *, char **);
2831 void		*window_pane_get_new_data(struct window_pane *,
2832 		     struct window_pane_offset *, size_t *);
2833 void		 window_pane_update_used_data(struct window_pane *,
2834 		     struct window_pane_offset *, size_t);
2835 
2836 /* layout.c */
2837 u_int		 layout_count_cells(struct layout_cell *);
2838 struct layout_cell *layout_create_cell(struct layout_cell *);
2839 void		 layout_free_cell(struct layout_cell *);
2840 void		 layout_print_cell(struct layout_cell *, const char *, u_int);
2841 void		 layout_destroy_cell(struct window *, struct layout_cell *,
2842 		     struct layout_cell **);
2843 void		 layout_resize_layout(struct window *, struct layout_cell *,
2844 		     enum layout_type, int, int);
2845 struct layout_cell *layout_search_by_border(struct layout_cell *, u_int, u_int);
2846 void		 layout_set_size(struct layout_cell *, u_int, u_int, u_int,
2847 		     u_int);
2848 void		 layout_make_leaf(struct layout_cell *, struct window_pane *);
2849 void		 layout_make_node(struct layout_cell *, enum layout_type);
2850 void		 layout_fix_offsets(struct window *);
2851 void		 layout_fix_panes(struct window *, struct window_pane *);
2852 void		 layout_resize_adjust(struct window *, struct layout_cell *,
2853 		     enum layout_type, int);
2854 void		 layout_init(struct window *, struct window_pane *);
2855 void		 layout_free(struct window *);
2856 void		 layout_resize(struct window *, u_int, u_int);
2857 void		 layout_resize_pane(struct window_pane *, enum layout_type,
2858 		     int, int);
2859 void		 layout_resize_pane_to(struct window_pane *, enum layout_type,
2860 		     u_int);
2861 void		 layout_assign_pane(struct layout_cell *, struct window_pane *,
2862 		     int);
2863 struct layout_cell *layout_split_pane(struct window_pane *, enum layout_type,
2864 		     int, int);
2865 void		 layout_close_pane(struct window_pane *);
2866 int		 layout_spread_cell(struct window *, struct layout_cell *);
2867 void		 layout_spread_out(struct window_pane *);
2868 
2869 /* layout-custom.c */
2870 char		*layout_dump(struct layout_cell *);
2871 int		 layout_parse(struct window *, const char *);
2872 
2873 /* layout-set.c */
2874 int		 layout_set_lookup(const char *);
2875 u_int		 layout_set_select(struct window *, u_int);
2876 u_int		 layout_set_next(struct window *);
2877 u_int		 layout_set_previous(struct window *);
2878 
2879 /* mode-tree.c */
2880 typedef void (*mode_tree_build_cb)(void *, struct mode_tree_sort_criteria *,
2881 				   uint64_t *, const char *);
2882 typedef void (*mode_tree_draw_cb)(void *, void *, struct screen_write_ctx *,
2883 	     u_int, u_int);
2884 typedef int (*mode_tree_search_cb)(void *, void *, const char *);
2885 typedef void (*mode_tree_menu_cb)(void *, struct client *, key_code);
2886 typedef u_int (*mode_tree_height_cb)(void *, u_int);
2887 typedef key_code (*mode_tree_key_cb)(void *, void *, u_int);
2888 typedef void (*mode_tree_each_cb)(void *, void *, struct client *, key_code);
2889 u_int	 mode_tree_count_tagged(struct mode_tree_data *);
2890 void	*mode_tree_get_current(struct mode_tree_data *);
2891 const char *mode_tree_get_current_name(struct mode_tree_data *);
2892 void	 mode_tree_expand_current(struct mode_tree_data *);
2893 void	 mode_tree_collapse_current(struct mode_tree_data *);
2894 void	 mode_tree_expand(struct mode_tree_data *, uint64_t);
2895 int	 mode_tree_set_current(struct mode_tree_data *, uint64_t);
2896 void	 mode_tree_each_tagged(struct mode_tree_data *, mode_tree_each_cb,
2897 	     struct client *, key_code, int);
2898 void	 mode_tree_up(struct mode_tree_data *, int);
2899 void	 mode_tree_down(struct mode_tree_data *, int);
2900 struct mode_tree_data *mode_tree_start(struct window_pane *, struct args *,
2901 	     mode_tree_build_cb, mode_tree_draw_cb, mode_tree_search_cb,
2902 	     mode_tree_menu_cb, mode_tree_height_cb, mode_tree_key_cb, void *,
2903 	     const struct menu_item *, const char **, u_int, struct screen **);
2904 void	 mode_tree_zoom(struct mode_tree_data *, struct args *);
2905 void	 mode_tree_build(struct mode_tree_data *);
2906 void	 mode_tree_free(struct mode_tree_data *);
2907 void	 mode_tree_resize(struct mode_tree_data *, u_int, u_int);
2908 struct mode_tree_item *mode_tree_add(struct mode_tree_data *,
2909 	     struct mode_tree_item *, void *, uint64_t, const char *,
2910 	     const char *, int);
2911 void	 mode_tree_draw_as_parent(struct mode_tree_item *);
2912 void	 mode_tree_no_tag(struct mode_tree_item *);
2913 void	 mode_tree_remove(struct mode_tree_data *, struct mode_tree_item *);
2914 void	 mode_tree_draw(struct mode_tree_data *);
2915 int	 mode_tree_key(struct mode_tree_data *, struct client *, key_code *,
2916 	     struct mouse_event *, u_int *, u_int *);
2917 void	 mode_tree_run_command(struct client *, struct cmd_find_state *,
2918 	     const char *, const char *);
2919 
2920 /* window-buffer.c */
2921 extern const struct window_mode window_buffer_mode;
2922 
2923 /* window-tree.c */
2924 extern const struct window_mode window_tree_mode;
2925 
2926 /* window-clock.c */
2927 extern const struct window_mode window_clock_mode;
2928 extern const char window_clock_table[14][5][5];
2929 
2930 /* window-client.c */
2931 extern const struct window_mode window_client_mode;
2932 
2933 /* window-copy.c */
2934 extern const struct window_mode window_copy_mode;
2935 extern const struct window_mode window_view_mode;
2936 void printflike(2, 3) window_copy_add(struct window_pane *, const char *, ...);
2937 void		 window_copy_vadd(struct window_pane *, const char *, va_list);
2938 void		 window_copy_pageup(struct window_pane *, int);
2939 void		 window_copy_start_drag(struct client *, struct mouse_event *);
2940 char		*window_copy_get_word(struct window_pane *, u_int, u_int);
2941 char		*window_copy_get_line(struct window_pane *, u_int);
2942 
2943 /* window-option.c */
2944 extern const struct window_mode window_customize_mode;
2945 
2946 /* names.c */
2947 void	 check_window_name(struct window *);
2948 char	*default_window_name(struct window *);
2949 char	*parse_window_name(const char *);
2950 
2951 /* control.c */
2952 void	control_discard(struct client *);
2953 void	control_start(struct client *);
2954 void	control_stop(struct client *);
2955 void	control_set_pane_on(struct client *, struct window_pane *);
2956 void	control_set_pane_off(struct client *, struct window_pane *);
2957 void	control_continue_pane(struct client *, struct window_pane *);
2958 void	control_pause_pane(struct client *, struct window_pane *);
2959 struct window_pane_offset *control_pane_offset(struct client *,
2960 	   struct window_pane *, int *);
2961 void	control_reset_offsets(struct client *);
2962 void printflike(2, 3) control_write(struct client *, const char *, ...);
2963 void	control_write_output(struct client *, struct window_pane *);
2964 int	control_all_done(struct client *);
2965 void	control_add_sub(struct client *, const char *, enum control_sub_type,
2966     	   int, const char *);
2967 void	control_remove_sub(struct client *, const char *);
2968 
2969 /* control-notify.c */
2970 void	control_notify_input(struct client *, struct window_pane *,
2971 	    const u_char *, size_t);
2972 void	control_notify_pane_mode_changed(int);
2973 void	control_notify_window_layout_changed(struct window *);
2974 void	control_notify_window_pane_changed(struct window *);
2975 void	control_notify_window_unlinked(struct session *, struct window *);
2976 void	control_notify_window_linked(struct session *, struct window *);
2977 void	control_notify_window_renamed(struct window *);
2978 void	control_notify_client_session_changed(struct client *);
2979 void	control_notify_client_detached(struct client *);
2980 void	control_notify_session_renamed(struct session *);
2981 void	control_notify_session_created(struct session *);
2982 void	control_notify_session_closed(struct session *);
2983 void	control_notify_session_window_changed(struct session *);
2984 
2985 /* session.c */
2986 extern struct sessions sessions;
2987 int	session_cmp(struct session *, struct session *);
2988 RB_PROTOTYPE(sessions, session, entry, session_cmp);
2989 int		 session_alive(struct session *);
2990 struct session	*session_find(const char *);
2991 struct session	*session_find_by_id_str(const char *);
2992 struct session	*session_find_by_id(u_int);
2993 struct session	*session_create(const char *, const char *, const char *,
2994 		     struct environ *, struct options *, struct termios *);
2995 void		 session_destroy(struct session *, int,	 const char *);
2996 void		 session_add_ref(struct session *, const char *);
2997 void		 session_remove_ref(struct session *, const char *);
2998 char		*session_check_name(const char *);
2999 void		 session_update_activity(struct session *, struct timeval *);
3000 struct session	*session_next_session(struct session *);
3001 struct session	*session_previous_session(struct session *);
3002 struct winlink	*session_new(struct session *, const char *, int, char **,
3003 		     const char *, const char *, int, char **);
3004 struct winlink	*session_attach(struct session *, struct window *, int,
3005 		     char **);
3006 int		 session_detach(struct session *, struct winlink *);
3007 int		 session_has(struct session *, struct window *);
3008 int		 session_is_linked(struct session *, struct window *);
3009 int		 session_next(struct session *, int);
3010 int		 session_previous(struct session *, int);
3011 int		 session_select(struct session *, int);
3012 int		 session_last(struct session *);
3013 int		 session_set_current(struct session *, struct winlink *);
3014 struct session_group *session_group_contains(struct session *);
3015 struct session_group *session_group_find(const char *);
3016 struct session_group *session_group_new(const char *);
3017 void		 session_group_add(struct session_group *, struct session *);
3018 void		 session_group_synchronize_to(struct session *);
3019 void		 session_group_synchronize_from(struct session *);
3020 u_int		 session_group_count(struct session_group *);
3021 u_int		 session_group_attached_count(struct session_group *);
3022 void		 session_renumber_windows(struct session *);
3023 
3024 /* utf8.c */
3025 utf8_char	 utf8_build_one(u_char);
3026 enum utf8_state	 utf8_from_data(const struct utf8_data *, utf8_char *);
3027 void		 utf8_to_data(utf8_char, struct utf8_data *);
3028 void		 utf8_set(struct utf8_data *, u_char);
3029 void		 utf8_copy(struct utf8_data *, const struct utf8_data *);
3030 enum utf8_state	 utf8_open(struct utf8_data *, u_char);
3031 enum utf8_state	 utf8_append(struct utf8_data *, u_char);
3032 int		 utf8_isvalid(const char *);
3033 int		 utf8_strvis(char *, const char *, size_t, int);
3034 int		 utf8_stravis(char **, const char *, int);
3035 int		 utf8_stravisx(char **, const char *, size_t, int);
3036 char		*utf8_sanitize(const char *);
3037 size_t		 utf8_strlen(const struct utf8_data *);
3038 u_int		 utf8_strwidth(const struct utf8_data *, ssize_t);
3039 struct utf8_data *utf8_fromcstr(const char *);
3040 char		*utf8_tocstr(struct utf8_data *);
3041 u_int		 utf8_cstrwidth(const char *);
3042 char		*utf8_padcstr(const char *, u_int);
3043 char		*utf8_rpadcstr(const char *, u_int);
3044 int		 utf8_cstrhas(const char *, const struct utf8_data *);
3045 
3046 /* osdep-*.c */
3047 char		*osdep_get_name(int, char *);
3048 char		*osdep_get_cwd(int);
3049 struct event_base *osdep_event_init(void);
3050 
3051 /* log.c */
3052 void	log_add_level(void);
3053 int	log_get_level(void);
3054 void	log_open(const char *);
3055 void	log_toggle(const char *);
3056 void	log_close(void);
3057 void printflike(1, 2) log_debug(const char *, ...);
3058 __dead void printflike(1, 2) fatal(const char *, ...);
3059 __dead void printflike(1, 2) fatalx(const char *, ...);
3060 
3061 /* menu.c */
3062 #define MENU_NOMOUSE 0x1
3063 #define MENU_TAB 0x2
3064 #define MENU_STAYOPEN 0x4
3065 struct menu	*menu_create(const char *);
3066 void		 menu_add_items(struct menu *, const struct menu_item *,
3067 		    struct cmdq_item *, struct client *,
3068 		    struct cmd_find_state *);
3069 void		 menu_add_item(struct menu *, const struct menu_item *,
3070 		    struct cmdq_item *, struct client *,
3071 		    struct cmd_find_state *);
3072 void		 menu_free(struct menu *);
3073 int		 menu_display(struct menu *, int, struct cmdq_item *, u_int,
3074 		    u_int, struct client *, struct cmd_find_state *,
3075 		    menu_choice_cb, void *);
3076 
3077 /* popup.c */
3078 #define POPUP_CLOSEEXIT 0x1
3079 #define POPUP_CLOSEEXITZERO 0x2
3080 typedef void (*popup_close_cb)(int, void *);
3081 typedef void (*popup_finish_edit_cb)(char *, size_t, void *);
3082 int		 popup_display(int, struct cmdq_item *, u_int, u_int, u_int,
3083 		    u_int, const char *, int, char **, const char *,
3084 		    struct client *, struct session *, popup_close_cb, void *);
3085 int		 popup_editor(struct client *, const char *, size_t,
3086 		    popup_finish_edit_cb, void *);
3087 
3088 /* style.c */
3089 int		 style_parse(struct style *,const struct grid_cell *,
3090 		     const char *);
3091 const char	*style_tostring(struct style *);
3092 void		 style_add(struct grid_cell *, struct options *,
3093 		     const char *, struct format_tree *);
3094 void		 style_apply(struct grid_cell *, struct options *,
3095 		     const char *, struct format_tree *);
3096 void		 style_set(struct style *, const struct grid_cell *);
3097 void		 style_copy(struct style *, struct style *);
3098 
3099 /* spawn.c */
3100 struct winlink	*spawn_window(struct spawn_context *, char **);
3101 struct window_pane *spawn_pane(struct spawn_context *, char **);
3102 
3103 /* regsub.c */
3104 char		*regsub(const char *, const char *, const char *, int);
3105 
3106 #endif /* TMUX_H */
3107