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