xref: /netbsd-src/external/bsd/tmux/dist/tmux.h (revision 46f5119e40af2e51998f686b2fdcc76b5488f7f3)
1 /* $Id: tmux.h,v 1.1.1.1 2011/03/10 09:15:39 jmmv Exp $ */
2 
3 /*
4  * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
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 "config.h"
23 
24 #define PROTOCOL_VERSION 6
25 
26 #include <sys/param.h>
27 #include <sys/time.h>
28 #include <sys/uio.h>
29 
30 #include <event.h>
31 #include <limits.h>
32 #include <signal.h>
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <termios.h>
36 
37 #include "array.h"
38 
39 #include "compat.h"
40 
41 extern char    *__progname;
42 extern char   **environ;
43 
44 /* Default configuration files. */
45 #define DEFAULT_CFG ".tmux.conf"
46 #define SYSTEM_CFG "/etc/tmux.conf"
47 
48 /* Default prompt history length. */
49 #define PROMPT_HISTORY 100
50 
51 /*
52  * Minimum layout cell size, NOT including separator line. The scroll region
53  * cannot be one line in height so this must be at least two.
54  */
55 #define PANE_MINIMUM 2
56 
57 /* Automatic name refresh interval, in milliseconds. */
58 #define NAME_INTERVAL 500
59 
60 /* Maximum data to buffer for output before suspending writing to a tty. */
61 #define BACKOFF_THRESHOLD 16384
62 
63 /*
64  * Maximum sizes of strings in message data. Don't forget to bump
65  * PROTOCOL_VERSION if any of these change!
66  */
67 #define COMMAND_LENGTH 2048	/* packed argv size */
68 #define TERMINAL_LENGTH 128	/* length of TERM environment variable */
69 #define ENVIRON_LENGTH 1024	/* environment variable length */
70 
71 /*
72  * UTF-8 data size. This must be big enough to hold combined characters as well
73  * as single.
74  */
75 #define UTF8_SIZE 9
76 
77 /* Fatal errors. */
78 #define fatal(msg) log_fatal("%s: %s", __func__, msg);
79 #define fatalx(msg) log_fatalx("%s: %s", __func__, msg);
80 
81 /* Definition to shut gcc up about unused arguments. */
82 #define unused __attribute__ ((unused))
83 
84 /* Attribute to make gcc check printf-like arguments. */
85 #define printflike1 __attribute__ ((format (printf, 1, 2)))
86 #define printflike2 __attribute__ ((format (printf, 2, 3)))
87 #define printflike3 __attribute__ ((format (printf, 3, 4)))
88 #define printflike4 __attribute__ ((format (printf, 4, 5)))
89 #define printflike5 __attribute__ ((format (printf, 5, 6)))
90 
91 /* Number of items in array. */
92 #ifndef nitems
93 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
94 #endif
95 
96 /* Bell option values. */
97 #define BELL_NONE 0
98 #define BELL_ANY 1
99 #define BELL_CURRENT 2
100 
101 /* Special key codes. */
102 #define KEYC_NONE 0xfff
103 #define KEYC_BASE 0x1000
104 
105 /* Key modifier bits. */
106 #define KEYC_ESCAPE 0x2000
107 #define KEYC_CTRL 0x4000
108 #define KEYC_SHIFT 0x8000
109 #define KEYC_PREFIX 0x10000
110 
111 /* Mask to obtain key w/o modifiers */
112 #define KEYC_MASK_MOD (KEYC_ESCAPE|KEYC_CTRL|KEYC_SHIFT|KEYC_PREFIX)
113 #define KEYC_MASK_KEY (~KEYC_MASK_MOD)
114 
115 /* Other key codes. */
116 enum key_code {
117 	/* Mouse key. */
118 	KEYC_MOUSE = KEYC_BASE,
119 
120 	/* Backspace key. */
121 	KEYC_BSPACE,
122 
123 	/* Function keys. */
124 	KEYC_F1,
125 	KEYC_F2,
126 	KEYC_F3,
127 	KEYC_F4,
128 	KEYC_F5,
129 	KEYC_F6,
130 	KEYC_F7,
131 	KEYC_F8,
132 	KEYC_F9,
133 	KEYC_F10,
134 	KEYC_F11,
135 	KEYC_F12,
136 	KEYC_F13,
137 	KEYC_F14,
138 	KEYC_F15,
139 	KEYC_F16,
140 	KEYC_F17,
141 	KEYC_F18,
142 	KEYC_F19,
143 	KEYC_F20,
144 	KEYC_IC,
145 	KEYC_DC,
146 	KEYC_HOME,
147 	KEYC_END,
148 	KEYC_NPAGE,
149 	KEYC_PPAGE,
150 	KEYC_BTAB,
151 
152 	/* Arrow keys. */
153 	KEYC_UP,
154 	KEYC_DOWN,
155 	KEYC_LEFT,
156 	KEYC_RIGHT,
157 
158 	/* Numeric keypad. */
159 	KEYC_KP_SLASH,
160 	KEYC_KP_STAR,
161 	KEYC_KP_MINUS,
162 	KEYC_KP_SEVEN,
163 	KEYC_KP_EIGHT,
164 	KEYC_KP_NINE,
165 	KEYC_KP_PLUS,
166 	KEYC_KP_FOUR,
167 	KEYC_KP_FIVE,
168 	KEYC_KP_SIX,
169 	KEYC_KP_ONE,
170 	KEYC_KP_TWO,
171 	KEYC_KP_THREE,
172 	KEYC_KP_ENTER,
173 	KEYC_KP_ZERO,
174 	KEYC_KP_PERIOD,
175 };
176 
177 /* Termcap codes. */
178 enum tty_code_code {
179 	TTYC_AX = 0,
180 	TTYC_ACSC,	/* acs_chars, ac */
181 	TTYC_BEL,	/* bell, bl */
182 	TTYC_BLINK,	/* enter_blink_mode, mb */
183 	TTYC_BOLD,	/* enter_bold_mode, md */
184 	TTYC_CIVIS,	/* cursor_invisible, vi */
185 	TTYC_CLEAR,	/* clear_screen, cl */
186 	TTYC_CNORM,	/* cursor_normal, ve */
187 	TTYC_COLORS,	/* max_colors, Co */
188 	TTYC_CSR,	/* change_scroll_region, cs */
189 	TTYC_CUB,	/* parm_left_cursor, LE */
190 	TTYC_CUB1,	/* cursor_left, le */
191 	TTYC_CUD,	/* parm_down_cursor, DO */
192 	TTYC_CUD1,	/* cursor_down, do */
193 	TTYC_CUF,	/* parm_right_cursor, RI */
194 	TTYC_CUF1,	/* cursor_right, nd */
195 	TTYC_CUP,	/* cursor_address, cm */
196 	TTYC_CUU,	/* parm_up_cursor, UP */
197 	TTYC_CUU1,	/* cursor_up, up */
198 	TTYC_DCH,	/* parm_dch, DC */
199 	TTYC_DCH1,	/* delete_character, dc */
200 	TTYC_DIM,	/* enter_dim_mode, mh */
201 	TTYC_DL,	/* parm_delete_line, DL */
202 	TTYC_DL1,	/* delete_line, dl */
203 	TTYC_EL,	/* clr_eol, ce */
204 	TTYC_EL1,	/* clr_bol, cb */
205 	TTYC_ENACS,	/* ena_acs, eA */
206 	TTYC_HOME,	/* cursor_home, ho */
207 	TTYC_HPA,	/* column_address, ch */
208 	TTYC_ICH,	/* parm_ich, IC */
209 	TTYC_ICH1,	/* insert_character, ic */
210 	TTYC_IL,	/* parm_insert_line, IL */
211 	TTYC_IL1,	/* insert_line, il */
212 	TTYC_INVIS,	/* enter_secure_mode, mk */
213 	TTYC_IS1,	/* init_1string, i1 */
214 	TTYC_IS2,	/* init_2string, i2 */
215 	TTYC_IS3,	/* init_3string, i3 */
216 	TTYC_KCBT,	/* key_btab, kB */
217 	TTYC_KCUB1,	/* key_left, kl */
218 	TTYC_KCUD1,	/* key_down, kd */
219 	TTYC_KCUF1,	/* key_right, kr */
220 	TTYC_KCUU1,	/* key_up, ku */
221 	TTYC_KDC2,
222 	TTYC_KDC3,
223 	TTYC_KDC4,
224 	TTYC_KDC5,
225 	TTYC_KDC6,
226 	TTYC_KDC7,
227 	TTYC_KDCH1,	/* key_dc, kD */
228 	TTYC_KDN2,
229 	TTYC_KDN3,
230 	TTYC_KDN4,
231 	TTYC_KDN5,
232 	TTYC_KDN6,
233 	TTYC_KDN7,
234 	TTYC_KEND,	/* key_end, ke */
235 	TTYC_KEND2,
236 	TTYC_KEND3,
237 	TTYC_KEND4,
238 	TTYC_KEND5,
239 	TTYC_KEND6,
240 	TTYC_KEND7,
241 	TTYC_KF1,	/* key_f1, k1 */
242 	TTYC_KF10,	/* key_f10, k; */
243 	TTYC_KF11,	/* key_f11, F1 */
244 	TTYC_KF12,	/* key_f12, F2 */
245 	TTYC_KF13,	/* key_f13, F3 */
246 	TTYC_KF14,	/* key_f14, F4 */
247 	TTYC_KF15,	/* key_f15, F5 */
248 	TTYC_KF16,	/* key_f16, F6 */
249 	TTYC_KF17,	/* key_f17, F7 */
250 	TTYC_KF18,	/* key_f18, F8 */
251 	TTYC_KF19,	/* key_f19, F9 */
252 	TTYC_KF2,	/* key_f2, k2 */
253 	TTYC_KF20,	/* key_f20, F10 */
254 	TTYC_KF3,	/* key_f3, k3 */
255 	TTYC_KF4,	/* key_f4, k4 */
256 	TTYC_KF5,	/* key_f5, k5 */
257 	TTYC_KF6,	/* key_f6, k6 */
258 	TTYC_KF7,	/* key_f7, k7 */
259 	TTYC_KF8,	/* key_f8, k8 */
260 	TTYC_KF9,	/* key_f9, k9 */
261 	TTYC_KHOM2,
262 	TTYC_KHOM3,
263 	TTYC_KHOM4,
264 	TTYC_KHOM5,
265 	TTYC_KHOM6,
266 	TTYC_KHOM7,
267 	TTYC_KHOME,	/* key_home, kh */
268 	TTYC_KIC2,
269 	TTYC_KIC3,
270 	TTYC_KIC4,
271 	TTYC_KIC5,
272 	TTYC_KIC6,
273 	TTYC_KIC7,
274 	TTYC_KICH1,	/* key_ic, kI */
275 	TTYC_KLFT2,
276 	TTYC_KLFT3,
277 	TTYC_KLFT4,
278 	TTYC_KLFT5,
279 	TTYC_KLFT6,
280 	TTYC_KLFT7,
281 	TTYC_KMOUS,	/* key_mouse, Km */
282 	TTYC_KNP,	/* key_npage, kN */
283 	TTYC_KNXT2,
284 	TTYC_KNXT3,
285 	TTYC_KNXT4,
286 	TTYC_KNXT5,
287 	TTYC_KNXT6,
288 	TTYC_KNXT7,
289 	TTYC_KPP,	/* key_ppage, kP */
290 	TTYC_KPRV2,
291 	TTYC_KPRV3,
292 	TTYC_KPRV4,
293 	TTYC_KPRV5,
294 	TTYC_KPRV6,
295 	TTYC_KPRV7,
296 	TTYC_KRIT2,
297 	TTYC_KRIT3,
298 	TTYC_KRIT4,
299 	TTYC_KRIT5,
300 	TTYC_KRIT6,
301 	TTYC_KRIT7,
302 	TTYC_KUP2,
303 	TTYC_KUP3,
304 	TTYC_KUP4,
305 	TTYC_KUP5,
306 	TTYC_KUP6,
307 	TTYC_KUP7,
308 	TTYC_OP,	/* orig_pair, op */
309 	TTYC_REV,	/* enter_reverse_mode, mr */
310 	TTYC_RI,	/* scroll_reverse, sr */
311 	TTYC_RMACS,	/* exit_alt_charset_mode */
312 	TTYC_RMCUP,	/* exit_ca_mode, te */
313 	TTYC_RMIR,	/* exit_insert_mode, ei */
314 	TTYC_RMKX,	/* keypad_local, ke */
315 	TTYC_SETAB,	/* set_a_background, AB */
316 	TTYC_SETAF,	/* set_a_foreground, AF */
317 	TTYC_SGR0,	/* exit_attribute_mode, me */
318 	TTYC_SMACS,	/* enter_alt_charset_mode, as */
319 	TTYC_SMCUP,	/* enter_ca_mode, ti */
320 	TTYC_SMIR,	/* enter_insert_mode, im */
321 	TTYC_SMKX,	/* keypad_xmit, ks */
322 	TTYC_SMSO,	/* enter_standout_mode, so */
323 	TTYC_SMUL,	/* enter_underline_mode, us */
324 	TTYC_VPA,	/* row_address, cv */
325 	TTYC_XENL,	/* eat_newline_glitch, xn */
326 };
327 #define NTTYCODE (TTYC_XENL + 1)
328 
329 /* Termcap types. */
330 enum tty_code_type {
331 	TTYCODE_NONE = 0,
332 	TTYCODE_STRING,
333 	TTYCODE_NUMBER,
334 	TTYCODE_FLAG,
335 };
336 
337 /* Termcap code. */
338 struct tty_code {
339 	enum tty_code_type	type;
340 	union {
341 		char	       *string;
342 		int		number;
343 		int		flag;
344 	} value;
345 };
346 
347 /* Entry in terminal code table. */
348 struct tty_term_code_entry {
349 	enum tty_code_code	code;
350 	enum tty_code_type	type;
351 	const char	       *name;
352 };
353 
354 /* Message codes. */
355 enum msgtype {
356 	MSG_COMMAND,
357 	MSG_DETACH,
358 	MSG_ERROR,
359 	MSG_EXIT,
360 	MSG_EXITED,
361 	MSG_EXITING,
362 	MSG_IDENTIFY,
363 	MSG_PRINT,
364 	MSG_READY,
365 	MSG_RESIZE,
366 	MSG_SHUTDOWN,
367 	MSG_SUSPEND,
368 	MSG_VERSION,
369 	MSG_WAKEUP,
370 	MSG_ENVIRON,
371 	MSG_UNLOCK,
372 	MSG_LOCK,
373 	MSG_SHELL,
374 	MSG_STDERR,
375 	MSG_STDOUT,
376 };
377 
378 /*
379  * Message data.
380  *
381  * Don't forget to bump PROTOCOL_VERSION if any of these change!
382  */
383 struct msg_command_data {
384 	pid_t		pid;			/* pid from $TMUX or -1 */
385 	u_int		idx;			/* index from $TMUX */
386 
387 	int		argc;
388 	char		argv[COMMAND_LENGTH];
389 };
390 
391 struct msg_identify_data {
392 	char		cwd[MAXPATHLEN];
393 
394 	char		term[TERMINAL_LENGTH];
395 
396 #define IDENTIFY_UTF8 0x1
397 #define IDENTIFY_256COLOURS 0x2
398 #define IDENTIFY_88COLOURS 0x4
399 	int		flags;
400 };
401 
402 struct msg_lock_data {
403 	char		cmd[COMMAND_LENGTH];
404 };
405 
406 struct msg_environ_data {
407 	char		var[ENVIRON_LENGTH];
408 };
409 
410 struct msg_shell_data {
411 	char		shell[MAXPATHLEN];
412 };
413 
414 struct msg_exit_data {
415 	int		retcode;
416 };
417 
418 /* Mode key commands. */
419 enum mode_key_cmd {
420 	MODEKEY_NONE,
421 	MODEKEY_OTHER,
422 
423 	/* Editing keys. */
424 	MODEKEYEDIT_BACKSPACE,
425 	MODEKEYEDIT_CANCEL,
426 	MODEKEYEDIT_COMPLETE,
427 	MODEKEYEDIT_CURSORLEFT,
428 	MODEKEYEDIT_CURSORRIGHT,
429 	MODEKEYEDIT_DELETE,
430 	MODEKEYEDIT_DELETELINE,
431 	MODEKEYEDIT_DELETETOENDOFLINE,
432 	MODEKEYEDIT_ENDOFLINE,
433 	MODEKEYEDIT_ENTER,
434 	MODEKEYEDIT_HISTORYDOWN,
435 	MODEKEYEDIT_HISTORYUP,
436 	MODEKEYEDIT_PASTE,
437 	MODEKEYEDIT_STARTOFLINE,
438 	MODEKEYEDIT_SWITCHMODE,
439 	MODEKEYEDIT_SWITCHMODEAPPEND,
440 	MODEKEYEDIT_TRANSPOSECHARS,
441 
442 	/* Menu (choice) keys. */
443 	MODEKEYCHOICE_CANCEL,
444 	MODEKEYCHOICE_CHOOSE,
445 	MODEKEYCHOICE_DOWN,
446 	MODEKEYCHOICE_PAGEDOWN,
447 	MODEKEYCHOICE_PAGEUP,
448 	MODEKEYCHOICE_SCROLLDOWN,
449 	MODEKEYCHOICE_SCROLLUP,
450 	MODEKEYCHOICE_UP,
451 
452 	/* Copy keys. */
453 	MODEKEYCOPY_BACKTOINDENTATION,
454 	MODEKEYCOPY_BOTTOMLINE,
455 	MODEKEYCOPY_CANCEL,
456 	MODEKEYCOPY_CLEARSELECTION,
457 	MODEKEYCOPY_COPYSELECTION,
458 	MODEKEYCOPY_DOWN,
459 	MODEKEYCOPY_ENDOFLINE,
460 	MODEKEYCOPY_GOTOLINE,
461 	MODEKEYCOPY_HALFPAGEDOWN,
462 	MODEKEYCOPY_HALFPAGEUP,
463 	MODEKEYCOPY_HISTORYBOTTOM,
464 	MODEKEYCOPY_HISTORYTOP,
465 	MODEKEYCOPY_JUMP,
466 	MODEKEYCOPY_JUMPAGAIN,
467 	MODEKEYCOPY_JUMPREVERSE,
468 	MODEKEYCOPY_JUMPBACK,
469 	MODEKEYCOPY_LEFT,
470 	MODEKEYCOPY_MIDDLELINE,
471 	MODEKEYCOPY_NEXTPAGE,
472 	MODEKEYCOPY_NEXTSPACE,
473 	MODEKEYCOPY_NEXTSPACEEND,
474 	MODEKEYCOPY_NEXTWORD,
475 	MODEKEYCOPY_NEXTWORDEND,
476 	MODEKEYCOPY_PREVIOUSPAGE,
477 	MODEKEYCOPY_PREVIOUSSPACE,
478 	MODEKEYCOPY_PREVIOUSWORD,
479 	MODEKEYCOPY_RECTANGLETOGGLE,
480 	MODEKEYCOPY_RIGHT,
481 	MODEKEYCOPY_SCROLLDOWN,
482 	MODEKEYCOPY_SCROLLUP,
483 	MODEKEYCOPY_SEARCHAGAIN,
484 	MODEKEYCOPY_SEARCHDOWN,
485 	MODEKEYCOPY_SEARCHREVERSE,
486 	MODEKEYCOPY_SEARCHUP,
487 	MODEKEYCOPY_STARTNUMBERPREFIX,
488 	MODEKEYCOPY_STARTOFLINE,
489 	MODEKEYCOPY_STARTSELECTION,
490 	MODEKEYCOPY_TOPLINE,
491 	MODEKEYCOPY_UP,
492 };
493 
494 /* Entry in the default mode key tables. */
495 struct mode_key_entry {
496 	int			key;
497 
498 	/*
499 	 * Editing mode for vi: 0 is edit mode, keys not in the table are
500 	 * returned as MODEKEY_OTHER; 1 is command mode, keys not in the table
501 	 * are returned as MODEKEY_NONE. This is also matched on, allowing some
502 	 * keys to be bound in edit mode.
503 	 */
504 	int			mode;
505 	enum mode_key_cmd	cmd;
506 };
507 
508 /* Data required while mode keys are in use. */
509 struct mode_key_data {
510 	struct mode_key_tree   *tree;
511 	int			mode;
512 };
513 #define MODEKEY_EMACS 0
514 #define MODEKEY_VI 1
515 
516 /* Binding between a key and a command. */
517 struct mode_key_binding {
518 	int			key;
519 
520 	int			mode;
521 	enum mode_key_cmd	cmd;
522 
523 	SPLAY_ENTRY(mode_key_binding) entry;
524 };
525 SPLAY_HEAD(mode_key_tree, mode_key_binding);
526 
527 /* Command to string mapping. */
528 struct mode_key_cmdstr {
529 	enum mode_key_cmd	 cmd;
530 	const char		*name;
531 };
532 
533 /* Named mode key table description. */
534 struct mode_key_table {
535 	const char		*name;
536 	struct mode_key_cmdstr	*cmdstr;
537 	struct mode_key_tree	*tree;
538 	const struct mode_key_entry *table;	/* default entries */
539 };
540 
541 /* Modes. */
542 #define MODE_CURSOR 0x1
543 #define MODE_INSERT 0x2
544 #define MODE_KCURSOR 0x4
545 #define MODE_KKEYPAD 0x8	/* set = application, clear = number */
546 #define MODE_MOUSE 0x10
547 #define MODE_MOUSEMOTION 0x20
548 #define MODE_WRAP 0x40		/* whether lines wrap */
549 
550 /*
551  * A single UTF-8 character.
552  *
553  * The data member in this must be UTF8_SIZE to allow screen_write_copy to
554  * reinject stored UTF-8 data back into screen_write_cell after combining (ugh
555  * XXX XXX).
556  */
557 struct utf8_data {
558 	u_char	data[UTF8_SIZE];
559 
560 	size_t	have;
561 	size_t	size;
562 
563 	u_int	width;
564 };
565 
566 /* Grid output. */
567 #if defined(DEBUG) && \
568     ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
569      (defined(__GNUC__) && __GNUC__ >= 3))
570 #define GRID_DEBUG(gd, fmt, ...) log_debug2("%s: (sx=%u, sy=%u, hsize=%u) " \
571     fmt, __func__, (gd)->sx, (gd)->sy, (gd)->hsize, ## __VA_ARGS__)
572 #else
573 #define GRID_DEBUG(...)
574 #endif
575 
576 /* Grid attributes. */
577 #define GRID_ATTR_BRIGHT 0x1
578 #define GRID_ATTR_DIM 0x2
579 #define GRID_ATTR_UNDERSCORE 0x4
580 #define GRID_ATTR_BLINK 0x8
581 #define GRID_ATTR_REVERSE 0x10
582 #define GRID_ATTR_HIDDEN 0x20
583 #define GRID_ATTR_ITALICS 0x40
584 #define GRID_ATTR_CHARSET 0x80	/* alternative character set */
585 
586 /* Grid flags. */
587 #define GRID_FLAG_FG256 0x1
588 #define GRID_FLAG_BG256 0x2
589 #define GRID_FLAG_PADDING 0x4
590 #define GRID_FLAG_UTF8 0x8
591 
592 /* Grid line flags. */
593 #define GRID_LINE_WRAPPED 0x1
594 
595 /* Grid cell data. */
596 struct grid_cell {
597 	u_char	attr;
598 	u_char	flags;
599 	u_char	fg;
600 	u_char	bg;
601 	u_char	data;
602 } __packed;
603 
604 /* Grid cell UTF-8 data. Used instead of data in grid_cell for UTF-8 cells. */
605 struct grid_utf8 {
606 	u_char	width;
607 	u_char	data[UTF8_SIZE];
608 } __packed;
609 
610 /* Grid line. */
611 struct grid_line {
612 	u_int	cellsize;
613 	struct grid_cell *celldata;
614 
615 	u_int	utf8size;
616 	struct grid_utf8 *utf8data;
617 
618 	int	flags;
619 } __packed;
620 
621 /* Entire grid of cells. */
622 struct grid {
623 	int	flags;
624 #define GRID_HISTORY 0x1	/* scroll lines into history */
625 
626 	u_int	sx;
627 	u_int	sy;
628 
629 	u_int	hsize;
630 	u_int	hlimit;
631 
632 	struct grid_line *linedata;
633 };
634 
635 /* Option data structures. */
636 struct options_entry {
637 	char		*name;
638 
639 	enum {
640 		OPTIONS_STRING,
641 		OPTIONS_NUMBER,
642 		OPTIONS_DATA,
643 	} type;
644 
645 	char		*str;
646 	long long	 num;
647 	void		*data;
648 
649 	void		 (*freefn)(void *);
650 
651 	SPLAY_ENTRY(options_entry) entry;
652 };
653 
654 struct options {
655 	SPLAY_HEAD(options_tree, options_entry) tree;
656 	struct options	*parent;
657 };
658 
659 /* Key list for prefix option. */
660 ARRAY_DECL(keylist, int);
661 
662 /* Scheduled job. */
663 struct job {
664 	char		*cmd;
665 	pid_t		 pid;
666 	int		 status;
667 
668 	struct client	*client;
669 
670 	int		 fd;
671 	struct bufferevent *event;
672 
673 	void		(*callbackfn)(struct job *);
674 	void		(*freefn)(void *);
675 	void		*data;
676 
677 	int		 flags;
678 #define JOB_PERSIST 0x1	/* don't free after callback */
679 
680 	RB_ENTRY(job)	 entry;
681 	SLIST_ENTRY(job) lentry;
682 };
683 RB_HEAD(jobs, job);
684 SLIST_HEAD(joblist, job);
685 
686 /* Screen selection. */
687 struct screen_sel {
688 	int		 flag;
689 	int		 rectflag;
690 
691 	u_int		 sx;
692 	u_int		 sy;
693 
694 	u_int		 ex;
695 	u_int		 ey;
696 
697 	struct grid_cell cell;
698 };
699 
700 /* Virtual screen. */
701 struct screen {
702 	char		*title;
703 
704 	struct grid	*grid;		/* grid data */
705 
706 	u_int		 cx;		/* cursor x */
707 	u_int		 cy;		/* cursor y */
708 
709 	u_int		 rupper;	/* scroll region top */
710 	u_int		 rlower;	/* scroll region bottom */
711 
712 	int		 mode;
713 
714 	bitstr_t	*tabs;
715 
716 	struct screen_sel sel;
717 };
718 
719 /* Screen write context. */
720 struct screen_write_ctx {
721 	struct window_pane *wp;
722 	struct screen	*s;
723 };
724 
725 /* Screen size. */
726 #define screen_size_x(s) ((s)->grid->sx)
727 #define screen_size_y(s) ((s)->grid->sy)
728 #define screen_hsize(s) ((s)->grid->hsize)
729 #define screen_hlimit(s) ((s)->grid->hlimit)
730 
731 /* Input parser context. */
732 struct input_ctx {
733 	struct window_pane     *wp;
734 	struct screen_write_ctx ctx;
735 
736 	struct grid_cell	cell;
737 
738 	struct grid_cell	old_cell;
739 	u_int 			old_cx;
740 	u_int			old_cy;
741 
742 	u_char			interm_buf[4];
743 	size_t			interm_len;
744 
745 	u_char			param_buf[64];
746 	size_t			param_len;
747 
748 	u_char			input_buf[256];
749 	size_t			input_len;
750 
751 	int			param_list[24];	/* -1 not present */
752 	u_int			param_list_len;
753 
754 	struct utf8_data	utf8data;
755 
756 	int			ch;
757 	int			flags;
758 #define INPUT_DISCARD 0x1
759 
760 	const struct input_state *state;
761 };
762 
763 /*
764  * Window mode. Windows can be in several modes and this is used to call the
765  * right function to handle input and output.
766  */
767 struct session;
768 struct window;
769 struct mouse_event;
770 struct window_mode {
771 	struct screen *(*init)(struct window_pane *);
772 	void	(*free)(struct window_pane *);
773 	void	(*resize)(struct window_pane *, u_int, u_int);
774 	void	(*key)(struct window_pane *, struct session *, int);
775 	void	(*mouse)(struct window_pane *,
776 		    struct session *, struct mouse_event *);
777 	void	(*timer)(struct window_pane *);
778 };
779 
780 /* Child window structure. */
781 struct window_pane {
782 	struct window	*window;
783 	struct layout_cell *layout_cell;
784 
785 	u_int		 sx;
786 	u_int		 sy;
787 
788 	u_int		 xoff;
789 	u_int		 yoff;
790 
791 	int		 flags;
792 #define PANE_REDRAW 0x1
793 #define PANE_FREEZE 0x2
794 
795 	char		*cmd;
796 	char		*shell;
797 	char		*cwd;
798 
799 	pid_t		 pid;
800 	char		 tty[TTY_NAME_MAX];
801 
802 	int		 fd;
803 	struct bufferevent *event;
804 
805 	struct input_ctx ictx;
806 
807 	int		 pipe_fd;
808 	struct bufferevent *pipe_event;
809 	size_t		 pipe_off;
810 
811 	struct screen	*screen;
812 	struct screen	 base;
813 
814 	/* Saved in alternative screen mode. */
815 	u_int		 saved_cx;
816 	u_int		 saved_cy;
817 	struct grid	*saved_grid;
818 	struct grid_cell saved_cell;
819 
820 	const struct window_mode *mode;
821 	void		*modedata;
822 
823 	TAILQ_ENTRY(window_pane) entry;
824 };
825 TAILQ_HEAD(window_panes, window_pane);
826 
827 /* Window structure. */
828 struct window {
829 	char		*name;
830 	struct event	 name_timer;
831 	struct timeval   silence_timer;
832 
833 	struct window_pane *active;
834 	struct window_pane *last;
835 	struct window_panes panes;
836 
837 	int		 lastlayout;
838 	struct layout_cell *layout_root;
839 
840 	u_int		 sx;
841 	u_int		 sy;
842 
843 	int		 flags;
844 #define WINDOW_BELL 0x1
845 #define WINDOW_ACTIVITY 0x2
846 #define WINDOW_REDRAW 0x4
847 #define WINDOW_SILENCE 0x8
848 
849 	struct options	 options;
850 
851 	u_int		 references;
852 };
853 ARRAY_DECL(windows, struct window *);
854 
855 /* Entry on local window list. */
856 struct winlink {
857 	int		 idx;
858 	struct window	*window;
859 
860 	size_t		 status_width;
861 	struct grid_cell status_cell;
862 	char		*status_text;
863 
864 	int              flags;
865 #define WINLINK_BELL 0x1
866 #define WINLINK_ACTIVITY 0x2
867 #define WINLINK_CONTENT 0x4
868 #define WINLINK_SILENCE 0x8
869 #define WINLINK_ALERTFLAGS \
870     (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_CONTENT|WINLINK_SILENCE)
871 
872 	RB_ENTRY(winlink) entry;
873 	TAILQ_ENTRY(winlink) sentry;
874 };
875 RB_HEAD(winlinks, winlink);
876 TAILQ_HEAD(winlink_stack, winlink);
877 
878 /* Layout direction. */
879 enum layout_type {
880 	LAYOUT_LEFTRIGHT,
881 	LAYOUT_TOPBOTTOM,
882 	LAYOUT_WINDOWPANE
883 };
884 
885 /* Layout cells queue. */
886 TAILQ_HEAD(layout_cells, layout_cell);
887 
888 /* Layout cell. */
889 struct layout_cell {
890 	enum layout_type type;
891 
892 	struct layout_cell *parent;
893 
894 	u_int		 sx;
895 	u_int		 sy;
896 
897 	u_int		 xoff;
898 	u_int		 yoff;
899 
900 	struct window_pane *wp;
901 	struct layout_cells cells;
902 
903 	TAILQ_ENTRY(layout_cell) entry;
904 };
905 
906 /* Paste buffer. */
907 struct paste_buffer {
908 	char		*data;
909 	size_t		 size;
910 };
911 ARRAY_DECL(paste_stack, struct paste_buffer *);
912 
913 /* Environment variable. */
914 struct environ_entry {
915 	char		*name;
916 	char		*value;
917 
918 	RB_ENTRY(environ_entry) entry;
919 };
920 RB_HEAD(environ, environ_entry);
921 
922 /* Client session. */
923 struct session_group {
924 	TAILQ_HEAD(, session) sessions;
925 
926 	TAILQ_ENTRY(session_group) entry;
927 };
928 TAILQ_HEAD(session_groups, session_group);
929 
930 struct session {
931 	u_int		 idx;
932 
933 	char		*name;
934 	char		*cwd;
935 
936 	struct timeval	 creation_time;
937 	struct timeval	 activity_time;
938 
939 	u_int		 sx;
940 	u_int		 sy;
941 
942 	struct winlink	*curw;
943 	struct winlink_stack lastw;
944 	struct winlinks	 windows;
945 
946 	struct options	 options;
947 
948 	struct paste_stack buffers;
949 
950 #define SESSION_UNATTACHED 0x1	/* not attached to any clients */
951 	int		 flags;
952 
953 	struct termios	*tio;
954 
955 	struct environ	 environ;
956 
957 	int		 references;
958 
959 	TAILQ_ENTRY(session) gentry;
960 	RB_ENTRY(session)    entry;
961 };
962 RB_HEAD(sessions, session);
963 ARRAY_DECL(sessionslist, struct session *);
964 
965 /* TTY information. */
966 struct tty_key {
967 	char		 ch;
968 	int		 key;
969 
970 	struct tty_key	*left;
971 	struct tty_key	*right;
972 
973 	struct tty_key	*next;
974 };
975 
976 struct tty_term {
977 	char		*name;
978 	u_int		 references;
979 
980 	char		 acs[UCHAR_MAX + 1][2];
981 
982 	struct tty_code	 codes[NTTYCODE];
983 
984 #define TERM_256COLOURS 0x1
985 #define TERM_88COLOURS 0x2
986 #define TERM_EARLYWRAP 0x4
987 	int		 flags;
988 
989 	SLIST_ENTRY(tty_term) entry;
990 };
991 SLIST_HEAD(tty_terms, tty_term);
992 
993 struct tty {
994 	char		*path;
995 
996 	u_int		 sx;
997 	u_int		 sy;
998 
999 	u_int		 cx;
1000 	u_int		 cy;
1001 
1002 	int		 mode;
1003 
1004 	u_int		 rlower;
1005 	u_int		 rupper;
1006 
1007 	char		*termname;
1008 	struct tty_term	*term;
1009 
1010 	int		 fd;
1011 	struct bufferevent *event;
1012 
1013 	int		 log_fd;
1014 
1015 	struct termios	 tio;
1016 
1017 	struct grid_cell cell;
1018 
1019 #define TTY_NOCURSOR 0x1
1020 #define TTY_FREEZE 0x2
1021 #define TTY_ESCAPE 0x4
1022 #define TTY_UTF8 0x8
1023 #define TTY_STARTED 0x10
1024 #define TTY_OPENED 0x20
1025 #define TTY_BACKOFF 0x40
1026 	int		 flags;
1027 
1028 	int		 term_flags;
1029 
1030 	void		 (*key_callback)(int, struct mouse_event *, void *);
1031 	void		*key_data;
1032 	struct event	 key_timer;
1033 	struct tty_key	*key_tree;
1034 };
1035 
1036 /* TTY command context and function pointer. */
1037 struct tty_ctx {
1038 	struct window_pane *wp;
1039 
1040 	const struct grid_cell *cell;
1041 	const struct grid_utf8 *utf8;
1042 
1043 	u_int		 num;
1044 	void		*ptr;
1045 
1046 	/*
1047 	 * Cursor and region position before the screen was updated - this is
1048 	 * where the command should be applied; the values in the screen have
1049 	 * already been updated.
1050 	 */
1051 	u_int		 ocx;
1052 	u_int		 ocy;
1053 
1054 	u_int		 orupper;
1055 	u_int		 orlower;
1056 
1057 	/* Saved last cell on line. */
1058 	struct grid_cell last_cell;
1059 	struct grid_utf8 last_utf8;
1060 	u_int		 last_width;
1061 };
1062 
1063 /*
1064  * xterm mouse mode is fairly silly. Buttons are in the bottom two
1065  * bits: 0 button 1; 1 button 2; 2 button 3; 3 buttons released.
1066  *
1067  * Bit 3 is shift; bit 4 is meta; bit 5 control.
1068  *
1069  * Bit 6 is added for mouse buttons 4 and 5.
1070  */
1071 /* Mouse input. */
1072 struct mouse_event {
1073 	u_char	b;
1074 #define MOUSE_1 0
1075 #define MOUSE_2 1
1076 #define MOUSE_3 2
1077 #define MOUSE_UP 3
1078 #define MOUSE_BUTTON 3
1079 #define MOUSE_45 64
1080 	u_char	x;
1081 	u_char	y;
1082 };
1083 
1084 /* Saved message entry. */
1085 struct message_entry {
1086 	char   *msg;
1087 	time_t	msg_time;
1088 };
1089 
1090 /* Client connection. */
1091 struct client {
1092 	struct imsgbuf	 ibuf;
1093 	struct event	 event;
1094 	int		 retcode;
1095 
1096 	struct timeval	 creation_time;
1097 	struct timeval	 activity_time;
1098 
1099 	struct environ	 environ;
1100 
1101 	char		*title;
1102 	char		*cwd;
1103 
1104 	struct tty	 tty;
1105 
1106 	int		 stdin_fd;
1107 	void		*stdin_data;
1108 	void		(*stdin_callback)(struct client *, void *);
1109 	struct bufferevent *stdin_event;
1110 
1111 	int		 stdout_fd;
1112 	struct bufferevent *stdout_event;
1113 
1114 	int		 stderr_fd;
1115 	struct bufferevent *stderr_event;
1116 
1117 	struct event	 repeat_timer;
1118 
1119 	struct timeval	 status_timer;
1120 	struct jobs	 status_jobs;
1121 	struct screen	 status;
1122 
1123 #define CLIENT_TERMINAL 0x1
1124 #define CLIENT_PREFIX 0x2
1125 #define CLIENT_EXIT 0x4
1126 #define CLIENT_REDRAW 0x8
1127 #define CLIENT_STATUS 0x10
1128 #define CLIENT_REPEAT 0x20	/* allow command to repeat within repeat time */
1129 #define CLIENT_SUSPENDED 0x40
1130 #define CLIENT_BAD 0x80
1131 #define CLIENT_IDENTIFY 0x100
1132 #define CLIENT_DEAD 0x200
1133 #define CLIENT_BORDERS 0x400
1134 #define CLIENT_READONLY 0x800
1135 #define CLIENT_BACKOFF 0x1000
1136 #define CLIENT_REDRAWWINDOW 0x2000
1137 	int		 flags;
1138 
1139 	struct event	 identify_timer;
1140 
1141 	char		*message_string;
1142 	struct event	 message_timer;
1143 	ARRAY_DECL(, struct message_entry) message_log;
1144 
1145 	char		*prompt_string;
1146 	char		*prompt_buffer;
1147 	size_t		 prompt_index;
1148 	int		 (*prompt_callbackfn)(void *, const char *);
1149 	void		 (*prompt_freefn)(void *);
1150 	void		*prompt_data;
1151 	u_int            prompt_hindex;
1152 
1153 #define PROMPT_SINGLE 0x1
1154 	int		 prompt_flags;
1155 
1156 	struct mode_key_data prompt_mdata;
1157 
1158 	struct session	*session;
1159 	struct session	*last_session;
1160 
1161 	int		 references;
1162 };
1163 ARRAY_DECL(clients, struct client *);
1164 
1165 /* Key/command line command. */
1166 struct cmd_ctx {
1167 	/*
1168 	 * curclient is the client where this command was executed if inside
1169 	 * tmux. This is NULL if the command came from the command-line.
1170 	 *
1171 	 * cmdclient is the client which sent the MSG_COMMAND to the server, if
1172 	 * any. This is NULL unless the command came from the command-line.
1173 	 *
1174 	 * cmdclient and curclient may both be NULL if the command is in the
1175 	 * configuration file.
1176 	 */
1177 	struct client  *curclient;
1178 	struct client  *cmdclient;
1179 
1180 	struct msg_command_data	*msgdata;
1181 
1182 	/* gcc2 doesn't understand attributes on function pointers... */
1183 #if defined(__GNUC__) && __GNUC__ >= 3
1184 	void printflike2 (*print)(struct cmd_ctx *, const char *, ...);
1185 	void printflike2 (*info)(struct cmd_ctx *, const char *, ...);
1186 	void printflike2 (*error)(struct cmd_ctx *, const char *, ...);
1187 #else
1188 	void (*print)(struct cmd_ctx *, const char *, ...);
1189 	void (*info)(struct cmd_ctx *, const char *, ...);
1190 	void (*error)(struct cmd_ctx *, const char *, ...);
1191 #endif
1192 };
1193 
1194 struct cmd {
1195 	const struct cmd_entry *entry;
1196 	void		*data;
1197 
1198 	TAILQ_ENTRY(cmd) qentry;
1199 };
1200 struct cmd_list {
1201 	int		 references;
1202 	TAILQ_HEAD(, cmd) list;
1203 };
1204 
1205 struct cmd_entry {
1206 	const char	*name;
1207 	const char	*alias;
1208 	const char	*usage;
1209 
1210 #define CMD_STARTSERVER 0x1
1211 #define CMD_CANTNEST 0x2
1212 #define CMD_SENDENVIRON 0x4
1213 #define CMD_ARG1 0x8
1214 #define CMD_ARG01 0x10
1215 #define CMD_ARG2 0x20
1216 #define CMD_ARG12 0x40
1217 #define CMD_READONLY 0x80
1218 	int		 flags;
1219 
1220 	const char	*chflags;
1221 
1222 	void		 (*init)(struct cmd *, int);
1223 	int		 (*parse)(struct cmd *, int, char **, char **);
1224 	int		 (*exec)(struct cmd *, struct cmd_ctx *);
1225 	void		 (*free)(struct cmd *);
1226 	size_t		 (*print)(struct cmd *, char *, size_t);
1227 };
1228 
1229 /* Generic command data. */
1230 struct cmd_target_data {
1231 	uint64_t chflags;
1232 
1233 	char	*target;
1234 
1235 	char	*arg;
1236 	char	*arg2;
1237 };
1238 
1239 struct cmd_srcdst_data {
1240 	uint64_t chflags;
1241 
1242 	char	*src;
1243 	char	*dst;
1244 
1245 	char	*arg;
1246 	char	*arg2;
1247 };
1248 
1249 struct cmd_buffer_data {
1250 	uint64_t chflags;
1251 
1252 	char	*target;
1253 	int	 buffer;
1254 
1255 	char	*arg;
1256 	char	*arg2;
1257 };
1258 
1259 /* Key binding. */
1260 struct key_binding {
1261 	int		 key;
1262 	struct cmd_list	*cmdlist;
1263 	int		 can_repeat;
1264 
1265 	SPLAY_ENTRY(key_binding) entry;
1266 };
1267 SPLAY_HEAD(key_bindings, key_binding);
1268 
1269 /* Set/display option data. */
1270 struct set_option_entry {
1271 	const char	*name;
1272 	enum {
1273 		SET_OPTION_STRING,
1274 		SET_OPTION_NUMBER,
1275 		SET_OPTION_KEYS,
1276 		SET_OPTION_COLOUR,
1277 		SET_OPTION_ATTRIBUTES,
1278 		SET_OPTION_FLAG,
1279 		SET_OPTION_CHOICE
1280 	} type;
1281 
1282 	u_int		 minimum;
1283 	u_int		 maximum;
1284 
1285 	const char     **choices;
1286 };
1287 
1288 /* List of configuration causes. */
1289 ARRAY_DECL(causelist, char *);
1290 
1291 /* tmux.c */
1292 extern struct options global_options;
1293 extern struct options global_s_options;
1294 extern struct options global_w_options;
1295 extern struct environ global_environ;
1296 extern struct event_base *ev_base;
1297 extern char	*cfg_file;
1298 extern char	*shell_cmd;
1299 extern int	 debug_level;
1300 extern time_t	 start_time;
1301 extern char	 socket_path[MAXPATHLEN];
1302 extern int	 login_shell;
1303 extern char	*environ_path;
1304 extern pid_t	 environ_pid;
1305 extern u_int	 environ_idx;
1306 void		 logfile(const char *);
1307 const char	*getshell(void);
1308 int		 checkshell(const char *);
1309 int		 areshell(const char *);
1310 __dead void	 shell_exec(const char *, const char *);
1311 
1312 /* cfg.c */
1313 extern int       cfg_finished;
1314 extern struct causelist cfg_causes;
1315 void printflike2 cfg_add_cause(struct causelist *, const char *, ...);
1316 int		 load_cfg(const char *, struct cmd_ctx *, struct causelist *);
1317 
1318 /* mode-key.c */
1319 extern const struct mode_key_table mode_key_tables[];
1320 extern struct mode_key_tree mode_key_tree_vi_edit;
1321 extern struct mode_key_tree mode_key_tree_vi_choice;
1322 extern struct mode_key_tree mode_key_tree_vi_copy;
1323 extern struct mode_key_tree mode_key_tree_emacs_edit;
1324 extern struct mode_key_tree mode_key_tree_emacs_choice;
1325 extern struct mode_key_tree mode_key_tree_emacs_copy;
1326 int	mode_key_cmp(struct mode_key_binding *, struct mode_key_binding *);
1327 SPLAY_PROTOTYPE(mode_key_tree, mode_key_binding, entry, mode_key_cmp);
1328 const char *mode_key_tostring(struct mode_key_cmdstr *r, enum mode_key_cmd);
1329 enum mode_key_cmd mode_key_fromstring(struct mode_key_cmdstr *, const char *);
1330 const struct mode_key_table *mode_key_findtable(const char *);
1331 void	mode_key_init_trees(void);
1332 void	mode_key_init(struct mode_key_data *, struct mode_key_tree *);
1333 enum mode_key_cmd mode_key_lookup(struct mode_key_data *, int);
1334 
1335 /* options.c */
1336 int	options_cmp(struct options_entry *, struct options_entry *);
1337 SPLAY_PROTOTYPE(options_tree, options_entry, entry, options_cmp);
1338 void	options_init(struct options *, struct options *);
1339 void	options_free(struct options *);
1340 struct options_entry *options_find1(struct options *, const char *);
1341 struct options_entry *options_find(struct options *, const char *);
1342 void	options_remove(struct options *, const char *);
1343 struct options_entry *printflike3 options_set_string(
1344 	    struct options *, const char *, const char *, ...);
1345 char   *options_get_string(struct options *, const char *);
1346 struct options_entry *options_set_number(
1347 	    struct options *, const char *, long long);
1348 long long options_get_number(struct options *, const char *);
1349 struct options_entry *options_set_data(
1350 	    struct options *, const char *, void *, void (*)(void *));
1351 void   *options_get_data(struct options *, const char *);
1352 
1353 /* job.c */
1354 extern struct joblist all_jobs;
1355 int	job_cmp(struct job *, struct job *);
1356 RB_PROTOTYPE(jobs, job, entry, job_cmp);
1357 void	job_tree_init(struct jobs *);
1358 void	job_tree_free(struct jobs *);
1359 struct job *job_get(struct jobs *, const char *);
1360 struct job *job_add(struct jobs *, int, struct client *,
1361 	    const char *, void (*)(struct job *), void (*)(void *), void *);
1362 void	job_remove(struct jobs *, struct job *);
1363 void	job_free(struct job *);
1364 int	job_run(struct job *);
1365 void	job_died(struct job *, int);
1366 void	job_kill(struct job *);
1367 
1368 /* environ.c */
1369 int	environ_cmp(struct environ_entry *, struct environ_entry *);
1370 RB_PROTOTYPE(environ, environ_entry, entry, environ_cmp);
1371 void	environ_init(struct environ *);
1372 void	environ_free(struct environ *);
1373 void	environ_copy(struct environ *, struct environ *);
1374 struct environ_entry *environ_find(struct environ *, const char *);
1375 void	environ_set(struct environ *, const char *, const char *);
1376 void	environ_put(struct environ *, const char *);
1377 void	environ_unset(struct environ *, const char *);
1378 void	environ_update(const char *, struct environ *, struct environ *);
1379 void	environ_push(struct environ *);
1380 
1381 /* tty.c */
1382 void	tty_raw(struct tty *, const char *);
1383 void	tty_attributes(struct tty *, const struct grid_cell *);
1384 void	tty_reset(struct tty *);
1385 void	tty_region_pane(struct tty *, const struct tty_ctx *, u_int, u_int);
1386 void	tty_region(struct tty *, u_int, u_int);
1387 void	tty_cursor_pane(struct tty *, const struct tty_ctx *, u_int, u_int);
1388 void	tty_cursor(struct tty *, u_int, u_int);
1389 void	tty_putcode(struct tty *, enum tty_code_code);
1390 void	tty_putcode1(struct tty *, enum tty_code_code, int);
1391 void	tty_putcode2(struct tty *, enum tty_code_code, int, int);
1392 void	tty_puts(struct tty *, const char *);
1393 void	tty_putc(struct tty *, u_char);
1394 void	tty_pututf8(struct tty *, const struct grid_utf8 *);
1395 void	tty_init(struct tty *, int, char *);
1396 int	tty_resize(struct tty *);
1397 void	tty_start_tty(struct tty *);
1398 void	tty_stop_tty(struct tty *);
1399 void	tty_set_title(struct tty *, const char *);
1400 void	tty_update_mode(struct tty *, int);
1401 void	tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int);
1402 int	tty_open(struct tty *, const char *, char **);
1403 void	tty_close(struct tty *);
1404 void	tty_free(struct tty *);
1405 void	tty_write(void (*)(
1406 	    struct tty *, const struct tty_ctx *), const struct tty_ctx *);
1407 void	tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *);
1408 void	tty_cmd_cell(struct tty *, const struct tty_ctx *);
1409 void	tty_cmd_clearendofline(struct tty *, const struct tty_ctx *);
1410 void	tty_cmd_clearendofscreen(struct tty *, const struct tty_ctx *);
1411 void	tty_cmd_clearline(struct tty *, const struct tty_ctx *);
1412 void	tty_cmd_clearscreen(struct tty *, const struct tty_ctx *);
1413 void	tty_cmd_clearstartofline(struct tty *, const struct tty_ctx *);
1414 void	tty_cmd_clearstartofscreen(struct tty *, const struct tty_ctx *);
1415 void	tty_cmd_deletecharacter(struct tty *, const struct tty_ctx *);
1416 void	tty_cmd_deleteline(struct tty *, const struct tty_ctx *);
1417 void	tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *);
1418 void	tty_cmd_insertline(struct tty *, const struct tty_ctx *);
1419 void	tty_cmd_linefeed(struct tty *, const struct tty_ctx *);
1420 void	tty_cmd_utf8character(struct tty *, const struct tty_ctx *);
1421 void	tty_cmd_reverseindex(struct tty *, const struct tty_ctx *);
1422 
1423 /* tty-term.c */
1424 extern struct tty_terms tty_terms;
1425 extern struct tty_term_code_entry tty_term_codes[NTTYCODE];
1426 struct tty_term *tty_term_find(char *, int, const char *, char **);
1427 void		 tty_term_free(struct tty_term *);
1428 int		 tty_term_has(struct tty_term *, enum tty_code_code);
1429 const char	*tty_term_string(struct tty_term *, enum tty_code_code);
1430 const char	*tty_term_string1(struct tty_term *, enum tty_code_code, int);
1431 const char	*tty_term_string2(
1432 		     struct tty_term *, enum tty_code_code, int, int);
1433 int		 tty_term_number(struct tty_term *, enum tty_code_code);
1434 int		 tty_term_flag(struct tty_term *, enum tty_code_code);
1435 
1436 /* tty-acs.c */
1437 const char	*tty_acs_get(struct tty *, u_char);
1438 
1439 /* tty-keys.c */
1440 void	tty_keys_init(struct tty *);
1441 void	tty_keys_free(struct tty *);
1442 int	tty_keys_next(struct tty *);
1443 
1444 /* paste.c */
1445 void		 paste_init_stack(struct paste_stack *);
1446 void		 paste_free_stack(struct paste_stack *);
1447 struct paste_buffer *paste_walk_stack(struct paste_stack *, uint *);
1448 struct paste_buffer *paste_get_top(struct paste_stack *);
1449 struct paste_buffer *paste_get_index(struct paste_stack *, u_int);
1450 int		 paste_free_top(struct paste_stack *);
1451 int		 paste_free_index(struct paste_stack *, u_int);
1452 void		 paste_add(struct paste_stack *, char *, size_t, u_int);
1453 int		 paste_replace(struct paste_stack *, u_int, char *, size_t);
1454 char		*paste_print(struct paste_buffer *, size_t);
1455 
1456 /* clock.c */
1457 extern const char clock_table[14][5][5];
1458 void		 clock_draw(struct screen_write_ctx *, int, int);
1459 
1460 /* cmd-set-option.c */
1461 extern const struct set_option_entry set_option_table[];
1462 extern const struct set_option_entry set_session_option_table[];
1463 extern const struct set_option_entry set_window_option_table[];
1464 const char	*cmd_set_option_print(
1465 		    const struct set_option_entry *, struct options_entry *);
1466 
1467 /* cmd.c */
1468 int		 cmd_pack_argv(int, char **, char *, size_t);
1469 int		 cmd_unpack_argv(char *, size_t, int, char ***);
1470 char	       **cmd_copy_argv(int, char **);
1471 void		 cmd_free_argv(int, char **);
1472 struct cmd	*cmd_parse(int, char **, char **);
1473 int		 cmd_exec(struct cmd *, struct cmd_ctx *);
1474 void		 cmd_free(struct cmd *);
1475 size_t		 cmd_print(struct cmd *, char *, size_t);
1476 struct session	*cmd_current_session(struct cmd_ctx *);
1477 struct client	*cmd_current_client(struct cmd_ctx *);
1478 struct client	*cmd_find_client(struct cmd_ctx *, const char *);
1479 struct session	*cmd_find_session(struct cmd_ctx *, const char *);
1480 struct winlink	*cmd_find_window(
1481 		     struct cmd_ctx *, const char *, struct session **);
1482 int		 cmd_find_index(
1483 		     struct cmd_ctx *, const char *, struct session **);
1484 struct winlink	*cmd_find_pane(struct cmd_ctx *,
1485 		     const char *, struct session **, struct window_pane **);
1486 char		*cmd_template_replace(char *, const char *, int);
1487 extern const struct cmd_entry *cmd_table[];
1488 extern const struct cmd_entry cmd_attach_session_entry;
1489 extern const struct cmd_entry cmd_bind_key_entry;
1490 extern const struct cmd_entry cmd_break_pane_entry;
1491 extern const struct cmd_entry cmd_capture_pane_entry;
1492 extern const struct cmd_entry cmd_choose_buffer_entry;
1493 extern const struct cmd_entry cmd_choose_client_entry;
1494 extern const struct cmd_entry cmd_choose_session_entry;
1495 extern const struct cmd_entry cmd_choose_window_entry;
1496 extern const struct cmd_entry cmd_clear_history_entry;
1497 extern const struct cmd_entry cmd_clock_mode_entry;
1498 extern const struct cmd_entry cmd_command_prompt_entry;
1499 extern const struct cmd_entry cmd_confirm_before_entry;
1500 extern const struct cmd_entry cmd_copy_buffer_entry;
1501 extern const struct cmd_entry cmd_copy_mode_entry;
1502 extern const struct cmd_entry cmd_delete_buffer_entry;
1503 extern const struct cmd_entry cmd_detach_client_entry;
1504 extern const struct cmd_entry cmd_display_message_entry;
1505 extern const struct cmd_entry cmd_display_panes_entry;
1506 extern const struct cmd_entry cmd_down_pane_entry;
1507 extern const struct cmd_entry cmd_find_window_entry;
1508 extern const struct cmd_entry cmd_has_session_entry;
1509 extern const struct cmd_entry cmd_if_shell_entry;
1510 extern const struct cmd_entry cmd_join_pane_entry;
1511 extern const struct cmd_entry cmd_kill_pane_entry;
1512 extern const struct cmd_entry cmd_kill_server_entry;
1513 extern const struct cmd_entry cmd_kill_session_entry;
1514 extern const struct cmd_entry cmd_kill_window_entry;
1515 extern const struct cmd_entry cmd_last_pane_entry;
1516 extern const struct cmd_entry cmd_last_window_entry;
1517 extern const struct cmd_entry cmd_link_window_entry;
1518 extern const struct cmd_entry cmd_list_buffers_entry;
1519 extern const struct cmd_entry cmd_list_clients_entry;
1520 extern const struct cmd_entry cmd_list_commands_entry;
1521 extern const struct cmd_entry cmd_list_keys_entry;
1522 extern const struct cmd_entry cmd_list_panes_entry;
1523 extern const struct cmd_entry cmd_list_sessions_entry;
1524 extern const struct cmd_entry cmd_list_windows_entry;
1525 extern const struct cmd_entry cmd_load_buffer_entry;
1526 extern const struct cmd_entry cmd_lock_client_entry;
1527 extern const struct cmd_entry cmd_lock_server_entry;
1528 extern const struct cmd_entry cmd_lock_session_entry;
1529 extern const struct cmd_entry cmd_move_window_entry;
1530 extern const struct cmd_entry cmd_new_session_entry;
1531 extern const struct cmd_entry cmd_new_window_entry;
1532 extern const struct cmd_entry cmd_next_layout_entry;
1533 extern const struct cmd_entry cmd_next_window_entry;
1534 extern const struct cmd_entry cmd_paste_buffer_entry;
1535 extern const struct cmd_entry cmd_pipe_pane_entry;
1536 extern const struct cmd_entry cmd_previous_layout_entry;
1537 extern const struct cmd_entry cmd_previous_window_entry;
1538 extern const struct cmd_entry cmd_refresh_client_entry;
1539 extern const struct cmd_entry cmd_rename_session_entry;
1540 extern const struct cmd_entry cmd_rename_window_entry;
1541 extern const struct cmd_entry cmd_resize_pane_entry;
1542 extern const struct cmd_entry cmd_respawn_window_entry;
1543 extern const struct cmd_entry cmd_rotate_window_entry;
1544 extern const struct cmd_entry cmd_run_shell_entry;
1545 extern const struct cmd_entry cmd_save_buffer_entry;
1546 extern const struct cmd_entry cmd_select_layout_entry;
1547 extern const struct cmd_entry cmd_select_pane_entry;
1548 extern const struct cmd_entry cmd_select_window_entry;
1549 extern const struct cmd_entry cmd_send_keys_entry;
1550 extern const struct cmd_entry cmd_send_prefix_entry;
1551 extern const struct cmd_entry cmd_server_info_entry;
1552 extern const struct cmd_entry cmd_set_buffer_entry;
1553 extern const struct cmd_entry cmd_set_environment_entry;
1554 extern const struct cmd_entry cmd_set_option_entry;
1555 extern const struct cmd_entry cmd_set_window_option_entry;
1556 extern const struct cmd_entry cmd_show_buffer_entry;
1557 extern const struct cmd_entry cmd_show_environment_entry;
1558 extern const struct cmd_entry cmd_show_messages_entry;
1559 extern const struct cmd_entry cmd_show_options_entry;
1560 extern const struct cmd_entry cmd_show_window_options_entry;
1561 extern const struct cmd_entry cmd_source_file_entry;
1562 extern const struct cmd_entry cmd_split_window_entry;
1563 extern const struct cmd_entry cmd_start_server_entry;
1564 extern const struct cmd_entry cmd_suspend_client_entry;
1565 extern const struct cmd_entry cmd_swap_pane_entry;
1566 extern const struct cmd_entry cmd_swap_window_entry;
1567 extern const struct cmd_entry cmd_switch_client_entry;
1568 extern const struct cmd_entry cmd_unbind_key_entry;
1569 extern const struct cmd_entry cmd_unlink_window_entry;
1570 extern const struct cmd_entry cmd_up_pane_entry;
1571 
1572 /* cmd-list.c */
1573 struct cmd_list	*cmd_list_parse(int, char **, char **);
1574 int		 cmd_list_exec(struct cmd_list *, struct cmd_ctx *);
1575 void		 cmd_list_free(struct cmd_list *);
1576 size_t		 cmd_list_print(struct cmd_list *, char *, size_t);
1577 
1578 /* cmd-string.c */
1579 int	cmd_string_parse(const char *, struct cmd_list **, char **);
1580 
1581 /* cmd-generic.c */
1582 size_t	cmd_prarg(char *, size_t, const char *, char *);
1583 int	cmd_check_flag(uint64_t, int);
1584 void	cmd_set_flag(uint64_t *, int);
1585 #define CMD_TARGET_PANE_USAGE "[-t target-pane]"
1586 #define CMD_TARGET_WINDOW_USAGE "[-t target-window]"
1587 #define CMD_TARGET_SESSION_USAGE "[-t target-session]"
1588 #define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
1589 void	cmd_target_init(struct cmd *, int);
1590 int	cmd_target_parse(struct cmd *, int, char **, char **);
1591 void	cmd_target_free(struct cmd *);
1592 size_t	cmd_target_print(struct cmd *, char *, size_t);
1593 #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]"
1594 #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
1595 #define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]"
1596 #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
1597 void	cmd_srcdst_init(struct cmd *, int);
1598 int	cmd_srcdst_parse(struct cmd *, int, char **, char **);
1599 void	cmd_srcdst_free(struct cmd *);
1600 size_t	cmd_srcdst_print(struct cmd *, char *, size_t);
1601 #define CMD_BUFFER_PANE_USAGE "[-b buffer-index] [-t target-pane]"
1602 #define CMD_BUFFER_WINDOW_USAGE "[-b buffer-index] [-t target-window]"
1603 #define CMD_BUFFER_SESSION_USAGE "[-b buffer-index] [-t target-session]"
1604 #define CMD_BUFFER_CLIENT_USAGE "[-b buffer-index] [-t target-client]"
1605 void	cmd_buffer_init(struct cmd *, int);
1606 int	cmd_buffer_parse(struct cmd *, int, char **, char **);
1607 void	cmd_buffer_free(struct cmd *);
1608 size_t	cmd_buffer_print(struct cmd *, char *, size_t);
1609 
1610 /* client.c */
1611 int	client_main(int, char **, int);
1612 
1613 /* key-bindings.c */
1614 extern struct key_bindings key_bindings;
1615 int	 key_bindings_cmp(struct key_binding *, struct key_binding *);
1616 SPLAY_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp);
1617 struct key_binding *key_bindings_lookup(int);
1618 void	 key_bindings_add(int, int, struct cmd_list *);
1619 void	 key_bindings_remove(int);
1620 void	 key_bindings_clean(void);
1621 void	 key_bindings_init(void);
1622 void	 key_bindings_dispatch(struct key_binding *, struct client *);
1623 void printflike2 key_bindings_error(struct cmd_ctx *, const char *, ...);
1624 void printflike2 key_bindings_print(struct cmd_ctx *, const char *, ...);
1625 void printflike2 key_bindings_info(struct cmd_ctx *, const char *, ...);
1626 
1627 /* key-string.c */
1628 int	 key_string_lookup_string(const char *);
1629 const char *key_string_lookup_key(int);
1630 
1631 /* server.c */
1632 extern struct clients clients;
1633 extern struct clients dead_clients;
1634 int	 server_start(void);
1635 void	 server_update_socket(void);
1636 
1637 /* server-client.c */
1638 void	 server_client_create(int);
1639 void	 server_client_lost(struct client *);
1640 void	 server_client_callback(int, short, void *);
1641 void	 server_client_status_timer(void);
1642 void	 server_client_loop(void);
1643 
1644 /* server-window.c */
1645 void	 server_window_loop(void);
1646 
1647 /* server-fn.c */
1648 void	 server_fill_environ(struct session *, struct environ *);
1649 void	 server_write_client(
1650 	     struct client *, enum msgtype, const void *, size_t);
1651 void	 server_write_session(
1652 	     struct session *, enum msgtype, const void *, size_t);
1653 void	 server_redraw_client(struct client *);
1654 void	 server_status_client(struct client *);
1655 void	 server_redraw_session(struct session *);
1656 void	 server_redraw_session_group(struct session *);
1657 void	 server_status_session(struct session *);
1658 void	 server_status_session_group(struct session *);
1659 void	 server_redraw_window(struct window *);
1660 void	 server_redraw_window_borders(struct window *);
1661 void	 server_status_window(struct window *);
1662 void	 server_lock(void);
1663 void	 server_lock_session(struct session *);
1664 void	 server_lock_client(struct client *);
1665 int	 server_unlock(const char *);
1666 void	 server_kill_window(struct window *);
1667 int	 server_link_window(struct session *,
1668 	     struct winlink *, struct session *, int, int, int, char **);
1669 void	 server_unlink_window(struct session *, struct winlink *);
1670 void	 server_destroy_pane(struct window_pane *);
1671 void	 server_destroy_session_group(struct session *);
1672 void	 server_destroy_session(struct session *);
1673 void	 server_check_unattached (void);
1674 void	 server_set_identify(struct client *);
1675 void	 server_clear_identify(struct client *);
1676 void	 server_update_event(struct client *);
1677 
1678 /* status.c */
1679 int	 status_redraw(struct client *);
1680 char	*status_replace(
1681 	     struct client *, struct winlink *, const char *, time_t, int);
1682 void printflike2 status_message_set(struct client *, const char *, ...);
1683 void	 status_message_clear(struct client *);
1684 int	 status_message_redraw(struct client *);
1685 void	 status_prompt_set(struct client *, const char *,
1686 	     int (*)(void *, const char *), void (*)(void *), void *, int);
1687 void	 status_prompt_clear(struct client *);
1688 int	 status_prompt_redraw(struct client *);
1689 void	 status_prompt_key(struct client *, int);
1690 void	 status_prompt_update(struct client *, const char *);
1691 
1692 /* resize.c */
1693 void	 recalculate_sizes(void);
1694 
1695 /* input.c */
1696 void	 input_init(struct window_pane *);
1697 void	 input_free(struct window_pane *);
1698 void	 input_parse(struct window_pane *);
1699 
1700 /* input-key.c */
1701 void	 input_key(struct window_pane *, int);
1702 void	 input_mouse(struct window_pane *, struct mouse_event *);
1703 
1704 /* xterm-keys.c */
1705 char	*xterm_keys_lookup(int);
1706 int	 xterm_keys_find(const char *, size_t, size_t *, int *);
1707 
1708 /* colour.c */
1709 void	 colour_set_fg(struct grid_cell *, int);
1710 void	 colour_set_bg(struct grid_cell *, int);
1711 const char *colour_tostring(int);
1712 int	 colour_fromstring(const char *);
1713 u_char	 colour_256to16(u_char);
1714 u_char	 colour_256to88(u_char);
1715 
1716 /* attributes.c */
1717 const char *attributes_tostring(u_char);
1718 int	 attributes_fromstring(const char *);
1719 
1720 /* grid.c */
1721 extern const struct grid_cell grid_default_cell;
1722 struct grid *grid_create(u_int, u_int, u_int);
1723 void	 grid_destroy(struct grid *);
1724 int	 grid_compare(struct grid *, struct grid *);
1725 void	 grid_collect_history(struct grid *);
1726 void	 grid_scroll_history(struct grid *);
1727 void	 grid_scroll_history_region(struct grid *, u_int, u_int);
1728 void	 grid_expand_line(struct grid *, u_int, u_int);
1729 void	 grid_expand_line_utf8(struct grid *, u_int, u_int);
1730 const struct grid_cell *grid_peek_cell(struct grid *, u_int, u_int);
1731 struct grid_cell *grid_get_cell(struct grid *, u_int, u_int);
1732 void	 grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *);
1733 const struct grid_utf8 *grid_peek_utf8(struct grid *, u_int, u_int);
1734 struct grid_utf8 *grid_get_utf8(struct grid *, u_int, u_int);
1735 void	 grid_set_utf8(struct grid *, u_int, u_int, const struct grid_utf8 *);
1736 void	 grid_clear(struct grid *, u_int, u_int, u_int, u_int);
1737 void	 grid_clear_lines(struct grid *, u_int, u_int);
1738 void	 grid_move_lines(struct grid *, u_int, u_int, u_int);
1739 void	 grid_move_cells(struct grid *, u_int, u_int, u_int, u_int);
1740 char	*grid_string_cells(struct grid *, u_int, u_int, u_int);
1741 void	 grid_duplicate_lines(
1742 	     struct grid *, u_int, struct grid *, u_int, u_int);
1743 
1744 /* grid-utf8.c */
1745 size_t	 grid_utf8_size(const struct grid_utf8 *);
1746 size_t	 grid_utf8_copy(const struct grid_utf8 *, char *, size_t);
1747 void	 grid_utf8_set(struct grid_utf8 *, const struct utf8_data *);
1748 int	 grid_utf8_append(struct grid_utf8 *, const struct utf8_data *);
1749 int	 grid_utf8_compare(const struct grid_utf8 *, const struct grid_utf8 *);
1750 
1751 /* grid-view.c */
1752 const struct grid_cell *grid_view_peek_cell(struct grid *, u_int, u_int);
1753 struct grid_cell *grid_view_get_cell(struct grid *, u_int, u_int);
1754 void	 grid_view_set_cell(
1755 	     struct grid *, u_int, u_int, const struct grid_cell *);
1756 const struct grid_utf8 *grid_view_peek_utf8(struct grid *, u_int, u_int);
1757 struct grid_utf8 *grid_view_get_utf8(struct grid *, u_int, u_int);
1758 void	 grid_view_set_utf8(
1759 	     struct grid *, u_int, u_int, const struct grid_utf8 *);
1760 void	 grid_view_clear(struct grid *, u_int, u_int, u_int, u_int);
1761 void	 grid_view_scroll_region_up(struct grid *, u_int, u_int);
1762 void	 grid_view_scroll_region_down(struct grid *, u_int, u_int);
1763 void	 grid_view_insert_lines(struct grid *, u_int, u_int);
1764 void	 grid_view_insert_lines_region(struct grid *, u_int, u_int, u_int);
1765 void	 grid_view_delete_lines(struct grid *, u_int, u_int);
1766 void	 grid_view_delete_lines_region(struct grid *, u_int, u_int, u_int);
1767 void	 grid_view_insert_cells(struct grid *, u_int, u_int, u_int);
1768 void	 grid_view_delete_cells(struct grid *, u_int, u_int, u_int);
1769 char	*grid_view_string_cells(struct grid *, u_int, u_int, u_int);
1770 
1771 /* screen-write.c */
1772 void	 screen_write_start(
1773 	     struct screen_write_ctx *, struct window_pane *, struct screen *);
1774 void	 screen_write_stop(struct screen_write_ctx *);
1775 size_t printflike2 screen_write_cstrlen(int, const char *, ...);
1776 void printflike5 screen_write_cnputs(struct screen_write_ctx *,
1777 	     ssize_t, struct grid_cell *, int, const char *, ...);
1778 size_t printflike2 screen_write_strlen(int, const char *, ...);
1779 void printflike3 screen_write_puts(struct screen_write_ctx *,
1780 	     struct grid_cell *, const char *, ...);
1781 void printflike5 screen_write_nputs(struct screen_write_ctx *,
1782 	     ssize_t, struct grid_cell *, int, const char *, ...);
1783 void	 screen_write_vnputs(struct screen_write_ctx *,
1784 	     ssize_t, struct grid_cell *, int, const char *, va_list);
1785 void	 screen_write_parsestyle(
1786 	     struct grid_cell *, struct grid_cell *, const char *);
1787 void	 screen_write_putc(
1788 	     struct screen_write_ctx *, struct grid_cell *, u_char);
1789 void	 screen_write_copy(struct screen_write_ctx *,
1790 	     struct screen *, u_int, u_int, u_int, u_int);
1791 void	 screen_write_backspace(struct screen_write_ctx *);
1792 void	 screen_write_cursorup(struct screen_write_ctx *, u_int);
1793 void	 screen_write_cursordown(struct screen_write_ctx *, u_int);
1794 void	 screen_write_cursorright(struct screen_write_ctx *, u_int);
1795 void	 screen_write_cursorleft(struct screen_write_ctx *, u_int);
1796 void	 screen_write_alignmenttest(struct screen_write_ctx *);
1797 void	 screen_write_insertcharacter(struct screen_write_ctx *, u_int);
1798 void	 screen_write_deletecharacter(struct screen_write_ctx *, u_int);
1799 void	 screen_write_insertline(struct screen_write_ctx *, u_int);
1800 void	 screen_write_deleteline(struct screen_write_ctx *, u_int);
1801 void	 screen_write_clearline(struct screen_write_ctx *);
1802 void	 screen_write_clearendofline(struct screen_write_ctx *);
1803 void	 screen_write_clearstartofline(struct screen_write_ctx *);
1804 void	 screen_write_cursormove(struct screen_write_ctx *, u_int, u_int);
1805 void	 screen_write_cursormode(struct screen_write_ctx *, int);
1806 void	 screen_write_reverseindex(struct screen_write_ctx *);
1807 void	 screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int);
1808 void	 screen_write_insertmode(struct screen_write_ctx *, int);
1809 void	 screen_write_mousemode(struct screen_write_ctx *, int);
1810 void	 screen_write_linefeed(struct screen_write_ctx *, int);
1811 void	 screen_write_linefeedscreen(struct screen_write_ctx *, int);
1812 void	 screen_write_carriagereturn(struct screen_write_ctx *);
1813 void	 screen_write_kcursormode(struct screen_write_ctx *, int);
1814 void	 screen_write_kkeypadmode(struct screen_write_ctx *, int);
1815 void	 screen_write_clearendofscreen(struct screen_write_ctx *);
1816 void	 screen_write_clearstartofscreen(struct screen_write_ctx *);
1817 void	 screen_write_clearscreen(struct screen_write_ctx *);
1818 void	 screen_write_cell(struct screen_write_ctx *,
1819 	     const struct grid_cell *, const struct utf8_data *);
1820 
1821 /* screen-redraw.c */
1822 void	 screen_redraw_screen(struct client *, int, int);
1823 void	 screen_redraw_pane(struct client *, struct window_pane *);
1824 
1825 /* screen.c */
1826 void	 screen_init(struct screen *, u_int, u_int, u_int);
1827 void	 screen_reinit(struct screen *);
1828 void	 screen_free(struct screen *);
1829 void	 screen_reset_tabs(struct screen *);
1830 void	 screen_set_title(struct screen *, const char *);
1831 void	 screen_resize(struct screen *, u_int, u_int);
1832 void	 screen_set_selection(struct screen *,
1833 	     u_int, u_int, u_int, u_int, u_int, struct grid_cell *);
1834 void	 screen_clear_selection(struct screen *);
1835 int	 screen_check_selection(struct screen *, u_int, u_int);
1836 
1837 /* window.c */
1838 extern struct windows windows;
1839 int		 winlink_cmp(struct winlink *, struct winlink *);
1840 RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
1841 struct winlink	*winlink_find_by_index(struct winlinks *, int);
1842 struct winlink	*winlink_find_by_window(struct winlinks *, struct window *);
1843 int		 winlink_next_index(struct winlinks *, int);
1844 u_int		 winlink_count(struct winlinks *);
1845 struct winlink	*winlink_add(struct winlinks *, struct window *, int);
1846 void		 winlink_remove(struct winlinks *, struct winlink *);
1847 struct winlink	*winlink_next(struct winlink *);
1848 struct winlink	*winlink_previous(struct winlink *);
1849 struct winlink	*winlink_next_by_number(struct winlink *, struct session *,
1850 		     int);
1851 struct winlink	*winlink_previous_by_number(struct winlink *, struct session *,
1852 		     int);
1853 void		 winlink_stack_push(struct winlink_stack *, struct winlink *);
1854 void		 winlink_stack_remove(struct winlink_stack *, struct winlink *);
1855 int		 window_index(struct window *, u_int *);
1856 struct window	*window_create1(u_int, u_int);
1857 struct window	*window_create(const char *, const char *, const char *,
1858 		     const char *, struct environ *, struct termios *,
1859 		     u_int, u_int, u_int, char **);
1860 void		 window_destroy(struct window *);
1861 void		 window_set_active_at(struct window *, u_int, u_int);
1862 void		 window_set_active_pane(struct window *, struct window_pane *);
1863 struct window_pane *window_add_pane(struct window *, u_int);
1864 void		 window_resize(struct window *, u_int, u_int);
1865 void		 window_remove_pane(struct window *, struct window_pane *);
1866 struct window_pane *window_pane_at_index(struct window *, u_int);
1867 struct window_pane *window_pane_next_by_number(struct window *,
1868 		        struct window_pane *, u_int);
1869 struct window_pane *window_pane_previous_by_number(struct window *,
1870 		        struct window_pane *, u_int);
1871 u_int		 window_pane_index(struct window *, struct window_pane *);
1872 u_int		 window_count_panes(struct window *);
1873 void		 window_destroy_panes(struct window *);
1874 struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int);
1875 void		 window_pane_destroy(struct window_pane *);
1876 int		 window_pane_spawn(struct window_pane *, const char *,
1877 		     const char *, const char *, struct environ *,
1878 		     struct termios *, char **);
1879 void		 window_pane_resize(struct window_pane *, u_int, u_int);
1880 void		 window_pane_alternate_on(
1881 		     struct window_pane *, struct grid_cell *);
1882 void		 window_pane_alternate_off(
1883 		     struct window_pane *, struct grid_cell *);
1884 int		 window_pane_set_mode(
1885 		     struct window_pane *, const struct window_mode *);
1886 void		 window_pane_reset_mode(struct window_pane *);
1887 void		 window_pane_key(struct window_pane *, struct session *, int);
1888 void		 window_pane_mouse(struct window_pane *,
1889 		     struct session *, struct mouse_event *);
1890 int		 window_pane_visible(struct window_pane *);
1891 char		*window_pane_search(
1892 		     struct window_pane *, const char *, u_int *);
1893 struct window_pane *window_pane_find_up(struct window_pane *);
1894 struct window_pane *window_pane_find_down(struct window_pane *);
1895 struct window_pane *window_pane_find_left(struct window_pane *);
1896 struct window_pane *window_pane_find_right(struct window_pane *);
1897 
1898 /* layout.c */
1899 u_int		 layout_count_cells(struct layout_cell *);
1900 struct layout_cell *layout_create_cell(struct layout_cell *);
1901 void		 layout_free_cell(struct layout_cell *);
1902 void		 layout_print_cell(struct layout_cell *, const char *, u_int);
1903 void		 layout_destroy_cell(struct layout_cell *, struct layout_cell **);
1904 void		 layout_set_size(
1905 		     struct layout_cell *, u_int, u_int, u_int, u_int);
1906 void		 layout_make_leaf(
1907 		     struct layout_cell *, struct window_pane *);
1908 void		 layout_make_node(struct layout_cell *, enum layout_type);
1909 void		 layout_fix_offsets(struct layout_cell *);
1910 void		 layout_fix_panes(struct window *, u_int, u_int);
1911 u_int		 layout_resize_check(struct layout_cell *, enum layout_type);
1912 void		 layout_resize_adjust(
1913 		     struct layout_cell *, enum layout_type, int);
1914 void		 layout_init(struct window *);
1915 void		 layout_free(struct window *);
1916 void		 layout_resize(struct window *, u_int, u_int);
1917 void		 layout_resize_pane(
1918 		     struct window_pane *, enum layout_type, int);
1919 void		 layout_assign_pane(struct layout_cell *, struct window_pane *);
1920 struct layout_cell *layout_split_pane(
1921 		     struct window_pane *, enum layout_type, int);
1922 void		 layout_close_pane(struct window_pane *);
1923 
1924 /* layout-custom.c */
1925 char		*layout_dump(struct window *);
1926 int		 layout_parse(struct window *, const char *);
1927 
1928 /* layout-set.c */
1929 const char	*layout_set_name(u_int);
1930 int		 layout_set_lookup(const char *);
1931 u_int		 layout_set_select(struct window *, u_int);
1932 u_int		 layout_set_next(struct window *);
1933 u_int		 layout_set_previous(struct window *);
1934 void		 layout_set_active_changed(struct window *);
1935 
1936 /* layout-string.c */
1937 struct layout_cell *layout_find_string(struct window *, const char *);
1938 struct layout_cell *layout_find_bottomright(struct layout_cell *);
1939 
1940 /* window-clock.c */
1941 extern const struct window_mode window_clock_mode;
1942 
1943 /* window-copy.c */
1944 extern const struct window_mode window_copy_mode;
1945 void		 window_copy_init_from_pane(struct window_pane *);
1946 void		 window_copy_init_for_output(struct window_pane *);
1947 void		 window_copy_add(struct window_pane *, const char *, ...);
1948 void		 window_copy_vadd(struct window_pane *, const char *, va_list);
1949 void		 window_copy_pageup(struct window_pane *);
1950 
1951 /* window-choose.c */
1952 extern const struct window_mode window_choose_mode;
1953 void		 window_choose_vadd(
1954 		     struct window_pane *, int, const char *, va_list);
1955 void printflike3 window_choose_add(
1956 		     struct window_pane *, int, const char *, ...);
1957 void		 window_choose_ready(struct window_pane *,
1958 		     u_int, void (*)(void *, int), void (*)(void *), void *);
1959 
1960 /* names.c */
1961 void		 queue_window_name(struct window *);
1962 char		*default_window_name(struct window *);
1963 
1964 /* signal.c */
1965 void set_signals(void(*)(int, short, void *));
1966 void clear_signals(int);
1967 
1968 /* session.c */
1969 extern struct sessions sessions;
1970 extern struct sessions dead_sessions;
1971 extern struct session_groups session_groups;
1972 int	session_cmp(struct session *, struct session *);
1973 RB_PROTOTYPE(sessions, session, entry, session_cmp);
1974 int		 session_alive(struct session *);
1975 struct session	*session_find(const char *);
1976 struct session	*session_find_by_index(u_int);
1977 struct session	*session_create(const char *, const char *, const char *,
1978 		     struct environ *, struct termios *, int, u_int, u_int,
1979 		     char **);
1980 void		 session_destroy(struct session *);
1981 struct session	*session_next_session(struct session *);
1982 struct session	*session_previous_session(struct session *);
1983 struct winlink	*session_new(struct session *,
1984 		     const char *, const char *, const char *, int, char **);
1985 struct winlink	*session_attach(
1986 		     struct session *, struct window *, int, char **);
1987 int		 session_detach(struct session *, struct winlink *);
1988 struct winlink*	 session_has(struct session *, struct window *);
1989 int		 session_next(struct session *, int);
1990 int		 session_previous(struct session *, int);
1991 int		 session_select(struct session *, int);
1992 int		 session_last(struct session *);
1993 struct session_group *session_group_find(struct session *);
1994 u_int		 session_group_index(struct session_group *);
1995 void		 session_group_add(struct session *, struct session *);
1996 void		 session_group_remove(struct session *);
1997 void		 session_group_synchronize_to(struct session *);
1998 void		 session_group_synchronize_from(struct session *);
1999 void		 session_group_synchronize1(struct session *, struct session *);
2000 
2001 /* utf8.c */
2002 void	utf8_build(void);
2003 int	utf8_open(struct utf8_data *, u_char);
2004 int	utf8_append(struct utf8_data *, u_char);
2005 
2006 /* osdep-*.c */
2007 char   *osdep_get_name(int, char *);
2008 
2009 /* log.c */
2010 void		 log_open_tty(int);
2011 void		 log_open_file(int, const char *);
2012 void		 log_close(void);
2013 void printflike1 log_warn(const char *, ...);
2014 void printflike1 log_warnx(const char *, ...);
2015 void printflike1 log_info(const char *, ...);
2016 void printflike1 log_debug(const char *, ...);
2017 void printflike1 log_debug2(const char *, ...);
2018 __dead void printflike1 log_fatal(const char *, ...);
2019 __dead void printflike1 log_fatalx(const char *, ...);
2020 
2021 /* xmalloc.c */
2022 char		*xstrdup(const char *);
2023 void		*xcalloc(size_t, size_t);
2024 void		*xmalloc(size_t);
2025 void		*xrealloc(void *, size_t, size_t);
2026 void		 xfree(void *);
2027 int printflike2	 xasprintf(char **, const char *, ...);
2028 int		 xvasprintf(char **, const char *, va_list);
2029 int printflike3	 xsnprintf(char *, size_t, const char *, ...);
2030 int		 xvsnprintf(char *, size_t, const char *, va_list);
2031 
2032 #endif /* TMUX_H */
2033