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