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