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